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

Box is unsound #10

Open
glandium opened this issue Jan 12, 2024 · 4 comments
Open

Box is unsound #10

glandium opened this issue Jan 12, 2024 · 4 comments

Comments

@glandium
Copy link

allocator-api2's Box is backed by a NonNull.
std's Box is backed by a Unique. Unique is a wrapper around NonNull with an important addition: a marker to give a hint to dropck

The Box type in this crate doesn't have this marker.

Relatedly, I'm working on refreshing https://crates.io/crates/allocator-api with code automatically generated from the code in the rust repo (and comparing what I have vs this crate is how I found this discrepancy).

@zakarumych
Copy link
Owner

zakarumych commented Jan 13, 2024

Thank you for reporting this.

Can you provide an example that will cause UB with allocator_api2::Box without unsafe?

I guess the fix is adding PhantomData<T> here

@WorldSEnder
Copy link

The current Drop impl on Box does not indicate a #[may_dangle] on T, so I do not quite see that the linked question and answer applies currently - although a proper fix and the insertion of such a #[may_dangle] would most be nice to have.

@glandium
Copy link
Author

My memory is hazy wrt details (it was 6 years ago), but I'm rather sure that I've ended up with cases where the borrow checker would allow things leading to UAFs when I wrote the initial Box in the allocator-api crate without a PhantomData, and that was without may_dangle because it's never been stable.

OTOH, I can't reproduce with trivial test cases with the rustc version of the time (1.25.0, which is the first version with NonNull in libstd). That said, I'd rather be overly cautious than not enough.

moz-v2v-gh pushed a commit to mozilla/gecko-dev that referenced this issue Sep 18, 2024
…hain-reviewers

See also zakarumych/allocator-api2#10

This patch was produced with the following steps:
 - Vendor allocator-api2 normally.
 - Modify the vendored source in third_party/rust.
   - Stop exporting the Box implementation.
   - Change the version to 0.2.999.
 - Run cargo update -p allocator-api2 --precise 0.2.999

Differential Revision: https://phabricator.services.mozilla.com/D218729
jamienicol pushed a commit to jamienicol/gecko that referenced this issue Sep 19, 2024
…hain-reviewers

See also zakarumych/allocator-api2#10

This patch was produced with the following steps:
 - Vendor allocator-api2 normally.
 - Modify the vendored source in third_party/rust.
   - Stop exporting the Box implementation.
   - Change the version to 0.2.999.
 - Run cargo update -p allocator-api2 --precise 0.2.999

Differential Revision: https://phabricator.services.mozilla.com/D218729
i3roly pushed a commit to i3roly/firefox-dynasty that referenced this issue Sep 20, 2024
…hain-reviewers

See also zakarumych/allocator-api2#10

This patch was produced with the following steps:
 - Vendor allocator-api2 normally.
 - Modify the vendored source in third_party/rust.
   - Stop exporting the Box implementation.
   - Change the version to 0.2.999.
 - Run cargo update -p allocator-api2 --precise 0.2.999

Differential Revision: https://phabricator.services.mozilla.com/D218729
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified-and-comments-removed that referenced this issue Sep 20, 2024
…hain-reviewers

See also zakarumych/allocator-api2#10

This patch was produced with the following steps:
 - Vendor allocator-api2 normally.
 - Modify the vendored source in third_party/rust.
   - Stop exporting the Box implementation.
   - Change the version to 0.2.999.
 - Run cargo update -p allocator-api2 --precise 0.2.999

Differential Revision: https://phabricator.services.mozilla.com/D218729

UltraBlame original commit: 3521a2abcbfb3b8f213770d8595af015f75f439c
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified that referenced this issue Sep 20, 2024
…hain-reviewers

See also zakarumych/allocator-api2#10

This patch was produced with the following steps:
 - Vendor allocator-api2 normally.
 - Modify the vendored source in third_party/rust.
   - Stop exporting the Box implementation.
   - Change the version to 0.2.999.
 - Run cargo update -p allocator-api2 --precise 0.2.999

Differential Revision: https://phabricator.services.mozilla.com/D218729

UltraBlame original commit: 3521a2abcbfb3b8f213770d8595af015f75f439c
github-actions bot pushed a commit to servo/webrender that referenced this issue Sep 22, 2024
…hain-reviewers

See also zakarumych/allocator-api2#10

This patch was produced with the following steps:
 - Vendor allocator-api2 normally.
 - Modify the vendored source in third_party/rust.
   - Stop exporting the Box implementation.
   - Change the version to 0.2.999.
 - Run cargo update -p allocator-api2 --precise 0.2.999

Differential Revision: https://phabricator.services.mozilla.com/D218729
github-actions bot pushed a commit to jschwe/webrender that referenced this issue Sep 22, 2024
…hain-reviewers

See also zakarumych/allocator-api2#10

This patch was produced with the following steps:
 - Vendor allocator-api2 normally.
 - Modify the vendored source in third_party/rust.
   - Stop exporting the Box implementation.
   - Change the version to 0.2.999.
 - Run cargo update -p allocator-api2 --precise 0.2.999

Differential Revision: https://phabricator.services.mozilla.com/D218729
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

3 participants