RUSTSEC-2025-0001: gix-worktree-state nonexclusive checkout sets executable files world-writable
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
調査の方向性
advisory の詳細と、参照されている gix-worktree-state の checkout ファイル(checkout/function.rs、checkout/entry.rs、checkout/chunk.rs)から始めてください。PoC で説明されている Unix 系の checkout を再現し、destination_is_initially_empty を true に設定した場合の動作と比較してください。完了とは、報告された全ユーザー書き込み可能な実行権限が対処され、パッチ適用後のバージョンが反映されていることを意味します。
索引モデルが issue の本文から書いたものです。
説明
gix-worktree-state nonexclusive checkout sets executable files world-writable
| Details | |
|---|---|
| Package | gix-worktree-state |
| Version | 0.13.0 |
| URL | https://github.com/GitoxideLabs/gitoxide/security/advisories/GHSA-fqmf-w4xh-33rh |
| Date | 2025-01-18 |
| Patched versions | >=0.17.0 |
Summary
gix-worktree-state specifies 0777 permissions when checking out executable files, intending that the umask will restrict them appropriately. But one of the strategies it uses to set permissions is not subject to the umask. This causes files in a repository to be world-writable in some situations.
Details
Git repositories track executable bits for regular files. In tree objects and the index, regular file modes are stored as 0644 if not executable, or 0755 if executable. But this is independent of how the permissions are set in the filesystem (where supported).
gix_worktree_state::checkout has two strategies for checking out a file and marking it executable on a Unix-like operating system, one of which is vulnerable:
- If the file is created by assuming it does not already exist, correct permissions are applied, because permissions specified when opening a file are subject to the umask.
- If the file is considered possibly already to exist—even in a clean checkout if the application does not specify the option to treat the destination directory as empty—then permissions conferring unrestricted access to any user account on the system are wrongly applied, because permissions specified when calling chmod on an existing file are not subject to the umask.
Specifically, checkout::entry::checkout chooses the strategy for each file. The same strategy is usually chosen for each executable file, if no process (i.e. long running) smudge filter is in use. The strategy depends on the checkout::Options::destination_is_initially_empty value, which is passed along to checkout::entry::open_file, whose return value includes a flag indicating whether permissions still need to be set:
-
With
destination_is_initially_empty: true, executable permissions are specified when opening the file, viaOpenOptionsEx::mode, by its effect on the behavior ofOpenOptions::open. A mode of 0777 is safe here, for the same reason the default mode of 0666 is safe. When creating a file, the applied mode is the specified mode with any bits unset from it that are set in the umask.The
set_executable_after_creationflag in theopen_filereturn value is thenfalse. -
With
destination_is_initially_empty: false, executable permissions are set in a separate step, viaPermissionsExt::set_modeandset_permissions. A mode of 0777 is not safe here, because the umask is not applied. The vulnerable code appears incheckout::entry::finalize_entry, which receives theset_executable_after_creationflag originally fromopen_file:The file has unrestricted permissions.
finalize_entry is likewise called from checkout::chunk::process_delayed_filter_results.
PoC
-
On a Unix-like system such as GNU/Linux or macOS, create a new project and define its dependencies. While the vulnerability is in
gix-worktree-state, this example will use vulnerable code through thegixcrate, which exposes it. Run:cargo new checkout-index cd checkout-index cargo add gix gix-object -
In the
checkout-indexdirectory, editsrc/main.rsso that its entire contents are:fn main() -> Result<(), Box<dyn std::error::Error>> { let repo = gix::discover("has-executable")?; let mut index = repo.open_index()?; gix::worktree::state::checkout( &mut index, repo.work_dir().ok_or("need non-bare repo")?, gix_object::find::Never, // Can also use: repo.objects.clone() &gix::progress::Discard, &gix::progress::Discard, &Default::default(), Default::default(), )?; Ok(()) } -
Create the test repository that the vulnerable program will operate on. Still in the
checkout-indexdirectory, run:git init has-executable touch has-executable/a has-executable/b chmod +x has-executable/b git -C has-executable add .It is not necessary to commit the changes, only to stage them, since the test program will check out the index.
-
Optionally, run
rm has-executable/[ab]to remove the staged files from disk. -
Run the program by issuing
cargo run. The program usesgix-worktree-stateto check out the index. It should terminate successfully and not issue any errors. -
Run
ls -l has-executableto inspect the permissions of the checked out files. Observe that owner, group, and other all have read, write, and execute permissions onb.-rw-r--r-- 1 ek ek 0 Jan 9 03:38 a -rwxrwxrwx 1 ek ek 0 Jan 9 03:38 bWith affected versions of
gix-worktree-state, the output shows-rwxrwxrwxforb, whether the files were removed in step 4 or not. -
It was not necessary to set
destination_is_initially_emptytofalseexplicitly to trigger the bug, because that is its default value. If desired, modify the program to passtrueand rerun the experiment to verify thatbis no longer created with excessive permissions. The modified program would change the lastcheckoutargument fromDefault::default(),to:gix::worktree::state::checkout::Options { destination_is_initially_empty: true, ..Default::default() },
Impact
Setting unlimited file permissions is a problem on systems where a user account exists on the system that should not have the ability to access and modify the files. That applies to multi-user systems, or when an account is used to run software with reduced abilities. (Some programs may also treat broad write permissions to mean less validation is required.)
This bug affects Unix-like systems but not Windows. The gix clone command is not believed to be affected, due to checkout_exclusive's use of destination_is_initially_empty: true. Specialized uses in which repositories are known never to have any files marked executable are unaffected. Repositories that no untrusted users can access, due to not having the ability to traverse the directories to them or due to sufficiently restrictive ACLs, are likewise unaffected.
The default value of destination_is_initially_empty is false, so some applications may be affected even if they don't attempt checkouts in nonempty directories. The 0777 permissions are applied to files that are created earlier in the same checkout, as well as those that already existed, regardless of their prior permissions. On preexisting files, 0777 is set even if overwrite_existing is false, as that prevents the checkout from changing file contents but not permissions.
Files not tracked/staged as executable are not checked out with insecure permissions. Such a file that previously existed keeps its old permissions. However, this may include executable permissions that no longer match repository metadata, as well as undesired write permissions acquired from a previous vulnerable checkout. set_mode(0o777) clears other bits, so the bug is not exacerbated by the presence of setuid/setgid bits. In some applications, the vulnerable strategy may be used only for files rewritten by a long running smudge filter or only in the presence of delays.
See advisory page for additional details.
- 主要言語
- Rust
- スター
- 2k
- フォーク
- 203
- 平均マージ
- 1日 22時間
- マージ済み PR(30日)
- 15
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
rustsec/rustsec のほかの issue
-
rustsec_refs_imported() could possibly panic on short or malformed rustsec.org URLs対応中かも @chiliec が 42 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
rustsec/rustsec#1601 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 3/5 1〜2日 初心者へのやさしさ 55/100
rustsec/rustsec#1591 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 5/5 1週間以上 初心者へのやさしさ 30/100
rustsec/rustsec#1576 · コメント 3 件 · リアクション 2 件 ·
メンテナーはふだん 1 日以内に返信
-
advisory linter requires affected functions to start with package rather than crate name対応中かも @MartinNowak が 176 日前に担当しました。 オープン
難易度 3/5 1〜2日 初心者へのやさしさ 48/100
rustsec/rustsec#1575 · コメント 14 件 ·
メンテナーはふだん 1 日以内に返信
rustsec/rustsec の issue をすべて見る
似ている issue
-
[Feature] 设置里面的同步功能オープンenhancement user-priority/P2
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
メンテナーはふだん 1 日以内に返信
-
agent:triaged bug bughunt pm:npm priority:p1
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
SocketDev/socket-patch#1127 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
メンテナーはふだん 1 日以内に返信