Commit Graph

19291 Commits

Author SHA1 Message Date
Sylvestre Ledru 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 Ledru 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 Ledru 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
oech3 529467d8e5 reduce usage of nix::unistd::geteuid 2026-05-06 11:41:38 +02:00
oech3 80f5826a2d yes: add BENCHMARKING.md (#12097) 2026-05-06 10:59:21 +02:00
Sylvestre Ledru 20f7af8732 stat: warn once when QUOTING_STYLE env has an unknown value (#12136)
* stat: warn once when QUOTING_STYLE env has an unknown value

* Add spell-checker directive to test_stat.rs
2026-05-06 10:16:13 +02:00
oech3 aeaf810eb5 test_tail.rs: increase delay 2026-05-06 08:35:00 +02:00
oech3 7905732b9a yes: remove unnecessary cfg 2026-05-06 08:28:27 +02:00
renovate[bot] 0f45d9d219 chore(deps): update rust crate exacl to 0.13.0 2026-05-06 07:07:03 +02:00
Daniel Hofstetter 2e04477a78 nohup: refactor find_stdout & extract function (#12146)
try_open_nohup_file to eliminate duplicate code
2026-05-05 22:13:30 +02:00
Daniel Hofstetter 852af483f5 Cargo.toml: unpin notify (#11978) 2026-05-05 22:12:30 +02:00
Daniel Hofstetter 797b8d68ba Revert "fix(renovate): do not update pinned dependencies" (#11977)
This reverts commit 33b9156667.
2026-05-05 22:11:52 +02:00
Daniel Hofstetter 05759a8592 yes: move import to the other imports (#12153) 2026-05-05 22:11:22 +02:00
mattsu b195b1de88 chmod: fix TOCTOU race in recursive traversal (#11918)
* chmod: fix TOCTOU race in recursive traversal

Use fchmodat2 (Linux 6.6+) with AT_SYMLINK_NOFOLLOW to prevent an
attacker from replacing a directory entry with a symlink between the
stat and chmod calls. Falls back to fchmodat on older kernels.

- Restrict fchmodat2 (syscall 452) to asm-generic architectures only
  (x86_64, x86, arm, aarch64, riscv)
- Add SAFETY comment on unsafe syscall block per project convention
- Add O_PATH + /proc/self/fd fallback for musl on kernel < 6.6
- Cache ENOSYS result with AtomicBool to skip fchmodat2 on old kernels
- Remove unnecessary nix::Mode round-trip on the fchmodat2 path
- safe_chmod_file() takes explicit SymlinkBehavior parameter
- Always pass NoFollow for regular entries during recursion
- Document residual TOCTOU in symlink branch as intentional for -L
- Add test verifying NoFollow chmod doesn't modify symlink target
- Update check-safe-traversal.sh to recognize fchmodat2
2026-05-05 22:06:06 +02:00
oech3 fb93f53b3a tee: add benchmark (#12134) 2026-05-05 21:41:13 +02:00
Daniel Hofstetter adce17fa26 ls: use lines() instead of split('\n') in test 2026-05-05 15:50:30 +02:00
oech3 39364b6e23 factor: remove unsafe str::from_utf8_unchecked 2026-05-05 14:42:27 +02:00
Guillem L. Jara f7ba1f9b07 chore(ls): test for sorting stability 2026-05-05 11:22:45 +02:00
Guillem L. Jara 779cb058cd fix(ls): disambiguate size sorting appropiately 2026-05-05 11:22:45 +02:00
Guillem L. Jara 5a25c70c16 fix(ls): respect sorting when grouping directories 2026-05-05 11:22:45 +02:00
oech3 3e3daaa347 yes: remove cfg & move ownership of buffer to fn exec 2026-05-05 10:25:10 +02:00
xtqqczze 6b75bae3ce chore(deps): update rust crate crc-catalog to 2.5.0 2026-05-05 08:49:52 +02:00
Daniel Hofstetter c23dc6769e ls: hide "paths" argument 2026-05-04 18:01:03 +02:00
Guillem L. Jara bf89c8bf22 chore(cp): move raw libc calls to rustix 2026-05-04 17:46:32 +02:00
Guillem L. Jara b5ba95b030 chore(cp): add rustix as dep 2026-05-04 17:46:32 +02:00
Dorian Péron 379fbbb77e uucore: make the automatic flush at the end of binaries opt-outable
... To avoid duplicate error message when the util already does the job
2026-05-04 14:19:37 +02:00
Dorian Péron dac86df588 cksum: stop checksum computation from panicking over write error 2026-05-04 14:19:37 +02:00
xtqqczze 2b6ba09c4a chore(deps): update rust crate kqueue-sys to v1.1.0 2026-05-04 14:14:54 +02:00
oech3 45a48a1365 yes: avoid kernel side length validation (#12115) 2026-05-04 10:12:43 +02:00
Sylvestre Ledru 4a69cf0c5e tr: drop '[:...:]' wrapper from invalid character class error (#12122) 2026-05-04 09:54:56 +02:00
Sylvestre Ledru 0b6a2f26e3 uucore/safe_copy: use rustix Mode flags to avoid mode_t width mismatch (#12140)
`Mode::from_bits_truncate(DEST_INITIAL_MODE)` failed to build on macOS
because `mode_t` is `u16` there but `u32` on Linux. Compose the mode
from `Mode::RUSR | Mode::WUSR` so the call is portable by construction
and self-documents the intent (read+write owner = 0o600).
2026-05-04 09:41:55 +02:00
Sylvestre Ledru 163103355a head: strip os error suffix from stdout write error message (#12121) 2026-05-04 09:38:54 +02:00
Sylvestre Ledru b2c4e0c125 factor: emit GNU 9.11 'is not a valid positive integer' for stdin input (#12137)
* factor: emit GNU's 'X is not a valid positive integer' wording

GNU's factor.c routes both stdin and command-line input through the same
print_factors() and reports invalid input as
  factor: 'X' is not a valid positive integer
Match that wording exactly so the new GNU 9.11 'nul4' test passes and
the 'cont' test no longer needs the warning/invalid-digit hunk in
tests_factor_factor.pl.patch.

* Add 'cmdline' to spell-checker ignore list
2026-05-04 09:31:59 +02:00
Sylvestre Ledru fdafdcac96 uucore: add safe_copy module with TOCTOU-resistant copy primitives (#12130) 2026-05-03 11:35:24 +02:00
oech3 a1aa3b97eb nohup: remove unsafe stub 2026-05-03 11:24:12 +02:00
oech3 af09954d5a uucore: do not use Linux specific fn at tests (#12128) 2026-05-03 09:57:43 +02:00
Sylvestre Ledru 9de73ef9be tests: patch GNU numfmt 'neg-arg-not-option' to accept clap-style error (#12123) 2026-05-03 09:56:18 +02:00
karanabe 3057b7d9da rm: fix inaccessible GNU test adaptation (#12127) 2026-05-03 09:53:27 +02:00
karanabe 37ac49ee35 cp: fix fail-perm GNU test adaptation
GNU coreutils 9.11 changed fail-perm.sh to use the EACCES helper
in the expected diagnostics. Match the full diagnostic line so the
existing uutils message adaptation still applies.
2026-05-02 14:34:47 +02:00
oech3 4b5a2af7a9 nohup: reduce unsafe 2026-05-01 16:31:22 +02:00
Guillem L. Jara f774940451 fix(ls): place dot dirs on top in version sorting
Also fixes the fact that version sorting had incorrect edge cases due to wrong name passing.
2026-05-01 15:09:49 +02:00
Guillem L. Jara e4a2ab3955 fix(ls): properly skip . & .. on --recursive
Depending on the sorting it would not, so it could recurse back through `..`. Backported from another PR of mine.
2026-05-01 15:09:49 +02:00
pocopepe 375fc3cd48 numfmt: reject %f values too large to format exactly 2026-05-01 09:40:58 +02:00
renovate[bot] 99d362039b chore(deps): update rust crate ctor to 0.12.0 2026-05-01 07:36:13 +02:00
xtqqczze 843b2026a9 chore(deps): update rust crate string-interner to 0.20.0 (#12103) 2026-04-30 22:55:17 +02:00
oech3 4620c2f3b6 yes: use tee syscall as fast-path 2026-04-30 14:45:28 +02:00
Chris Denton a07879b8ab tty: support printing msys2 tty path 2026-04-30 11:12:22 +02:00
ksgk1 b3d8706a2c sort: fix inconsistent sort ordering under i18n-collator with equal sorting keys (#12013)
* sort: Fix inconsistent sort orderg under i18n-collator with equal sorting keys.

* Test cases for fix #11980

* Simplyfing fix for #11980

* Fix clippy lint and rename test files.

* Remove old test files

* Update tests/by-util/test_sort.rs

Co-authored-by: Daniel Hofstetter <daniel.hofstetter@42dh.com>

* Update tests/by-util/test_sort.rs

Co-authored-by: Daniel Hofstetter <daniel.hofstetter@42dh.com>

* Removing redundant test and swapping default order for sort to match sort's ordering.

* Comment for clarification.

---------

Co-authored-by: Daniel Hofstetter <daniel.hofstetter@42dh.com>
2026-04-30 10:33:48 +02:00
xtqqczze 3b2ff61d21 refactor(more): avoid Box<dyn Write> 2026-04-30 09:19:11 +02:00
xtqqczze 36595414b4 refactor: rename print methods to write for consistency 2026-04-30 09:09:57 +02:00