-
Notifications
You must be signed in to change notification settings - Fork 296
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
Unsoundness due to construction of &mut [u8] and Box<[u8]> in Clone impl #522
Comments
I agree that this is unsound. |
saethlin
added a commit
to saethlin/bytes
that referenced
this issue
Jan 2, 2022
Previously, this code produced a &mut[u8] and a Box<[u8]> to the shared allocation upon cloning it. If the underlying allocation were actually shared, such as through a &[u8] from the Deref impl, creating either of these types incorrectly asserted uniqueness of the allocation. This fixes the example in tokio-rs#522, but Miri still does not pass on this test suite with -Zmiri-tag-raw-pointers because Miri does not currently understand int to pointer casts.
saethlin
added a commit
to saethlin/bytes
that referenced
this issue
Jan 2, 2022
Previously, this code produced a &mut[u8] and a Box<[u8]> to the shared allocation upon cloning it. If the underlying allocation were actually shared, such as through a &[u8] from the Deref impl, creating either of these types incorrectly asserted uniqueness of the allocation. This fixes the example in tokio-rs#522, but Miri still does not pass on this test suite with -Zmiri-tag-raw-pointers because Miri does not currently understand int to pointer casts.
Darksonn
pushed a commit
that referenced
this issue
Apr 6, 2022
Previously, this code produced a &mut[u8] and a Box<[u8]> to the shared allocation upon cloning it. If the underlying allocation were actually shared, such as through a &[u8] from the Deref impl, creating either of these types incorrectly asserted uniqueness of the allocation. This fixes the example in #522, but Miri still does not pass on this test suite with -Zmiri-tag-raw-pointers because Miri does not currently understand int to pointer casts.
lelongg
pushed a commit
to lelongg/bytes
that referenced
this issue
Jan 9, 2023
Previously, this code produced a &mut[u8] and a Box<[u8]> to the shared allocation upon cloning it. If the underlying allocation were actually shared, such as through a &[u8] from the Deref impl, creating either of these types incorrectly asserted uniqueness of the allocation. This fixes the example in tokio-rs#522, but Miri still does not pass on this test suite with -Zmiri-tag-raw-pointers because Miri does not currently understand int to pointer casts.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This example is minimized from the protobuf crate's test suite, using bytes v1.1.0:
I think this is pretty solidly unsound under any reasonable aliasing formulation. Miri's stacked borrow checker flags the use of
buf
as the problematic line because its access was invalidated by constructing the&mut [u8]
, but I think a different sort of aliasing model could flag the creation of the&mut
itself as the problem, because it aliases.A diff which could fix this looks like this:
But
per Stacked Borrows, this just gets over one hurdle only to crash straight into another, sinceBox
has unique access just the same as&mut
. I suspect this could be patched up as well by forsakingBox
entirely within the internals of this library. But that might be kind of invasive, so I would prefer to get some feedback from maintainers first. What do you all think?Updated to reflect the fact that Box asserts uniqueness, even in the absence of Stacked Borrows.
The text was updated successfully, but these errors were encountered: