Object::clone, Repository::config and Repository::index can wrap libgit2 reference counts

Aperta
#1,358 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
25/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
rust
Ambito
backend

Direzione di ricerca

Start by tracing Object::clone, Repository::config and Repository::index in git2-rs to the bundled libgit2 reference count increments described in the report. The issue asks for checks on those increments; the payload does not name the bundled source files or tests. Done means the three reproductions no longer allow reference counts to wrap and the reported use-after-free paths are addressed.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

libgit2 1.9.7, which libgit2-sys bundles, keeps reference counts in a 32-bit atomic int and does not check them before incrementing.

Object::clone calls git_object_dup. With one handle, one surviving clone and the reference held by libgit2's object cache, forgetting 2^32 - 2 further clones (std::mem::forget is safe) and dropping the original frees the object. The surviving handle's next call, Object::kind, reads freed memory.

Repository::config() and Repository::index() return the repository's cached config or index with its count incremented. GIT_REFCOUNT_DEC frees when the decremented count is <= 0 and the owner pointer is null, so 2^31 - 1 forgotten handles are enough. Dropping the Repository then frees the config or index while a Config or Index handle remains.

We ran all three paths with git2 0.21.0 (bundled libgit2 1.9.7) and a program with no unsafe code. AddressSanitizer reports a heap use-after-free in Object::kind, Config::get_string and Index::len. We reported this to libgit2 privately and have had no reply. Could you patch the bundled libgit2 to check these increments?

Lingua principale
Rust
Stelle
2.1k
Fork
470
Merge medio
2g 17h
PR unite (30g)
18

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di rust-lang/git2-rs

Tutte le issue di rust-lang/git2-rs

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.