Best practices for sharing memory with untrusted parties
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Aptitud para principiantes
- 25/100
Línea de trabajo
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.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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).
- Lenguaje dominante
- Sin datos de lenguaje
- Estrellas
- 760
- Forks
- 68
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Preparar el entorno
Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de rust-lang/unsafe-code-guidelines
-
I-opsem-nominated
Dificultad 4/5 3-5 días Aptitud para principiantes 35/100
rust-lang/unsafe-code-guidelines#634 · 5 comentarios ·
-
Dificultad 5/5 Más de una semana Aptitud para principiantes 15/100
-
Dificultad 5/5 Más de una semana Aptitud para principiantes 12/100
rust-lang/unsafe-code-guidelines#632 · 8 comentarios · 1 reacción ·
-
Dificultad 5/5 Más de una semana Aptitud para principiantes 10/100
rust-lang/unsafe-code-guidelines#631 · 7 comentarios ·
-
I-opsem-nominated
Dificultad 5/5 Más de una semana Aptitud para principiantes 20/100
rust-lang/unsafe-code-guidelines#630 · 1 reacción ·
Todos los issues de rust-lang/unsafe-code-guidelines
Issues similares
-
bug core-lang
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día
-
Call-argument syntax diagnostic needs example spacing and removal of confusing trailing sentenceAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
mw00/project-maya#1368 ·
Los mantenedores suelen responder en 2 días
-
test(bind-json): legacy Solidity fixture requires an unavailable solc on Linux ARM64Posiblemente ocupada Un pull request vinculado a esta issue está abierto o ya se fusionó. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
foundry-rs/foundry#18828 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
Los mantenedores suelen responder en 1 día