Re: UML: /proc/net/netstat silently mis-read by stdio line readers (fgets/getline) — raw reads of every size are byte-exact, all other /proc files are unaffected
Johan ter Mors
johan.termors at gmail.com
Wed Nov 25 09:13:26 PST 2026
Hi Anton,
Yes — reproduced on a build without multipath TCP.
Config: the same lean 7.3.6 build as in the report, with only CONFIG_MPTCP
(and MPTCP_IPV6) turned off; everything else identical (defconfig + HOSTFS/
BLK_DEV_INITRD/RD_GZIP/VETH/NET_NS/SYN_COOKIES/IPV6, DEBUG_INFO/BTF off,
the same two ptrace-only lab patches that do not touch procfs).
Guest-side proof that this is really a no-MPTCP kernel: the raw
/proc/net/netstat is 2748 bytes here vs 4197 on the MPTCP control build,
and the MPTcpExt records are absent from the raw dump. Control kernel:
same recipe with MPTCP on. Kernel hash:
no-MPTCP vmlinux sha256
ead23a1013670c33afedb70fa57129c6ed803f84393acf97e8c640b8ce4e3dd8
control the report build (vmlinux_736_e736_saved)
Method: per kernel, 160 fresh process instances across two boots — each
boot runs 40 execve'd instances of a static glibc instrument that does the
full pattern set against a raw-read reference of the same boot, plus 40
instances of the literal minimal reproducer from my report (same C code,
only the printf gained an instance id), plus 40 fork-cloned instances.
One variable between the two kernels: CONFIG_MPTCP.
pattern (diag instrument, 80 fresh execs per kernel, 2 boots)
no-MPTCP MPTCP control
fgets(buf, 16384) 80/80 corrupt 80/80 corrupt
fgets(buf, 4096) 80/80 exact 80/80 exact
getline() 80/80 exact 80/80 exact
fread(buf, 16384) 80/80 exact 80/80 exact
raw read(fd, 131072) 80/80 exact 80/80 exact
literal report reproducer, 40 instances per kernel:
no-MPTCP first-line=1025 total=1577 names=yes (40/40)
MPTCP control first-line=1025 total=3026 names=yes (40/40)
The corruption is identical in shape and size on both kernels: the first
fgets(16384) returns 1025 bytes of the 2196-byte TcpExt names line, the
remaining 1171 bytes of that line never appear in the stream, everything
after it is byte-exact (assembled total 1577 of 2748 without MPTCP, 3026
of 4197 with — the same absolute 1171 bytes lost). (In this shape the
surviving 1025 bytes still contain "SyncookiesSent", hence names=yes
despite the loss — flag semantics, not a contradiction with the report's
names=NO captures.) The only kernel-side difference is the file's own
MPTcpExt lines; the loss is a function of the reader, not of the content.
Two honest refinements, stated explicitly:
1. Within a boot, the behaviour is fully deterministic: all 160 instances
per kernel — across both boots, both instruments and the fork-cloned runs
— fail identically (same call, same lost chunk). The shapes we reported
in the original mail (first byte fused onto the next record; and the
full-length stream with stale-memory windows) are not what the same
reproducer shows on these fresh boots: today it is the 1025-byte
truncation shape above. So the *shape* of the mis-assembly tracks the
reader context / boot session, not the kernel configuration — both
kernels show exactly the same shape today.
2. The failure mode is a function of the reader's layout/state; we still
cannot split the mechanism further from user space, and the raw path
remains byte-exact everywhere (all other /proc files clean under all
patterns, as reported).
We have no non-UML kernel >= 6.12 here (no hypervisor), so the stock-kernel
control stays open — if it helps, the test binary is one small static
file; we can send it (plus the diag sources and serial logs) and you can
run it on any UML and any regular 6.12/7.x box in seconds.
Happy to test hypotheses or patches.
Kind regards,
Johan ter Mors
Op wo 25 nov 2026 om 17:30 schreef Anton Ivanov
<anton.ivanov at cambridgegreys.com>:
>
>
>
> On 25/11/2026 16:24, Johan ter Mors wrote:
> > [Quick note before the report: my earlier mail of today carried a
> > mangled Subject header — my mail client put the intended maintainer
> > Cc addresses into the subject line, so the report went out without a
> > usable subject and without the maintainer Cc. This thread is the same
> > report with a corrected envelope; please treat this copy as the
> > report. The mangled original is archived here, for the record:
> >
> > https://lore.kernel.org/linux-um/CAPM+r-+XCeM01ZXAj8Cti5qL1iaFrGrV+dYSumWD8585O3swew@mail.gmail.com/
> > ]
> >
> > Hi,
> >
> > While parsing TcpExt counters inside our lab guests (own lean UML
> > builds), we hit a reproducible case where stdio line readers (fgets
> > and getline) silently mis-read /proc/net/netstat — while every raw
> > read of the same file, on the same boot, is byte-exact. The same
> > statically linked binary behaves correctly on a non-UML host kernel.
> > We have not found an earlier report, so here is the full picture. We
> > could not pin the final mechanism; the data is attached so you can
> > judge it directly.
> >
> > Observed:
> >
> > - Which stdio call mis-assembles varies per process instance of the
> > same binary; within one instance it is deterministic per fopen.
> > Captured byte-exactly across instances on 7.3.6 and 6.12.117:
> > * fgets(buf, 16384) mis-assembles in most instances. Two shapes:
> > (i) the TcpExt *names* record is lost except its first byte,
> > which fuses onto the next record: the stream starts
> > "TTcpExt: 0 0 ...". 2002 of 4197 bytes on 7.3.6; 1718 of
> > 3862 on 6.12.117 — exactly the names-line length is
> > missing, and memcmp proves the output is the pure
> > subsequence "T" + rest-of-file;
> > (ii) full-length output (4197/4197) in which the names
> > string is absent and 16-byte windows exist that appear
> > NOWHERE in the file — the reader's own stale process
> > memory mixed into the assembled stream.
> > * In other instances fgets(buf, 4096) mis-assembled (names-line
> > length missing, plus foreign windows) while fgets(buf, 16384)
> > was byte-exact in the same process; in another instance
> > getline() returned full-length output with foreign windows.
> > So no fgets size is a safe workaround.
> > * Three fresh fopen() repeats of fgets(16384) in one instance
> > where the earlier calls were all byte-exact stayed correct —
> > but we have not seen a rule predicting which instance fails.
> > - Scope sweep, both UML kernels: 20 /proc files (net/netstat, snmp,
> > dev, sockstat, softnet_stat, tcp, udp, unix, mounts, cpuinfo,
> > version, self/limits, self/status, vmstat, meminfo, stat, uptime,
> > loadavg, ...) x 6 reader patterns (getline, fgets 512/4096/16384/
> > 65536, fread 16384): every file reads byte-exact with every
> > pattern EXCEPT /proc/net/netstat.
> > - fread(buf, 16384) and explicit setvbuf() configurations (4096/
> > 8192/16384-byte buffers, _IONBF, _IOLBF) have so far never
> > mis-assembled (limited number of instances observed), and raw
> > read() is byte-exact in every pattern we tried: single reads of
> > 18 sizes (2048 .. 131072) at offset 0, sequential pairs, and
> > lseek(K)+read() sweeps across the record boundaries — on the same
> > boots where stdio mis-assembles.
> > - The identical binary on a non-UML host kernel (5.10.134) is
> > correct for every pattern in every instance.
> > - Reproduces on 6.12.117, 7.3.5 and 7.3.6 UML (own lean builds;
> > defconfig + MPTCP/HOSTFS/BLK_DEV_INITRD/RD_GZIP/VETH/NET_NS, and
> > SYN_COOKIES/IPV6 on 7.3.6; DEBUG_INFO/BTF off; two small
> > ptrace-only lab patches that do not touch procfs).
> > - We do not have a non-UML kernel >= 6.12 in this lab (no
> > hypervisor), so a stock-kernel control is still open — running the
> > reproducer on any regular 6.12/7.x box would pin the scope nicely.
> >
> > Security note: we checked this explicitly before reporting. The
> > mis-assembled output contains only file bytes plus, in the mixing
> > shape, the reader's own stale process memory — never anything outside
> > the reading process (the kernel's raw read path is byte-exact on the
> > same boots, verified down to writes into stack buffers; memcmp
> > controls prove the file content was stable). No crash, no splat, no
> > privilege effect in any run; the reader is its own only victim. So we
> > do not consider this a security issue — it is a correctness bug for
> > common parsing patterns, and monitoring agents parsing
> > /proc/net/netstat with stdio on UML silently lose the TcpExt field
> > names.
> >
> > Minimal reproducer (static glibc, reads the file, prints three
> > numbers):
> >
> > #define _GNU_SOURCE
> > #include <stdio.h>
> > #include <string.h>
> > int main(void) {
> > FILE *f = fopen("/proc/net/netstat", "r");
> > static char line[16384], all[65536];
> > int tot = 0, l1 = -1;
> > while (fgets(line, sizeof line, f)) {
> > int n = (int)strlen(line);
> > if (l1 < 0) l1 = n;
> > if (tot + n < (int)sizeof all) { memcpy(all + tot, line, n); tot += n; }
> > }
> > printf("first-line=%d total=%d names=%s\n", l1, tot,
> > tot > 0 && memmem(all, tot, "SyncookiesSent", 14) ? "yes" : "NO");
> > return 0;
> > }
> >
> > On UML 7.3.6, failing instance A: first-line=1 total=2002 names=NO
> > (names lost, fused)
> > On UML 7.3.6, failing instance B: first-line=2196 total=4197 names=NO
> > (full length, stale-memory mixing)
> > Correct instance of the same binary on the same guest:
> > first-line=2196 total=4197 names=yes
> >
> > Because every raw read of the same file is correct on the same boots,
> > we suspect the fault sits in the interaction between the UML
> > syscall-return delivery and glibc stdio's line assembly rather than in
> > seq_file's data path; the per-instance randomness (same binary, same
> > pattern, byte-exact in one instance and mis-assembled in the next)
> > suggests the failure depends on the reader process's layout/state. We
> > cannot split that further from user space, and a ptrace-based tracer
> > on UML is not a reliable witness (the guest kernel already ptraces its
> > own user processes for syscall emulation, so a second ptrace layer
> > distorts what it observes).
> >
> > Kernel log clean on all runs; happy to provide the full diagnostic
> > sources, serial logs and the saved UML vmlinux files, and to test
> > patches or hypotheses.
> >
> > Thanks,
> > Johan ter Mors — independent researcher
> >
> >
>
> I have never observed this. Quick question - can you reproduce it with a kernel build without multipath TCP?
>
> --
> Anton R. Ivanov
> Cambridgegreys Limited. Registered in England. Company Number 10273661
More information about the linux-um
mailing list