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

未关闭
#1,358 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
5/5
预计耗时
一周以上
新手友好度
25/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
活跃
技术栈
rust
领域
backend

调研方向

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.

由索引模型根据 Issue 内容生成。

描述

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?

主要语言
Rust
星标
2.1k
派生
470
平均合并
2 天 17 小时
30 天内合并 PR
18

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

rust-lang/git2-rs 的其他 Issue

查看 rust-lang/git2-rs 的全部 Issue

相似的 Issue

更多 Rust Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。