# `Repository::rebase` does not keep `RebaseOptions` borrowed, but libgit2 keeps pointers into them (use-after-free in safe code)
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
調査の方向性
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.
索引モデルが issue の本文から書いたものです。
説明
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.
- 主要言語
- Rust
- スター
- 2.1k
- フォーク
- 470
- 平均マージ
- 2日 17時間
- マージ済み PR(30日)
- 18
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
rust-lang/git2-rs のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
メンテナーはふだん 1 日以内に返信
-
`stash_foreach` crashes on stash entries with no message or a non-UTF-8 message対応中かも @shivampwm2020 が 43 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
難易度 3/5 1〜2日 初心者へのやさしさ 68/100
メンテナーはふだん 1 日以内に返信
-
難易度 3/5 1〜2日 初心者へのやさしさ 64/100
メンテナーはふだん 1 日以内に返信
rust-lang/git2-rs の issue をすべて見る
似ている issue
-
bug P2
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
メンテナーはふだん 1 日以内に返信
-
Windows microphone listing treats words in a device name as DirectShow labels対応中かも @Sujal-chaudhary が今日担当しました。 オープンbug
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
clipy-recorder/clipy#447 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
-
nightly-cleanup
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
max-sixty/worktrunk#4939 · リアクション 1 件 ·
メンテナーはふだん 1 日以内に返信
-
[Flaky Test] tests::signer::v0::miner_recovers_when_broadcast_block_delay_across_tenures_occursオープンflaky
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
stacks-network/stacks-core#7918 · コメント 1 件 ·
メンテナーはふだん 2 日以内に返信