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 摘要。