-
Notifications
You must be signed in to change notification settings - Fork 75
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
Possible UB in Zeroize
implementation for Option<T>
#782
Comments
Thanks for reporting this. I was a bit hesitant about this in regard to PRs like #649 and #687, especially as I read ongoing discussion about Unfortunately I don't have anything more to say about this topic, but can circulate this question among interested parties, particularly ones who work on unsafe code guidelines to get more feedback. |
FWIW, the language reference only mentions wrt. invalid enum discriminants, "Producing an invalid value, even in private fields and locals [is undefined behaviour]. 'Producing' a value happens any time a value is assigned to or read from a place, passed to a function/primitive operation or returned from a function/primitive operation." This to me, sounds like, despite an outstanding mutable reference, changing the underlying storage to an invalid value without reading it back through the reference is still defined. That same page in the reference of course mentions that the list of UB is not considered exhaustive, though. |
I found this discussion in the Unsafe Code Guidelines WG which seems to almost match this code. It might be worth bringing up whether |
Zeroize
implementation for Option<T>
Zeroize
implementation for Option<T>
Moved to RustCrypto/utils#653 |
It seems the
Zeroize
implementation forOption<T> where T: Zeroize
has language-level UB here:crates/zeroize/src/lib.rs
Line 317 in f6deffc
I believe, as a
repr(Rust)
enum, the memory layout and set of valid bit-patterns forOption
is not defined, and that setting an enum's storage to an invalid bit-pattern while a reference to it exists, even if the value is never read, is instant language-level UB. The documentation forOption
does mention guarantees for several special cases, but theNone
case still isn't defined for many of those cases, and theZeroize
implementation is more generic than that. Here's an example of a miri error in such a situation, that scottmcm came up with on URLO here.The text was updated successfully, but these errors were encountered: