Aliasing UB in Convert for &mut T and Buf (Miri Stacked/Tree borrow violations)
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 74/100
Direzione di ricerca
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.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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
- Lingua principale
- Rust
- Stelle
- 2.1k
- Fork
- 470
- Merge medio
- 2g 17h
- PR unite (30g)
- 18
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di rust-lang/git2-rs
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
I maintainer di solito rispondono entro 1 giorno
-
`stash_foreach` crashes on stash entries with no message or a non-UTF-8 messageForse già presa @shivampwm2020 l’ha presa 43 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 68/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 64/100
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di rust-lang/git2-rs
Issue simili
-
bug P2
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
I maintainer di solito rispondono entro 1 giorno
-
Windows microphone listing treats words in a device name as DirectShow labelsForse già presa @Sujal-chaudhary l’ha presa oggi. Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
clipy-recorder/clipy#447 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
nightly-cleanup
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
max-sixty/worktrunk#4939 · 1 reazione ·
I maintainer di solito rispondono entro 1 giorno
-
[Flaky Test] tests::signer::v0::miner_recovers_when_broadcast_block_delay_across_tenures_occursApertaflaky
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
stacks-network/stacks-core#7918 · 1 commento ·
I maintainer di solito rispondono entro 2 giorni