Skip to content

chmod, chown: check --preserve-root on the directory actually descended into - #14972

Merged
sylvestre merged 2 commits into
uutils:mainfrom
abendrothj:chmod-chown-operand-by-fd
Nov 8, 2026
Merged

sylvestre merged 2 commits into
uutils:mainfrom
abendrothj:chmod-chown-operand-by-fd

Conversation

@abendrothj

@abendrothj abendrothj commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

The recursive operand of chmod, chown and chgrp was checked against --preserve-root with its own path lookup, separate from the one the change and the descent used. A rename landing in between could send a -H/-L recursion into "/" after the check had passed.

On Linux, chown/chgrp now also decide on the stat that the operand's descriptor is already verified against. chmod opens the operand, checks that descriptor, and changes its mode through it; it still reopens the directory to descend, like GNU, and only continues if it is the same directory. Under -P this also stops the operand's own mode change from following a symlink swapped in at the directory's name, unless the open itself is refused and chmod goes by path. If the operand can't be opened because it isn't readable yet, the system refuses it (EPERM, as under a macOS sandbox) or this process has no descriptor left, chmod changes its mode by name, as GNU does; other errors are reported.

test_chmod_recursive_descends_only_into_the_directory_it_changed races a thread that re-points the operand, over 200 runs. Without the change it failed 10 of 10 times on Linux and on macOS; with it, it passed every time (30 on Linux, 20 on macOS), in about 0.3 s on Linux. test_chmod_recursive_operand_refused_by_sandbox runs only on macOS, through sandbox-exec. Run on macOS and Linux; FreeBSD, Android and Redox are only cross-checked with clippy.

Closes #14990

Copilot AI balanced review requested due to automatic review settings September 30, 2026 02:28

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@codspeed

codspeed Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

1 warning, 1 note

⚠️ 124 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

ℹ️ 1 benchmark has no flamegraph

The flamegraph wasn't generated: most of the time was spent in runtime internals, which would leave nothing useful to analyze.

See affected benchmarks

✅ 401 untouched benchmarks
⏩ 70 skipped benchmarks1


Comparing abendrothj:chmod-chown-operand-by-fd (683dd8a) with main (4a78f16)

Open in CodSpeed

Footnotes

  1. 70 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@github-actions

github-actions Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

GNU testsuite comparison:

Skip an intermittent issue tests/date/resolution (fails in this run but passes in the 'main' branch)

@xtqqczze

This comment was marked as resolved.

@xtqqczze

This comment was marked as outdated.

@abendrothj

Copy link
Copy Markdown
Contributor Author

Opened #14990.

Copilot AI balanced review requested due to automatic review settings October 1, 2026 01:17
@abendrothj
abendrothj force-pushed the chmod-chown-operand-by-fd branch from b5edd8c to ab7438f Compare October 1, 2026 01:17

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@abendrothj

Copy link
Copy Markdown
Contributor Author

The SELinux GNU job failed while booting its VM, before any test ran; unrelated to this change.

Comment thread src/uu/chmod/src/chmod.rs Resolved
Comment thread src/uu/chmod/src/chmod.rs Resolved
Comment thread src/uu/chmod/src/chmod.rs Resolved
Comment thread src/uu/chmod/src/chmod.rs Resolved
Comment thread src/uucore/src/lib/features/fs.rs Resolved
Comment thread src/uucore/src/lib/features/perms.rs Resolved
Copilot AI balanced review requested due to automatic review settings October 6, 2026 07:15

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@abendrothj
abendrothj force-pushed the chmod-chown-operand-by-fd branch from 0e38dba to a400b6f Compare October 6, 2026 23:17
Copilot AI balanced review requested due to automatic review settings October 6, 2026 23:17

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Copilot AI balanced review requested due to automatic review settings October 7, 2026 07:38

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@abendrothj
abendrothj marked this pull request as draft October 7, 2026 08:07
@abendrothj
abendrothj force-pushed the chmod-chown-operand-by-fd branch from 1066329 to 9989952 Compare October 7, 2026 08:12
@abendrothj

Copy link
Copy Markdown
Contributor Author

rebased on #15030: the gates here are Redox-only now, like the rest of chmod. with the old ones, chmod wouldn't have built on Hurd/AIX once both were merged (main + this failed Hurd clippy). cross-checked with clippy for Hurd and AIX, not run there. back out of draft once ci is green.

@abendrothj
abendrothj marked this pull request as ready for review October 7, 2026 14:48
Copilot AI balanced review requested due to automatic review settings October 7, 2026 14:48

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Copilot AI balanced review requested due to automatic review settings October 13, 2026 10:18
@abendrothj
abendrothj force-pushed the chmod-chown-operand-by-fd branch from ff34b06 to 2d04aa0 Compare October 13, 2026 10:18

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@abendrothj
abendrothj force-pushed the chmod-chown-operand-by-fd branch from 2d04aa0 to 73df228 Compare October 13, 2026 10:36
@xtqqczze

Copy link
Copy Markdown
Collaborator

AIX is only cross-checked with clippy (AIX with libc 0.2.189, see #15083).

You should be able to compile for AIX now with libc v0.2.191.

@abendrothj
abendrothj force-pushed the chmod-chown-operand-by-fd branch from 73df228 to ef4af3b Compare October 19, 2026 02:31
Copilot AI balanced review requested due to automatic review settings October 19, 2026 02:31

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.

@abendrothj

Copy link
Copy Markdown
Contributor Author

Thanks, clippy for powerpc64-ibm-aix passes now. Updated the description.

@sylvestre
sylvestre force-pushed the chmod-chown-operand-by-fd branch from ef4af3b to 07613f2 Compare October 25, 2026 09:31
Copilot AI balanced review requested due to automatic review settings October 25, 2026 09:31

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.

@sylvestre

Copy link
Copy Markdown
Contributor

rebased on main's chmod reporting refactor: errors go through report_failure, dropped CannotAccess (same text as CannotStat), and the unreadable-operand test now expects 'cannot read directory' like GNU

@abendrothj
abendrothj force-pushed the chmod-chown-operand-by-fd branch from 07613f2 to 26eaa7a Compare October 26, 2026 22:30
Copilot AI balanced review requested due to automatic review settings October 26, 2026 22:30

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.

@abendrothj
abendrothj force-pushed the chmod-chown-operand-by-fd branch from 26eaa7a to f031f8c Compare November 2, 2026 23:05
Copilot AI balanced review requested due to automatic review settings November 2, 2026 23:05

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.

@sylvestre

Copy link
Copy Markdown
Contributor

a bunch of jobs are failing

On Linux, a rename between the path lookup and the descent can no longer
slip "/" past --preserve-root under -H or -L.
A rename between the checks can no longer send the mode change or the
descent into "/", also under -L.
@abendrothj
abendrothj force-pushed the chmod-chown-operand-by-fd branch from f031f8c to 683dd8a Compare November 7, 2026 06:33
Copilot AI balanced review requested due to automatic review settings November 7, 2026 06:33

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.

@sylvestre
sylvestre merged commit 07b66ef into uutils:main Nov 8, 2026
231 of 232 checks passed
sylvestre added a commit to sylvestre/coreutils that referenced this pull request Nov 8, 2026
Follow-up to 07b66ef (uutils#14972): fall back to the path on any open
failure instead of an errno allowlist, and keep only the symlink-operand
and unopenable-operand tests.
sylvestre added a commit to sylvestre/coreutils that referenced this pull request Nov 8, 2026
Follow-up to 07b66ef (uutils#14972): fall back to the path only when
permissions keep the operand from opening, instead of an errno
allowlist, and drop the tests for -h, sandboxed operands and the
descriptor count.
sylvestre added a commit to sylvestre/coreutils that referenced this pull request Nov 8, 2026
Follow-up to 07b66ef (uutils#14972): fall back to the path only when
permissions keep the operand from opening, instead of an errno
allowlist.
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, chown: -R --preserve-root judges the operand by a separate path lookup

4 participants