Best practices for sharing memory with untrusted parties
还没有人认领这个 Issue。
评估
调研方向
Read the linked unsafe-code-guidelines issues #152, #321, #350, and #606, along with Rust issues #154321 and PR #141260, to understand the competing volatile and atomic-access models. Done means reaching a documented consensus on safe best practices for sharing memory with untrusted parties.
由索引模型根据 Issue 内容生成。
描述
This was the starting point for https://github.com/rust-lang/unsafe-code-guidelines/issues/152. That got closed saying "volatile is for MMIO", which is further discussed in #321. However, since then we got "also volatile can access memory outside the AM" (https://github.com/rust-lang/rust/pull/141260) which changes the picture again IMO. The question also recently came up in https://github.com/rust-lang/rust/issues/154321.
I would say the safest (least AM/model-breaking) way to share memory with an untrusted party is to never make that memory part of the AM. This avoids any trouble related to memory models or compiler assumptions. If this isn't actual "memory" in the first place, there can't be any assumptions. And now that volatile accesses are allowed to access such "non-memory", this is actually a viable option. I think this also explains why people are naturally drawn towards using volatile for this kind of interaction. If LLVM changes volatile loads to no longer be willreturn (which @nikic says is on the table), this model even allows reads and writes on memory that might get unmapped at any time. (Alternatively, https://github.com/rust-lang/unsafe-code-guidelines/issues/606 discusses ways for such segfaults to be valid everywhere, that'd also implicitly cover volatile accesses.)
For a Rust program this means only using raw pointers, never creating a reference, and only using read_volatile and write_volatile. Those don't even have to be atomic; all concurrency behavior is hidden behind the opaqueness of volatile accesses. (Atomic volatile accesses are useful if the party those accesses are communicating with also has access to actual Rust memory. That's not the case for this discussion.) It currently also means never using offset or field projections but we could fix that (https://github.com/rust-lang/unsafe-code-guidelines/issues/350) -- the LLVM IR we generate is already okay here, we "just" have to update our Rust-level model.
The other model we have discussed in the past is to have that shared memory be actual Rust memory and model whatever the untrusted code does as atomic accesses. This means the Rust code must also use atomic accesses. This seems to work fine in practice but the model actually has a gaping hole -- mixed-size accesses are UB, so the untrusted code can still cause UB in the Rust code. The advantage of this model is that the Rust code is allowed to use shared references (as long as all bytes of the pointee type are inside an UnsafeCell).
- 主要语言
- 没有语言数据
- 星标
- 760
- 派生
- 68
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
rust-lang/unsafe-code-guidelines 的其他 Issue
-
I-opsem-nominated
难度 4/5 3-5 天 新手友好度 35/100
rust-lang/unsafe-code-guidelines#634 · 5 条评论 ·
-
难度 5/5 一周以上 新手友好度 15/100
-
难度 5/5 一周以上 新手友好度 12/100
rust-lang/unsafe-code-guidelines#632 · 8 条评论 · 1 个 reaction ·
-
难度 5/5 一周以上 新手友好度 10/100
rust-lang/unsafe-code-guidelines#631 · 7 条评论 ·
-
I-opsem-nominated
难度 5/5 一周以上 新手友好度 20/100
rust-lang/unsafe-code-guidelines#630 · 1 个 reaction ·
查看 rust-lang/unsafe-code-guidelines 的全部 Issue
相似的 Issue
-
bug core-lang
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
Call-argument syntax diagnostic needs example spacing and removal of confusing trailing sentence未关闭
难度 2/5 1-3 小时 新手友好度 85/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
mw00/project-maya#1368 ·
维护者通常 2 天内回复
-
test(bind-json): legacy Solidity fixture requires an unavailable solc on Linux ARM64可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭
难度 2/5 1-3 小时 新手友好度 76/100
foundry-rs/foundry#18828 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 85/100
维护者通常 1 天内回复