Skip to content
New issue

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

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

Already on GitHub? # to your account

Do ZST Boxes violate provenance monotonicity? #529

Closed
joshlf opened this issue Aug 29, 2024 · 4 comments · Fixed by rust-lang/rust#129748
Closed

Do ZST Boxes violate provenance monotonicity? #529

joshlf opened this issue Aug 29, 2024 · 4 comments · Fixed by rust-lang/rust#129748

Comments

@joshlf
Copy link

joshlf commented Aug 29, 2024

(Writing on my phone; apologies for the lack of formatting.)

Per the Box module-level docs:

For zero-sized values, the Box pointer still has to be valid for reads and writes and sufficiently aligned. In particular, casting any aligned non-zero integer literal to a raw pointer produces a valid pointer, but a pointer pointing into previously allocated memory that since got freed is not valid. The recommended way to build a Box to a ZST if Box::new cannot be used is to use ptr::NonNull::dangling.

I'm trying to interpret "pointer pointing into previously allocated memory." IIUC, an integer whose address is the same as previously-allocated memory should be fine, so what really distinguishes these two cases is whether or not the pointer in question has provenance for the previously-freed allocation.

However, this implies that Box violates provenance monotonicity: an operation with a provenance-free pointer (one cast from a bare integer) is sound, while the same operation with a provenance-carrying integer is not.

Am I understanding this correctly?

@RalfJung
Copy link
Member

RalfJung commented Aug 29, 2024

Good catch! That's an outdated copy of the pointer validity docs that hasn't been updated for rust-lang/rust#117945.

rust-timer added a commit to rust-lang-ci/rust that referenced this issue Sep 3, 2024
Rollup merge of rust-lang#129748 - RalfJung:box-validity, r=workingjubilee

Box validity: update for new zero-sized rules

Fixes rust-lang/unsafe-code-guidelines#529

Cc `@joshlf` `@rust-lang/opsem`
@RalfJung
Copy link
Member

RalfJung commented Sep 8, 2024

Funny... the PR with the "fixes" annotation got merged a week ago, but now @saethlin pushing this somewhere led to the issue actually getting closed...

@saethlin
Copy link
Member

saethlin commented Sep 8, 2024

Yeah... that was me updating my fork. There's some kind of GitHub bug here.

@RalfJung
Copy link
Member

RalfJung commented Sep 9, 2024

I think it might be a permission thing. bors doesn't have permissions to close issues in this repo, but you do.

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

Successfully merging a pull request may close this issue.

3 participants