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

Abierto
#1,358 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todaví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

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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?

Lenguaje dominante
Rust
Estrellas
2.1k
Forks
470
Merge medio
2 d 17 h
PR fusionados (30 d)
18

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de rust-lang/git2-rs

Todos los issues de rust-lang/git2-rs

Issues similares

Más issues de Rust

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.