-
Notifications
You must be signed in to change notification settings - Fork 0
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
Potential soundness issue #1
Comments
Thanks for reaching out! When creating this crate, I was aware that I am relying on compiler internal implementation details. My original use for this crate was pinned initialization. Now I have created a different solution, so I do not really have a use for this anymore. I do not like using I should probably yank the current version just to be extra sure (do you have any other solutions?). If you would like to have the name of this crate, I can transfer it to you. If you want to create a better solution. |
All sub-optimal solutions that I could think of are:
Thank you for the kind offer! :) Unfortunately, to me it looks like any "zero-cost" and sound solution could only be implemented at the compiler level. There has been some speculation about adding an |
Hi! I came across your crate on crates.io because I wanted to do something similar to
UnsafeAliasCell
and I was curious about how others might solve the same issue :) I may have spotted a potential soundness issue in your approach, which I wanted to let you know about.Currently the implementation of
UnsafeAliasCell
relies on it being!Unpin
in order for LLVM to omit thenoalias
attribute:unsafe-alias-cell/src/lib.rs
Lines 6 to 11 in ee50cdb
As far as I understand, rustc and miri currently do this as an implementation detail to work-around a known soundness issue with self-referential structs (e.g. async generators), but it is not a stable API guarantee to the outside world. This means that at some point in the future, Rust may start to emit
noalias
again for types that are!Unpin
and then current users of this crate will have a soundness bug in them retroactively. I was warned of the same danger some time ago (relevant Zulip thread).We were chatting on Zulip about something similar very recently, in case it helps for additional inspiration on how to work-around this soundness issue. Although I'm not sure if there exists a proper one-size-fits-all solution yet without additional support from the standard library. You might be able to partially leverage the
MaybeUninit<T>
type to strip thenoalias
attribute from pointeesT
(pointeesT
as in e.g.Box<T>
and&mut T
, where we distinguish between the pointer and pointee parts of the type), but a big downside is that it also strips a lot of other useful LLVM attributes as well. I'm not sure if this would work for regular struct fields likei32
or the pointers themselves. I hope this feedback is useful and might help prevent some UB :)The text was updated successfully, but these errors were encountered: