Repository navigation
Description
install -D cannot create leading directories inside a directory that is writable and searchable but not readable. GNU creates them.
$ mkdir wx && chmod 300 wx && echo hi > f
$ install -D f wx/sub/f # uutils main at 2b85f6f12
install: cannot create directory 'wx/sub'
$ ginstall -D f wx/sub/f # GNU 9.12, built from source
$ echo $?
0
mkdir wx/sub works with those permissions, so nothing about the operation requires read access. Across directory modes, as a non-root user, creating d<mode>/x:
| mode | GNU | uutils -D |
|---|---|---|
300 (-wx) |
creates it | fails: cannot create directory 'd300/x' |
333 (-wx for all) |
creates it | fails: cannot create directory 'd333/x' |
700, 733, 755 |
creates it | creates it |
The cause is in create_dir_all_safe: it opens the deepest existing ancestor with DirFd::open, which uses O_RDONLY | O_DIRECTORY. That needs read permission on the directory, while mkdirat only needs write and execute. This has been the behaviour since #10140 moved -D to the fd-anchored walk; the TOCTOU hardening itself is fine, it is only the way the anchor fd is obtained that is too strict.
install -d is not affected - it creates directories path-based. Installing into an existing write-only directory is not affected either, only creating leading directories. Other DirFd::open callers (rm, du, chmod, chcon, perms) read directory entries, so they need read permission anyway.
An earlier version of this issue said macOS has no search-only open flag. That is wrong: it has O_SEARCH (O_EXEC | O_DIRECTORY). Both platforms can anchor *at calls on an unreadable directory, measured on a 0300 directory as a non-root user:
| through the anchor fd | Linux O_PATH |
macOS O_SEARCH |
|---|---|---|
| open the write-only directory | ok | ok |
mkdirat, openat child dir |
ok | ok |
openat file with O_CREAT |
ok | ok |
fstatat, fchmodat, fchownat, renameat, linkat, unlinkat, utimensat |
ok | - |
plain O_RDONLY | O_DIRECTORY |
EACCES |
EACCES |
Two things to watch on Linux, both measured: O_PATH ignores O_DIRECTORY, so a regular file opens happily and the descriptor has to be checked with fstat; and O_PATH | O_NOFOLLOW | O_DIRECTORY on a symlink to a directory succeeds and resolves the symlink, so a search-only descriptor cannot carry a NoFollow guarantee. A fix must keep the fallback on symlink-following opens only, or it silently undoes #10140.
Activity
abendrothj commentedon Oct 1, 2026
Rechecked against GNU 9.12 built from the release tarball: same results as 9.10 for every mode in the table. I've updated the versions in the description, and the uutils lines to what current main (
2b85f6f12) prints.