Skip to content

Maybe unsound in some as_ptr usage #121

Open
@lwz23

Description

@lwz23

Hello, thank you for your contribution in this project. I am scanning unsound problem in rust project and I notice the following code:

pub fn new(address: VirtAddr) -> &'static Self {

pub fn new(address: VirtAddr) -> &'static Self {
        let this = unsafe { &*address.as_ptr::<Self>() };

        let valid_checksum = this.header.is_valid();
        let valid_signature = this.header.signature() == b"RSDT";

        assert!(valid_checksum, "rsdp: failed to validate RSDT checksum");
        assert!(valid_signature, "rsdp: failed to validate RSDT signature");

        this
    }

Considering this is a pub function and there is no varify in VirtAddr contruct method, I think this is unsound because the address can be any invalid value and deference it will result in UB.

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