Aliasing UB in Convert for &mut T and Buf (Miri Stacked/Tree borrow violations)
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Aptitud para principiantes
- 74/100
Línea de trabajo
Start by reading the Convert implementation in src/call.rs and the Buf Binding implementation in src/buf.rs, then inspect the corresponding uses of raw. Run the Miri-based tests that exercise these paths through libgit2. Done means the conversions preserve valid mutation permissions and the tests no longer report stacked- or tree-borrow violations.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Hi, I have found the following aliasing bugs in git2.
Convert for &mut T in src/call.rs
The first problem is as follows:
impl<T> Convert<*mut T> for &mut T {
fn convert(&self) -> *mut T {
&**self as *const T as *mut T
}
}
The problem is it first created a shared ref &**self, then cast it to a mutable raw pointer. So mutating through the raw pointer is UB.
Fix:
impl<T> Convert<*mut T> for &mut T {
fn convert(&self) -> *mut T {
unsafe { ptr::read(self) as *mut T }
}
}
copy the &mut T out of *self instead of reborrowing so the pointer keeps write permission.
raw in src/buf.rs
The problem is in:
pub struct Buf {
raw: raw::git_buf,
}
impl Binding for Buf {
type Raw = *mut raw::git_buf;
unsafe fn from_raw(raw: *mut raw::git_buf) -> Buf {
Buf { raw: *raw }
}
fn raw(&self) -> *mut raw::git_buf {
&self.raw as *const _ as *mut _
}
}
It is a similar problem, casting a shared reference to a mutable pointer. So mutating it results in a UB.
Fix: use a cell which allows interior mutability:
pub struct Buf {
raw: UnsafeCell<raw::git_buf>,
}
also, update the corresponding sites that uses raw.
I have run confirmed the bug running it using the MiriLLI tools (with tests that calls these from libgit2). The two are UB under both tree borrow and stacked borrow models.
I am happy to open a PR to fix these bugs. Thanks
- Lenguaje dominante
- Rust
- Estrellas
- 2.1k
- Forks
- 470
- Merge medio
- 2 d 17 h
- PR fusionados (30 d)
- 18
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Sin plantilla de pull request
- Leer la guía de contribución
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/git2-rs
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
Los mantenedores suelen responder en 1 día
-
`stash_foreach` crashes on stash entries with no message or a non-UTF-8 messagePosiblemente ocupada @shivampwm2020 la tomó hace 43 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día
-
Dificultad 3/5 1-2 días Aptitud para principiantes 68/100
Los mantenedores suelen responder en 1 día
-
Dificultad 3/5 1-2 días Aptitud para principiantes 64/100
Los mantenedores suelen responder en 1 día
Todos los issues de rust-lang/git2-rs
Issues similares
-
bug P2
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 85/100
Los mantenedores suelen responder en 1 día
-
Windows microphone listing treats words in a device name as DirectShow labelsPosiblemente ocupada @Sujal-chaudhary la tomó hoy. Abiertobug
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
clipy-recorder/clipy#447 · 2 comentarios ·
Los mantenedores suelen responder en 1 día
-
nightly-cleanup
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
max-sixty/worktrunk#4939 · 1 reacción ·
Los mantenedores suelen responder en 1 día
-
[Flaky Test] tests::signer::v0::miner_recovers_when_broadcast_block_delay_across_tenures_occursAbiertoflaky
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
stacks-network/stacks-core#7918 · 1 comentario ·
Los mantenedores suelen responder en 2 días