Description
When install -D or install -d creates ancestor directories, the process umask still applies to them. GNU install creates ancestor directories at exactly 0755 whatever the caller's umask is.
Impact
Ancestor modes when creating a/b as a non-root user on Linux (uutils main at 2b85f6f, GNU 9.12 built from source):
| umask |
GNU -D and -d |
uutils install -D f a/b/f |
uutils install -d a/b (ancestor a) |
0022 |
0755 |
0755 |
0755 |
0002 |
0755 |
0755 |
0775 |
0027 |
0755 |
0750 |
0750 |
0077 |
0755 |
0700 |
0700 |
0111 |
0755 |
a is 0644, then cannot create directory 'a/b' |
a is 0666, then cannot create directory 'a/b': Permission denied |
-D starts its ancestors from 0755 and -d from 0777, and the umask is then applied to both. Under umask 0002 (the trigger for #11363) -D happens to give 0755, so that report came from a broken test, but -d diverges there too.
Affected code
src/uu/install/src/install.rs: both code paths (directory() line ~498 and standard() line ~687) create ancestor directories without zeroing umask first
src/uucore/src/lib/features/safe_traversal.rs: create_dir_all_safe documents that "the actual mode will be modified by the process umask"
Fix
Zero the process umask early in install's uumain (unix only). uucore::mode already uses rustix::process::umask internally for get_umask(); a zero_umask() helper can be exported from there.
Related: #11363, PR #12713
Description
When
install -Dorinstall -dcreates ancestor directories, the process umask still applies to them. GNUinstallcreates ancestor directories at exactly0755whatever the caller's umask is.Impact
Ancestor modes when creating
a/bas a non-root user on Linux (uutils main at 2b85f6f, GNU 9.12 built from source):-Dand-dinstall -D f a/b/finstall -d a/b(ancestora)002207550755075500020755075507750027075507500750007707550700070001110755ais0644, thencannot create directory 'a/b'ais0666, thencannot create directory 'a/b': Permission denied-Dstarts its ancestors from0755and-dfrom0777, and the umask is then applied to both. Under umask0002(the trigger for #11363)-Dhappens to give0755, so that report came from a broken test, but-ddiverges there too.Affected code
src/uu/install/src/install.rs: both code paths (directory()line ~498 andstandard()line ~687) create ancestor directories without zeroing umask firstsrc/uucore/src/lib/features/safe_traversal.rs:create_dir_all_safedocuments that "the actual mode will be modified by the process umask"Fix
Zero the process umask early in
install'suumain(unix only).uucore::modealready usesrustix::process::umaskinternally forget_umask(); azero_umask()helper can be exported from there.Related: #11363, PR #12713