Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maybe unsound in some as_ptr usage #121

Open
lwz23 opened this issue Jan 7, 2025 · 1 comment
Open

Maybe unsound in some as_ptr usage #121

lwz23 opened this issue Jan 7, 2025 · 1 comment

Comments

@lwz23
Copy link

lwz23 commented Jan 7, 2025

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.

@lwz23
Copy link
Author

lwz23 commented Jan 7, 2025

impl Rsdt<u64> {

same problem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant