Investigate unsound mapped RwLock write guard downgrading
Los mantenedores suelen responder en 1 día
Evaluación
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Aptitud para principiantes
- 25/100
- Tipo de issue
- Error
- Claridad
- Bastante claro
- Estado de actividad
- Activo
- Stack tecnológico
- rust
- Área
- backend, testing-qa
Línea de trabajo
Start by reviewing MappedRwLockWriteGuard::downgrade and OwnedMappedRwLockWriteGuard::downgrade, along with the mapped-guard history in #65, #61, #62, and the closed proposal in #358. Run the safe reproducer under Miri and compare it with downgrading the original write guard before projecting a shared reference. Done means verifying the soundness concern and reaching an agreed API contract and solution.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Summary
@orthur2 @jeffoodchain Could you help verify the soundness issue below and discuss the appropriate API contract and solution?
MappedRwLockWriteGuard::downgrade and OwnedMappedRwLockWriteGuard::downgrade retain a pointer obtained from an arbitrary mutable projection while allowing other readers of the original value. A safe-code reproducer triggers undefined behavior under Miri. This issue tracks verification and the solution; the attempted fix in #358 has been closed pending discussion.
Reproducer
The following entirely safe program reproduces the problem on commit 44fc2d8:
use asyncband::rwlock::{RwLock, RwLockWriteGuard};
use std::sync::Mutex;
fn main() {
let lock = RwLock::new(Mutex::new(0u8));
let write = RwLockWriteGuard::map(lock.try_write().unwrap(), |inner| {
inner.get_mut().unwrap()
});
let read = write.downgrade();
let shared = &*read;
let outer = lock.try_read().unwrap();
*outer.lock().unwrap() = 1;
println!("{shared}");
}
Miri reports that the later mutable access through outer.lock() invalidates the shared reference. The corresponding owned mapped guard reproducer also fails.
Soundness concern
The mutable projection &mut T -> &mut U can reach interior-mutable storage using exclusive access, as Mutex::get_mut does here. After downgrading, another reader of the original T can mutate that storage through its interior-mutability API while the mapped guard still exposes &U.
Both Mutex<u8> and u8 are Send + Sync, so adding those bounds alone does not address this example. The expected behavior is that safe guard operations cannot permit mutation that invalidates a live shared reference.
History and possible solutions
- #65 introduced both mapped downgrade methods; they first shipped in mea 0.4.2 on 2025-08-30 and remain present in v0.7.3. This is not new in 0.7.3.
- #62 tracks the original write-lock downgrade request; #61 contains the preceding mapped-guard work and follow-up discussion.
- #358 contains the reproduction analysis and a proposed removal, but is closed pending agreement on the solution.
Keeping all exclusive permits appears sound but continues blocking readers, changing the downgrade contract. Downgrading the original write guard before applying a shared projection is another option: RwLockReadGuard::map(write.downgrade(), |root| &root.field) retains the lock throughout. A convenience API accepting a projection from the original &T could express the same boundary, but cannot simply reuse an arbitrary mutable projection.
Could you confirm whether the reproducer and reasoning establish that these APIs are unsound, and help decide whether to remove mapped downgrading or support it under a different contract?
- Lenguaje dominante
- Rust
- Estrellas
- 277
- Forks
- 44
- Merge medio
- 1 d 9 h
- PR fusionados (30 d)
- 39
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 apache/asyncband
-
Tracking Issue to Release 0.7.4Posiblemente ocupada @QwQBiG la tomó hace 2 días. Abierto
apache/asyncband#369 · 2 comentarios · 1 asignado ·
Los mantenedores suelen responder en 1 día
-
Dificultad 3/5 1-2 días Aptitud para principiantes 55/100
apache/asyncband#360 · 3 comentarios ·
Los mantenedores suelen responder en 1 día
-
enhancement good first issue help wanted
Dificultad 5/5 Más de una semana Aptitud para principiantes 35/100
apache/asyncband#324 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Discuss shared broadcast receives without a Clone boundPosiblemente ocupada @orthur2 la tomó hace 5 días. Abiertoenhancement question
Dificultad 5/5 Más de una semana Aptitud para principiantes 30/100
apache/asyncband#312 · 5 comentarios ·
Los mantenedores suelen responder en 1 día
-
enhancement help wanted
Dificultad 5/5 Más de una semana Aptitud para principiantes 35/100
apache/asyncband#298 · 7 comentarios ·
Los mantenedores suelen responder en 1 día
Todos los issues de apache/asyncband
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
adorsys/status-list-server#698 ·
Los mantenedores suelen responder en 2 días
-
Expose the dot grid colourAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
nannou-org/egui_graph#92 ·
Los mantenedores suelen responder en 1 día
-
documentation good first issue
Dificultad 2/5 Medio día Aptitud para principiantes 72/100
sujithputta02/Esapay#13 ·
-
Deduplicate normalized_f64_bits (hash_table.rs and bloom_filter.rs)Posiblemente ocupada Un pull request vinculado a esta issue está abierto o ya se fusionó. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
tursodatabase/turso#10002 ·
Los mantenedores suelen responder en 1 día
-
needs triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
topgrade-rs/topgrade#2419 ·
Los mantenedores suelen responder en 1 día