RustCrypto / RustCrypto/utils

zeroize: possible UB in `Zeroize` implementation for `Option<T>`

未关闭
#653 3 条评论 2 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

主要语言
Rust
星标
674
派生
170
平均合并
1 天 12 小时
30 天内合并 PR
10

描述

Originally filed by @jessa0 as https://github.com/iqlusioninc/crates/issues/782:

It seems the Zeroize implementation for Option<T> where T: Zeroize has language-level UB here:

https://github.com/RustCrypto/utils/blob/00b569b52b6dece2a8ae881f8e5a150a45ccc674/zeroize/src/lib.rs#L330

I believe, as a repr(Rust) enum, the memory layout and set of valid bit-patterns for Option 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 for Option does mention guarantees for several special cases, but the None case still isn't defined for many of those cases, and the Zeroize 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.

贡献指南

这个仓库没有索引到贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

从 zeroize/src/lib.rs 约第 330 行开始,使用链接的 Rust Playground 或 Miri 示例重现报告的行为。确定 Option 实现的可靠方案,并验证所得行为不再触发报告的未定义行为错误。

由索引模型根据 Issue 内容生成。

评估

技术栈
rust
领域
security
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。