install: post-copy finalization reopens destination by path, allowing symlink-swap redirection
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 24.1k
- Forks
- 2k
- Avg merge
- 1d 5h
- Merged PRs (30d)
- 365
Description
install safely creates the destination file relative to a parent directory fd, but then falls back to path-based post-copy finalization on the original destination pathname.
That finalization path includes --strip-program, chmod, timestamp updates, and some SELinux handling. If an attacker can replace the destination leaf with a symlink after the copy step but before finalization, those later operations can be redirected to a different file.
This is reproducible with install -s --strip-program ...: a delayed strip helper gives enough time to swap dest to dest -> victim, and the helper then writes to victim instead of the file install created.
Impact:
- Real TOCTOU vulnerability on Unix
- High risk when
installis used in a privileged workflow - The safe write phase and the finalization phase do not stay bound to the same inode
Root cause:
- Safe create/write by fd
- Unsafe finalization by pathname
Suggested fix:
- Keep the destination file open through finalization
- Perform strip/metadata updates via that file handle
- Reject destination path changes before success
- Use
O_NOFOLLOW | O_EXCLfor fd-based destination creation
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the install implementation's fd-based destination creation and path-based post-copy finalization, especially the --strip-program flow. Reproduce the symlink swap with a delayed strip helper, then trace chmod, timestamp, and SELinux handling. Done means finalization remains bound to the created file and destination path changes cannot redirect operations.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- cli, security
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100