Commit Graph
337 Commits
Author SHA1 Message Date
xtqqczzeandDaniel Hofstetter 24e3d0d39e fix(selinux): add missing os checks 2026-05-21 09:13:41 +02:00
xtqqczzeandDaniel Hofstetter 7449705a98 fix(tests): refine feature checks for SELinux 2026-05-19 11:19:55 +02:00
oech3andGitHub eca185b22b replace nix getgroups by rustix (#12269) 2026-05-13 07:41:32 +02:00
Sylvestre LedruandDaniel Hofstetter f057cc6a01 tests: replace .no_stdout().no_stderr() chains with .no_output()
Bulk rename of the antipattern across 19 test files (136 occurrences).
.no_output() is the established shorthand in the uutests framework
for asserting both empty stdout and empty stderr.
2026-05-12 09:31:31 +02:00
Sylvestre LedruandDorian Péron bd170a5d4b cp: strip setuid/setgid when chown fails during -p (#9750)
When `cp -p` cannot chown the destination to the source's owner
(e.g. a non-root user copying a root-owned setuid file), GNU cp
strips the setuid and setgid bits from the applied mode so the
destination does not give the copying user elevated privileges via
the copy. uutils was unconditionally applying the source mode,
producing user-owned files with a live setuid bit.

Track `ownership_preserved` alongside the existing chown retry
logic and, in the subsequent `handle_preserve(mode, ...)` block,
mask off `0o6000` from the source's mode when ownership could not
be preserved. The sticky bit (01000) is kept, matching GNU.
2026-05-06 11:47:38 +02:00
Sylvestre LedruandDorian Péron 7ba1bf857c cp: don't preserve xattrs with -p by default (#9704)
GNU `cp -p` preserves mode, ownership, and timestamps. xattrs are
NOT preserved unless the user asks for them via `--preserve=xattr`
or `-a`. uutils's `Attributes::DEFAULT` had xattr set to
`Preserve::Yes { required: true }`, which (1) diverges from GNU and
breaks scripts that expect the stock behavior, (2) leaks security
xattrs like file capabilities and SELinux labels into copies when
run as root, and (3) fails hard on destinations that don't support
xattrs.

Remove the xattr override in `Attributes::DEFAULT` so it inherits
`Preserve::No` from `Attributes::NONE`. `Attributes::ALL` (used by
`-a` and `--preserve=all`) still sets xattr to Yes, and
`--preserve=xattr` still works as before.
2026-05-06 11:47:38 +02:00
Sylvestre LedruandDorian Péron ef5d752282 cp: open source and dest with O_NOFOLLOW in no-dereference mode (#10017)
In `-P` / no-dereference mode, cp now opens the source file with
`O_NOFOLLOW`, matching GNU cp. This closes a TOCTOU window where an
attacker who can swap the source path between cp's `lstat` check and
the subsequent open could redirect the read through a symlink to a
sensitive file (e.g. /etc/shadow). With `O_NOFOLLOW` the open fails
with `ELOOP` instead.

The same flag is propagated to `safe_copy::create_dest_restrictive`,
so the destination open also refuses to follow a symlink in
no-dereference mode. Without that, an attacker who plants the dest
path as a symlink between the caller's check and the open could
redirect the truncate (and the subsequent write) to any file the
caller has permission to write — the symmetric attack to the source
side. With `nofollow=true` the dest open returns `ELOOP` and the
victim file is left untouched.

`copy_on_write` gains a `nofollow` parameter threaded from
`copy_helper`, set to `!options.dereference(source_in_command_line)`.
In deref mode the flag is false and behavior is unchanged — cp still
follows symlinks, matching GNU.

Extends `util/check-safe-traversal.sh` with a cp -P strace check so
the invariant is locked in: future changes that drop `O_NOFOLLOW`
here will fail the smoke test.
2026-05-06 11:47:38 +02:00
Sylvestre LedruandDorian Péron 681030bca3 cp: create destination with restrictive 0o600 initial mode (#10011)
cp previously created the destination with mode 0o666 masked by umask
(typically 0o644), then later applied the final permissions via
set_permissions. In a shared directory like /tmp this opened an
observable window where another user could open the destination with
the intermediate broad mode before cp narrowed it, leaking file
contents that were intended to stay private.

Create dest with 0o600 initially in every non-symlink code path —
clone, sparse_copy, sparse_copy_without_hole, fs_copy, the stream
path, and the non-Linux fs::copy fallback. The existing
set_permissions call in copy_file applies the real final mode after
the content is written, so user-visible end state is unchanged; only
the intermediate mode is tightened. Matches GNU cp.

Extend `util/check-safe-traversal.sh` with a cp strace check that
asserts the destination openat carries mode 0600 so a future change
that reintroduces 0666 fails the smoke test.
2026-05-06 11:47:38 +02:00
Babur AyanlarandDorian Péron 8bff321cfb fix(cp): always create dest dirs with owner write bit before fixing permissions 2026-03-17 18:33:17 +01:00
Victor ProkhorovandGitHub e6a3bb596f cp: handle special files (#11163) 2026-03-05 00:01:52 +01:00
Avi WeinstockandGitHub 2a81c11344 Merge pull request #11148 from Zellic/cp-fix-nonutf8-panic
cp: Fix panic when recursively copying a directory with a non-UTF8 name
2026-02-28 09:26:02 +01:00
Christopher DrydenandSylvestre Ledru 42b734bc42 Fix failing SELinux cp tests 2026-02-15 22:07:40 +01:00
Christopher DrydenandSylvestre Ledru 102c94fa78 cp: fix SELinux context handling for cp-a-selinux GNU test 2026-02-15 22:07:40 +01:00
31c5102bee cp: fix recursive copy of readonly directories (#10529)
Co-authored-by: Sylvestre Ledru <sylvestre@debian.org>
2026-02-07 14:28:24 +01:00
Yuri AstrakhanandGitHub 05204864d6 refactor: inline format! args in a few places (#10730)
* refactor: inline format! args in a few places

* in one spot remove redundant mem alloc

* run clippy fix with mixed
2026-02-07 10:05:44 +01:00
✿ Fleur de BlueandGitHub 2a2cafdbd4 Re-enable unused_qualifications lint (#10571) 2026-02-03 21:55:21 +01:00
525d1f88ec cp/mv: suppress xattr ENOTSUP errors for optional preservation (#10083)
* cp/mv: suppress xattr ENOTSUP errors for optional preservation

* mv: copy xattrs for symlink fallback and format tests

* cp: fix test expectation for GNU-compatible error format

* fix test portability for Android and xattr detection

---------

Co-authored-by: Sylvestre Ledru <sylvestre@debian.org>
2026-01-18 22:42:14 +01:00
Max AmbaumandGitHub 2a044db3a2 cp: Fixed POSIXLY_CORRECT test to actually check if file exists and its contents (#10247)
cp: Added check of file contents in POSIXLY_CORRECT test

cp: Fixed windows test by including path

cp: Updated test
2026-01-17 04:41:29 -08:00
oech3andoech3 25c088154a cp: Avoid other error at cp stream /dev/full 2026-01-09 20:09:19 +09:00
Phan Trung ThanhandGitHub 7274e7f6a1 cp: set status code when encountering circular symbolic links (#9757)
* cp: set exit code when encountering circular symbolic links error when copying directory

* cp: add test to ensure that cp sets the status code when encountering circular symbolic links during directory copy

* cp: check that the output of circular symbolic link test has the correct message

* cp: update check for stderr message

* cp: update circular symbolic link test to account for directory format in windows

* cp: use std::path::MAIN_SEPARATOR_STR for test
2026-01-06 10:51:26 +01:00
max-amb 83a52bf561 cp: Added test for permissions copying to an existing file 2026-01-04 13:18:48 +00:00
Dylan SkellyandGitHub 9cf774bed8 cp: symlink flags fixing conflicting flag logic to use last flag (#9960)
* Adding overrides_with_all for symlink flags for ordering

* Adding regression tests for symlink flag ordering
2026-01-01 15:04:47 +01:00
RustyJackandGitHub 939ab037a2 uucore: use --suffix to enable backup mode (#9741) 2025-12-21 10:17:35 +01:00
Cả thế giới là RustandGitHub 415d01cc75 cp: add readonly file regression tests (#9045)
* feat: add comprehensive readonly file regression tests for cp

- Add 10 new test functions covering readonly destination behavior
- Tests cover basic readonly copying, flag combinations, and edge cases
- Include macOS-specific clonefile behavior tests
- Ensure readonly file protection from PR #5261 cannot regress
- Tests provide evidence for closing issue #5349

* perf: optimize readonly regression tests with batched I/O operations

- Reduce file I/O overhead by batching file operations
- Consolidate setup operations to minimize system calls
- Improve test execution time from 0.44s to 0.27s (38% improvement)
- Maintain comprehensive test coverage for readonly file behavior

* fix: remove duplicate tests and trivial comments per PR feedback

- Remove test_cp_readonly_dest_regression (duplicate of test_cp_dest_no_permissions)
- Remove test_cp_readonly_dest_with_force (duplicate of test_cp_arg_force)
- Remove test_cp_readonly_dest_with_remove_destination (duplicate of test_cp_arg_remove_destination)
- Remove test_cp_macos_clonefile_readonly (duplicate of test_cp_existing_target)
- Remove test_cp_normal_copy_still_works (duplicate of test_cp_existing_target)
- Remove trivial performance comments from readonly tests
- Keep existing proven tests per maintainer preferences
- Keep unique readonly tests that provide additional coverage
2025-12-10 14:54:17 +01:00
Chris DrydenandGitHub 1ffad8228a cp: Enabling cp force flag to run on windows (#9624)
* Enabling cp force flag to run on windows

* Windows requires clearing the readonly permissions before deleting
2025-12-10 09:22:04 +01:00