Skip to content

Chmod preserve root - #10033

Merged
sylvestre merged 2 commits into
uutils:mainfrom
cerdelen:chmod_preserve_root
Jan 7, 2026
Merged

Chmod preserve root#10033
sylvestre merged 2 commits into
uutils:mainfrom
cerdelen:chmod_preserve_root

Conversation

@cerdelen

@cerdelen cerdelen commented Jan 3, 2026

Copy link
Copy Markdown
Contributor

Previously the --preserve-root flag could be bypassed because it was only compared to "/" so anyhting that resolved to root but wasn't literally "/" would not be caught.

Also added regression test.

Fixes: #10018

@sylvestre
sylvestre merged commit 413055b into uutils:main Jan 7, 2026
131 checks passed
@cerdelen
cerdelen deleted the chmod_preserve_root branch January 24, 2026 13:24
sylvestre added a commit that referenced this pull request Jul 31, 2026
--preserve-root was only enforced for the paths named on the command line
(the operand loop in Chmoder::chmod). With -R -L, a symlink encountered
*inside* the tree that resolves to / was followed, and the recursion walked
into the real root, defeating the failsafe.

Reproduced in a sandboxed root: a tree containing `link -> /` with
`chmod -R -L --preserve-root 777 tree` took an unrelated 0700 directory to
0777. GNU coreutils 9.10 refuses the same case.

Re-check the guard at every descent, in both walk_dir_with_context variants
so unix, non-unix and redox are all covered. Only symlinks are canonicalized,
so ordinary recursive trees are unaffected.

Behaviour now matches GNU: diagnose with the "(same as '/')" wording, skip the
subtree, continue, and exit 1 -- rather than aborting the whole run.

chown/chgrp already did this in 5c2c38c; chmod was the outlier. PR #10033
fixed only the operand-level "resolves to /" case.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

chmod: --preserve-root can be bypassed with any directory that resolves to root

2 participants