gix-worktree-state
Affected
- introduced
0.0.0-0, fixed0.17.0(semver)
Fixed versions
0.17.0
Fix
- Fixed version
0.17.0cargo update -p gix-worktree-state --precise 0.17.0
Advisory
Also known as: CVE-2025-22620, GHSA-fqmf-w4xh-33rh
gix-worktree-state nonexclusive checkout sets executable files world-writable
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:
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:
destination_is_initially_empty: true, executable permissions are specified when opening the file, via `OpenOptionsEx::mode`, by its effect on the behavior of `OpenOptions::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_creation flag in the open_file return value is then false.
destination_is_initially_empty: false, executable permissions are set in a separate step, via `PermissionsExt::set_mode` and `set_permissions`. A mode of 0777 is not safe here, because the umask is not applied. The vulnerable code appears in `checkout::entry::finalize_entry`, which receives the set_executable_after_creation flag originally from open_file:The file has unrestricted permissions.
finalize_entry is likewise called from `checkout::chunk::process_delayed_filter_results`.
PoC
gix-worktree-state, this example will use vulnerable code through the gix crate, which exposes it. Run: cargo new checkout-index
cd checkout-index
cargo add gix gix-object
checkout-index directory, edit src/main.rs so 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(())
}
checkout-index directory, 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.
rm has-executable/[ab] to remove the staged files from disk.cargo run. The program uses gix-worktree-state to check out the index. It should terminate successfully and not issue any errors.ls -l has-executable to inspect the permissions of the checked out files. Observe that owner, group, and other all have read, write, and execute permissions on b. -rw-r--r-- 1 ek ek 0 Jan 9 03:38 a
-rwxrwxrwx 1 ek ek 0 Jan 9 03:38 b
With affected versions of gix-worktree-state, the output shows -rwxrwxrwx for b, whether the files were removed in step 4 or not.
destination_is_initially_empty to false explicitly to trigger the bug, because that is its default value. If desired, modify the program to pass true and rerun the experiment to verify that b is no longer created with excessive permissions. The modified program would change the last checkout argument from Default::default(), to: gix::worktree::state::checkout::Options {
destination_is_initially_empty: true,
..Default::default()
},Medium Basis: CVSS v3 score 5, vector CVSS:3.1/AV:L/AC:L/PR:L/UI:R/S:U/C:N/I:H/A:N
0.0.0-0, fixed 0.17.0 (semver)0.17.0
0.17.0cargo update -p gix-worktree-state --precise 0.17.0Fix commands are the export's own generic commands. Ojuju never runs them. Check them against your setup first.
Check your own computer: guard packages check
Source: RustSec Advisory Database · CC0-1.0