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

Audit uses of addr_of! for read-only-ness #1607

Closed
Tracked by #671
joshlf opened this issue Sep 4, 2024 · 0 comments · Fixed by #1617
Closed
Tracked by #671

Audit uses of addr_of! for read-only-ness #1607

joshlf opened this issue Sep 4, 2024 · 0 comments · Fixed by #1617
Labels
blocking-next-release This issue should be resolved before we release on crates.io

Comments

@joshlf
Copy link
Member

joshlf commented Sep 4, 2024

Confirm that our uses of addr_of! are sound in light of rust-lang/rust#129653. As of this writing, it appears that there are two uses:

One is Unalign::get_ptr:

zerocopy/src/wrappers.rs

Lines 233 to 235 in b8c3178

pub const fn get_ptr(&self) -> *const T {
ptr::addr_of!(self.0)
}

One is in trailing_field_offset!:

zerocopy/src/macro_util.rs

Lines 187 to 189 in b8c3178

let field = unsafe {
$crate::macro_util::core_reexport::ptr::addr_of!((*ptr).$trailing_field_name)
};

The Unalign::get_ptr one may be problematic if the user uses the returned *const T to perform mutation. We may need to clarify in the safety docs on that method that the returned pointer is read-only.

@joshlf joshlf added the blocking-next-release This issue should be resolved before we release on crates.io label Sep 4, 2024
joshlf added a commit that referenced this issue Sep 7, 2024
github-merge-queue bot pushed a commit that referenced this issue Sep 7, 2024
@joshlf joshlf mentioned this issue Sep 14, 2024
87 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocking-next-release This issue should be resolved before we release on crates.io
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant