Skip to content

Unsoundness in #30

@lwz23

Description

@lwz23

Hello, thank you for your contribution in this project, I an testing our static analysis tool in github's Rust project and I notice the following code:

fn jmp64(entry_addr: u64) -> ! {
    unsafe {
        llvm_asm!(
            "pushl $$0x10
              pushl %eax
              movl  %ebx, %eax
              movl  %eax, %cr0
              lret"
            : : "{eax}"(entry_addr), "{ebx}"((1 << 31) | (1 << 0)) "{esi}"(0x7C00) :
        );
        unreachable_unchecked();
    }
}

I think there is a unsound problem because this function doesn't varify the entry_addr is valid and pass it to asm. It will trigger UB. Although it is a private function, I notice a possible way to call this function from a pub function start_kernel.

// 函数: start_kernel
pub fn start_kernel(entry_addr: u64) -> ! {
    setup_gdt();
    enable_pae();
    setup_page_tables();
    enable_paging();
    jmp64(entry_addr);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions