Skip to content

cp: set the destination's attributes without following a symlink - #16460

Open
abendrothj wants to merge 1 commit into
uutils:mainfrom
abendrothj:cp-finalize-chmod-nofollow
Open

abendrothj wants to merge 1 commit into
uutils:mainfrom
abendrothj:cp-finalize-chmod-nofollow

Conversation

@abendrothj

@abendrothj abendrothj commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Supersedes #13630.

After the copy, cp sets the destination's mode, times and xattrs by name. If the destination is replaced with a symlink after cp has checked it, those changes go to the link's target.

Those steps now refuse to follow a symlink there: the final chmod, the -p mode, the read-only toggle around the xattr copy, the xattr open, the timestamps, and the SELinux fallback that empties the destination (unless cp was writing through a destination symlink from the start). Where the libc can't chmod without following, or Linux has neither fchmodat2 nor /proc, cp keeps the following chmod.

The /proc fallback that chmod -R shares (kernels without fchmodat2) now refuses a symlink, like fchmodat2. On those kernels each chmod costs about four more syscalls. util/check-safe-traversal.sh checks cp with strace, and CI now builds cp for it.

@codspeed

codspeed Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will regress 2 benchmarks

Warning

uutils has exceeded the Hobby plan limit of 5 active contributors. Upgrade your plan or apply to the open source program by December 8, 2026 to keep using CodSpeed.

2 warnings, 1 note

⚠️ 122 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

⚠️ 5 benchmarks with a significant change ran on different hardware

Their base and head results were measured on machines with a different CPU, core count or memory, so the changes might not come from the code. Run base and head on the same runner type.

Learn more about Macro Runners

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

⚡ 3 improved benchmarks
❌ 2 regressed benchmarks
✅ 410 untouched benchmarks
⏩ 70 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
❌ Memory timeout_enforced 88.8 KB 179.6 KB -50.56%
❌ CPU Simulation df_deep_directory 881.9 µs 929.6 µs -5.14%
⚡ Memory socket_addrs_direct[100000] 68 KB 8.6 KB ×7.9
⚡ Memory hostname_ip_lookup[100000] 160.3 KB 100.9 KB +58.88%
⚡ Memory cp_recursive_deep_tree[(120, 4)] 789 KB 671 KB +17.59%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing abendrothj:cp-finalize-chmod-nofollow (b9284c9) with main (719655e)2

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. ↩

  2. No successful run was found on main (e47e3e6) during the generation of this report, so 719655e was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

@abendrothj
abendrothj marked this pull request as ready for review November 19, 2026 07:16
Copilot AI balanced review requested due to automatic review settings November 19, 2026 07:16

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.

Comment thread src/uu/cp/src/cp.rs Resolved
Comment thread src/uu/cp/src/cp.rs Resolved
@sylvestre
sylvestre force-pushed the cp-finalize-chmod-nofollow branch from 2e55840 to 2dd0389 Compare November 22, 2026 22:05
Copilot AI balanced review requested due to automatic review settings November 22, 2026 22: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.

@abendrothj
abendrothj force-pushed the cp-finalize-chmod-nofollow branch from 2dd0389 to 07d2e43 Compare November 23, 2026 09:26
Copilot AI balanced review requested due to automatic review settings November 23, 2026 09:26

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.

Where the libc can't chmod without following, or Linux has neither fchmodat2 nor /proc, cp keeps the following chmod.
The /proc fallback chmod -R shares now refuses a symlink.

Co-authored-by: Sylvestre Ledru <sylvestre@debian.org>
@sylvestre
sylvestre force-pushed the cp-finalize-chmod-nofollow branch from 07d2e43 to b9284c9 Compare November 24, 2026 22:52
Copilot AI balanced review requested due to automatic review settings November 24, 2026 22:52

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.

@github-actions

Copy link
Copy Markdown

GNU testsuite comparison:

Congrats! The gnu test tests/tail/debug is no longer failing!

This branch has not been deployed

No deployments
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.

3 participants