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

Unsound problem in InstrPtr::module #44

Open
lwz23 opened this issue Dec 9, 2024 · 3 comments
Open

Unsound problem in InstrPtr::module #44

lwz23 opened this issue Dec 9, 2024 · 3 comments

Comments

@lwz23
Copy link

lwz23 commented Dec 9, 2024

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

pub struct InstrPtr {
    /// Module containing the instruction set.
    pub module: *const Module,
    /// Offset to the current instruction.
    pub ptr: u32,
}
..........................
pub fn new(module: *const Module, ptr: u32) -> Self {
        InstrPtr { module, ptr }
    }

    #[inline(always)]
    pub fn get_module<'a, 'b>(&'a self) -> &'b Module {
        unsafe { &(*self.module) }
    }
..............................

Considering that pub mod instruction and module is a pub field, I assume that users can directly manipulate this field. This potential situation could result in self.module being a null pointer, and directly dereferencing it might trigger undefined behavior (UB). For safety reasons, I felt it necessary to report this issue. If you have performed checks elsewhere that ensure this is safe, please don’t take offense at my raising this issue.

@lwz23
Copy link
Author

lwz23 commented Dec 9, 2024

I believe same problem for

let module = unsafe { &(*self.module) };

let module = unsafe { &(*self.module) };

@lwz23
Copy link
Author

lwz23 commented Dec 10, 2024

If we need fix this maybe we should also add check in new method.

@lwz23
Copy link
Author

lwz23 commented Dec 16, 2024

ping

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