# `Repository::rebase` does not keep `RebaseOptions` borrowed, but libgit2 keeps pointers into them (use-after-free in safe code)
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 18/100
Línea de trabajo
The bug is in src/repo.rs (Repository::rebase and open_rebase, around lines 2410-2444), which borrow RebaseOptions only for the call, and in src/build.rs (CheckoutBuilder::configure and progress_cb, around lines 567-611), which hands libgit2 pointers into the options. Start by reproducing the use-after-free with the snippet, ideally under AddressSanitizer. Done means the signature ties the Rebase lifetime to the options (or Rebase owns the checkout state) so the snippet no longer compiles unsafely, with existing rebase tests passing.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
git_rebase_init and git_rebase_open store a shallow copy of the git_rebase_options they are
given (rebase_alloc, rebase.c:292) and use its checkout options again in git_rebase_next
(rebase.c:764) and git_rebase_abort (:1206). RebaseOptions::raw fills those through
CheckoutBuilder::configure (src/build.rs:567-600), so the callback payloads point at the
CheckoutBuilder inside the RebaseOptions, and the path, target directory and label pointers
point at its strings. Repository::rebase and open_rebase (src/repo.rs:2410-2444) borrow the
options only for the call, so safe code can drop or move them while the Rebase is alive:
#![forbid(unsafe_code)]
use git2::build::CheckoutBuilder;
use git2::{RebaseOptions, Repository, Signature};
fn main() {
let dir = std::env::temp_dir().join(format!("rebase-opts-uaf-{}", std::process::id()));
let repo = Repository::init(&dir).unwrap();
let sig = Signature::now("a", "[email protected]").unwrap();
let tree = repo.find_tree(repo.index().unwrap().write_tree().unwrap()).unwrap();
let base = repo.commit(Some("HEAD"), &sig, &sig, "base", &tree, &[]).unwrap();
let base = repo.find_commit(base).unwrap();
let tip = repo.commit(Some("HEAD"), &sig, &sig, "tip", &tree, &[&base]).unwrap();
let branch = repo.find_annotated_commit(tip).unwrap();
let upstream = repo.find_annotated_commit(base.id()).unwrap();
let mut checkout = CheckoutBuilder::new();
checkout.progress(|_path, cur, total| println!("checkout progress {cur}/{total}"));
let mut opts = Box::new(RebaseOptions::new());
opts.checkout_options(checkout);
let mut rebase = repo.rebase(Some(&branch), Some(&upstream), None, Some(&mut opts)).unwrap();
drop(opts);
rebase.next().unwrap().unwrap(); // progress_cb runs with the freed CheckoutBuilder as payload
}
With git2-rs at b9d59b6 (main), vendored libgit2 1.9.7, under AddressSanitizer (trimmed):
ERROR: AddressSanitizer: heap-use-after-free on address 0x6ee7561f70b8
READ of size 8 at 0x6ee7561f70b8 thread T0
#0 git2::build::progress_cb::{closure#0} src/build.rs:611:30
#7 report_progress libgit2/src/libgit2/checkout.c:1722:3
#9 git_checkout_index libgit2/src/libgit2/checkout.c:2734:11
#10 rebase_next_merge libgit2/src/libgit2/rebase.c:836:12
#11 git_rebase_next libgit2/src/libgit2/rebase.c:924:11
0x6ee7561f70b8 is located 184 bytes inside of 488-byte region [0x6ee7561f7000,0x6ee7561f71e8)
freed by thread T0 here:
#5 main src/main.rs:34:5
Without a sanitizer the program exits normally and the callback still runs through the dangling
payload.
Possible fix
Keep the options borrowed for as long as the rebase lives, e.g.
pub fn rebase<'a>(&'a self, .., opts: Option<&'a mut RebaseOptions<'_>>) -> Result<Rebase<'a>, Error>
and the same for open_rebase, or have Rebase own the checkout state that libgit2 points at.
Found by Crustify, an experimental
UB/soundness auditing agent developed at UC Berkeley and running on Claude Opus 5.5, then
manually reviewed and independently reproduced.
- 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