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 implementation created misaligned pointer #1526

Closed
shinmao opened this issue Sep 20, 2023 · 19 comments · Fixed by #1530
Closed

Unsound implementation created misaligned pointer #1526

shinmao opened this issue Sep 20, 2023 · 19 comments · Fixed by #1530

Comments

@shinmao
Copy link

shinmao commented Sep 20, 2023

The source of unsoundness

Hi, we found that <observers::map::HitcountsMapObserver<M> as observers::Observer<S>>::post_exec could create a misaligned pointer:

let map16 = unsafe { core::slice::from_raw_parts_mut(map.as_mut_ptr() as *mut u16, cnt) };

At this line, the u8 raw pointer was cast to u16 pointer and passed to core::slice::from_raw_parts_mut which requires the pointer to be aligned. Otherwise, it could lead to undefined behavior.

@domenukk
Copy link
Member

Great find, thanks! Can you please take a look at #1530 if this would be an okay fix?

@shinmao
Copy link
Author

shinmao commented Sep 20, 2023

@domenukk thanks for the response. I just saw the code and considered it should be fixed!

@shinmao
Copy link
Author

shinmao commented Sep 20, 2023

Another question:

fn content_mut(&mut self) -> &mut StateShMemContent {
let ptr = self.shmem.as_slice().as_ptr();
#[allow(clippy::cast_ptr_alignment)] // Beginning of the page will always be aligned
unsafe {
&mut *(ptr as *mut StateShMemContent)
}

The safety of this function depends on the usage of internal library. The comments mentioned that "Beginning of the page will always be aligned": Is that guaranteed because the start address is 0x0 and could be multiple of any alignments?

@domenukk
Copy link
Member

For all shmem implementations I know the start of the page will be aligned, but I'll happily replace this with a read_unaligned

@domenukk
Copy link
Member

Ah no, it's not that easy

@shinmao
Copy link
Author

shinmao commented Sep 20, 2023

I think it's fine if the address is 0x0.

@domenukk
Copy link
Member

I'll add a debug_assert

@shinmao
Copy link
Author

shinmao commented Sep 20, 2023

I have another issue about bolts::anymap::unpack_type_id. Personally, I would like to open another issue to avoid misunderstanding. Would you want me to describe it here?

@domenukk
Copy link
Member

Yes please open another issue :)

@shinmao
Copy link
Author

shinmao commented Sep 25, 2023

Would you mind help me report it to RUSTSEC so that we could remind users to update to the latest version?

@tokatoka
Copy link
Member

Yes 👍
How can we help?

@shinmao
Copy link
Author

shinmao commented Sep 26, 2023

@tokatoka I just send the PR to the advisory-db (please see the link: rustsec/advisory-db@03f3cea). What I can do now is that update the information of patched version. Is it patched and release in a new version, and which version?

@tokatoka
Copy link
Member

tokatoka commented Sep 26, 2023

no there's no new version released yet

@domenukk
Copy link
Member

Maybe we should do a release then, cc @andreafioraldi

@shinmao
Copy link
Author

shinmao commented Oct 5, 2023

Hi @domenukk , do you agree to create a security policy under the repo? Then I can send the advisory that all users can check the dependencies on Github.

@andreafioraldi
Copy link
Member

Hi @domenukk , do you agree to create a security policy under the repo? Then I can send the advisory that all users can check the dependencies on Github.

Hi @shinmao , thanks for the report!
I don't think that there is a threat model here and thus we cannot consider a bug in the code processing the coverage map as a security issue.
I don't mind too much about definitions, feel free to push things to advisory-db once we release the next version, but I would not bother by email any of our users for this bug.

@shinmao
Copy link
Author

shinmao commented Oct 5, 2023

@andreafioraldi thanks for the response.
I have sent PR to advisory-db (link) and wondering whether they have contacted you.

@andreafioraldi
Copy link
Member

Not yet, but if they want to email users with things like dependabot i will not let them proceed, this is not a security vulnerability and users must not receive ambiguos alerts on their mailboxes.

@shinmao
Copy link
Author

shinmao commented Oct 5, 2023

Understood. It is just something like undefined behavior from the perspective of Rust's language model.

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

Successfully merging a pull request may close this issue.

4 participants