split: writes into planted output files despite fs.protected_regular
============================================================================
ANT-2026-7JTISWCY [medium] CWE-283 info-leak
split: writes into planted output files despite fs.protected_regular
Location: src/uu/split/src/platform/unix.rs:178 in create_or_truncate_output_file()
Commit: 7bc1eb6d1d6fa2e1dc2c9d2277cf576c05f61e47
============================================================================
A local unprivileged user can capture the output of split run by root (or any other user) into a shared sticky directory such as /tmp. The attacker pre-creates the output names (…aa, …ab, …), and uutils split writes the chunks into those files even when fs.protected_regular/fs.protected_fifos are enabled. The attacker keeps ownership of the files, so they can always rewrite the chunks before the victim reassembles them. When the victim runs with a restrictive umask such as 077, the attacker can also read data that would otherwise have been private. GNU split 9.7 and uutils up to 0.9.0 are refused by the kernel on the same state.
The cause is the fallback in create_or_truncate_output_file() in src/uu/split/src/platform/unix.rs. After the O_WRONLY|O_CREAT|O_EXCL attempt fails with EEXIST, it reopens the name with plain O_WRONLY, with no O_CREAT. The kernel applies the protected_regular/protected_fifos owner check only to opens that carry O_CREAT, so it never runs. The only check afterwards is whether the file is the input, so the owner and type of the opened file are never examined. A planted FIFO is accepted too, because the EINVAL from ftruncate is deliberately ignored. No race is involved. The attacker only needs to know the output prefix and to create the files beforehand, and the issue only matters where those sysctls are on. They are 0 in the kernel's defaults but enabled by distributions such as Debian. The two-step open was introduced in 58040feb5c66 ("split: harden output open path against TOCTOU target swaps (#12565)"), first released in 0.10.0, as a side effect of the fix for #11401. The attached reproducer runs as root with umask 077 and fs.protected_regular=2. In it, nobody touches backup.part.aa, GNU split fails with Permission denied, and uutils split exits 0 while nobody reads root's token back from their own file.
Details
When an output name already exists, split reopens it with O_WRONLY and no O_CREAT. The kernel's
fs.protected_regular / fs.protected_fifos checks apply only to opens that carry O_CREAT, so a file that another
user planted under the output name in a sticky world-writable directory is accepted and receives the chunk.
nobody runs touch /tmp/backup.part.aa. Later root runs:
umask 077
split -b 1M /root/backup.tar /tmp/backup.part.
On a kernel with fs.protected_regular=2, uutils split exits 0 and the first chunk is in nobody's file (still
owned by nobody, who reads it with cat). GNU split 9.7 on the same state fails with
split: /tmp/backup.part.aa: Permission denied and leaves the planted file empty. The two traces differ in one flag:
GNU 9.7
openat(AT_FDCWD, "…/backup.part.aa", O_WRONLY|O_CREAT|O_EXCL, 0666) = -1 EEXIST (File exists)
openat(AT_FDCWD, "…/backup.part.aa", O_WRONLY|O_CREAT, 0666) = -1 EACCES (Permission denied)
uutils
openat(AT_FDCWD, "…/backup.part.aa", O_WRONLY|O_CREAT|O_EXCL|O_CLOEXEC, 0666) = -1 EEXIST (File exists)
openat(AT_FDCWD, "…/backup.part.aa", O_WRONLY|O_CLOEXEC) = 4
ftruncate(4, 0) = 0
The second open is the fallback in create_or_truncate_output_file, src/uu/split/src/platform/unix.rs:170:
fn create_or_truncate_output_file(input: &OsStr, filename: &OsStr) -> Result<std::fs::File> {
match std::fs::OpenOptions::new().write(true).create_new(true).open(Path::new(filename)) {
Ok(file) => Ok(file),
Err(e) if e.kind() == ErrorKind::AlreadyExists => {
let file = std::fs::OpenOptions::new()
.write(true) // :179 O_WRONLY only
.open(Path::new(filename))
.map_err(|e| open_file_error(filename, e))?;
if input_and_output_refer_to_same_file(input, &file) { … }
match file.set_len(0) {
// allow writing to symlink to nonseekable
Err(e) if e.kind() != ErrorKind::InvalidInput => Err(open_file_error(filename, e)),
_ => Ok(file),
}
}
fs.protected_regular and fs.protected_fifos make an open in a sticky directory fail with EACCES when the
existing regular file or FIFO belongs to neither the opener nor the directory owner. The kernel runs that check for
O_CREAT opens only: opening the planted file as root with O_WRONLY|O_CREAT returns EACCES, with O_WRONLY alone
it succeeds. In split, the first open has O_CREAT but stops at EEXIST because of O_EXCL; the fallback has
dropped O_CREAT, so the check never runs. After that open the only test on the descriptor is "is it the input"
(input_and_output_refer_to_same_file, :183); the owner and type of the opened file are not examined.
Every mode that writes files opens each new output through this function: ByteChunkWriter::new and
ByteChunkWriter::copy (src/uu/split/src/split.rs:564, :643), LineChunkWriter::start_new_chunk (:741),
OutFiles::init and OutFiles::instantiate_writer (:838, :874) and line_bytes (:1335) all call
Settings::instantiate_current_writer (:379), which calls platform::instantiate_current_writer
(unix.rs:131); for a file not opened before (is_new) that is create_or_truncate_output_file (unix.rs:140).
A planted FIFO behaves the same way under fs.protected_fifos=1: with mkfifo /tmp/backup.part.aa and the
attacker's cat waiting on it, GNU split fails with Permission denied, uutils split exits 0 and the reader
receives the chunk. ftruncate on the FIFO returns EINVAL, which unix.rs:191 ignores on purpose.
The two-step open comes from 58040feb5c66 ("split: harden output open path against TOCTOU target swaps (#12565)",
2026-06-05), first released in 0.10.0. Before that commit the output was opened once with
create(true).truncate(true), which carries O_CREAT, and uutils split up to 0.9.0 is refused like GNU.
Impact
A local unprivileged user who knows the output prefix that root (or any other user) passes to split for a
destination in /tmp, /var/tmp, /dev/shm or another sticky world-writable directory creates the output names
(…aa, …ab, …) beforehand. No race is involved. The planted files stay theirs after split has written the
chunks into them, and split reports success. At any umask the attacker keeps write access to the chunks and can
rewrite them before the victim reassembles them. When the victim runs with a restrictive umask such as 077 (as the
reproducer does), the attacker can also read chunks that would otherwise have been private; with the usual umask 022
the chunks in /tmp are world-readable in any case, so there the gain is the ability to modify them. A non-root
victim is affected the same way when the planted file is mode 0666.
The precondition is a predictable prefix in a shared sticky directory, which is the mistake fs.protected_regular
and fs.protected_fifos were added to contain. Both are off (0) in the kernel's own defaults; distributions such as
Debian turn them on, and the Debian host used for verification runs with fs.protected_regular=2 and
fs.protected_fifos=1; there GNU split refuses the planted file and uutils split does not. In a directory that
is not sticky the kernel check does not apply, GNU split writes into the planted file
as well, and there is no difference; the same follows for a kernel booted with both sysctls at 0.
This is a side effect of the hardening for issue #11401 (named as CVE-2026-35374 in the comment at
util/check-safe-traversal.sh:283, whose checks run to line 319), not a duplicate of it: replacing the path-based
O_TRUNC open with O_EXCL plus a fallback removed O_CREAT from the open that meets an existing file.
Reproducing
repro is a single Python script (standard library only) with no companion files. It must run as root. It uses the prebuilt /src/target/debug/coreutils split and GNU split 9.7 from /usr/bin, and it plays the attacker as uid nobody (group nogroup, with no supplementary groups). The attacker's whole part is one touch run as nobody. That is too small for its own file, so it stays in repro under the # attack heading.
Steps:
- Kernel setting. The script prints
fs.protected_regular. If the kernel has it at 0, the script sets it to 2 (the value Debian sets; the kernel's own default is 0) for the run and puts 0 back afterwards. Nothing else on the system is changed. - Set up. The script sets umask 077, so root's chunks should be private. It then creates a temporary directory holding root's
backup.tar, which contains a random 32-hex-digit token, and a root-owned mode-1777 subdirectorytmp/that stands in for/tmp. Root's command in every step issplit -b 1M backup.tar tmp/backup.part., withLC_ALL=C. - Control, nothing planted. uutils
splitcreatesbackup.part.aaas uid 0 with mode 600, andcatrun asnobodyis denied. The chunk is then removed. - Attack.
nobodyrunstouch tmp/backup.part.aa. - Control, GNU
split. GNUsplitwith the same arguments is refused by the kernel: it exits 1 withPermission denied, and the planted file stays at 0 bytes. - Trigger, uutils
split. uutilssplitwith the same arguments exits 0. The chunk is still owned by uid 65534, andcatrun asnobodyreturns root's token.
Expected output (paths and the token vary from run to run):
fs.protected_regular = 2
CONTROL nothing planted, uutils split: chunk uid 0 mode 600; nobody's cat: 'cat: …/tmp/backup.part.aa: Permission denied'
CONTROL planted file, GNU split: exit 1, 'split: …/tmp/backup.part.aa: Permission denied', planted file holds 0 bytes
OBSERVED planted file, uutils split: exit 0, '', chunk uid 65534
OBSERVED nobody's cat returns '<token>'; root's backup.tar holds '<token>'
BUG
The last line is BUG only if both of these hold:
- GNU
splitwas refused. This shows the kernel protection is in effect for this directory and this file. - uutils
splitexited 0, and the bytesnobodyread from their own file equal the token in root's input.
Otherwise the last line is OK. The script deletes its temporary directory at the end.
Suggested fix
The attached patch keeps O_CREAT on the fallback open in create_or_truncate_output_file
(src/uu/split/src/platform/unix.rs:178), which gives it the flags GNU uses for its second attempt; the explicit
.truncate(false) keeps clippy's suspicious_open_options quiet, and a comment above the open says why O_CREAT
must stay. The O_EXCL first attempt, the descriptor-based
same-file check and the ftruncate are unchanged, and there is still no path-based O_TRUNC. This is the only place
split opens an output for the first time; the append reopen of a file split already created does not need
O_CREAT.
--- a/src/uu/split/src/platform/unix.rs
+++ b/src/uu/split/src/platform/unix.rs
@@ -177,5 +177,7 @@
Err(e) if e.kind() == ErrorKind::AlreadyExists => {
let file = std::fs::OpenOptions::new()
.write(true)
+ .create(true)
+ .truncate(false)
.open(Path::new(filename))
.map_err(|e| open_file_error(filename, e))?;
The patch also adds a step to the split block of util/check-safe-traversal.sh that re-runs split over outputs
that already exist and fails if any reopen lacks O_CREAT, and an integration test,
test_existing_output_is_reopened_with_create in tests/by-util/test_split.rs, since the two-user sticky-directory
scenario cannot run in the test harness.
With the patch, the planted regular file and the planted FIFO are both refused with Permission denied (exit 1), as
with GNU split; an existing output owned by the caller is still truncated and overwritten, and an output symlink that
points at the input is still rejected with "would overwrite input". On a rebuilt clean checkout the reproducer prints
OK.
One visible side effect: an output name that is a dangling symlink is now created through the link, as GNU split
and uutils before 0.10.0 do, instead of failing with No such file or directory. The new integration test pins that
behaviour.
Running the reproducer
ANT-2026-7JTISWCY/repro, next to this file. It was written by an automated agent and our check ran it as root in a privileged container: run it INSIDE A THROWAWAY VM, with the image oss-scan-7bc1eb6d1d6f built by bash build/build-image.sh, from the archive's top directory:
docker run --rm --network=none --privileged -u 0 -w /src -v "$PWD/ANT-2026-7JTISWCY/repro:/tmp/repro:ro" oss-scan-7bc1eb6d1d6f /tmp/repro
It prints its evidence; the last line is BUG if the issue triggered, OK otherwise.
Hi! I'd like to work on this. Could you assign it to me?
I'll look at create_or_truncate_output_file() and match GNU's behaviour so split doesn't write into planted files under fs.protected_regular, with a test.
I'll keep the PR small and focused on this issue.