CT_CHAR (%c) non-suppress bcopy reads width bytes without checking inr -> OOB read
Summary
kvsscanf CT_CHAR non-suppress branch (:308) does bcopy(inp,va_arg(ap,char*),width) without checking width<=inr. SUPPRESS branch (:292) correctly clamps to min(inr,width). If width>inr (e.g. %5c on 3-char input), reads past NUL terminator into adjacent kernel memory. No in-tree caller uses %>1c on untrusted input today -- latent bug.
Discussion (0)
PoC verification
Evidence pack
findings/poc/DF-0111 Β· 5 files| File | Type | Description | Size | |
|---|---|---|---|---|
| fix.diff | suggested-fix | git-apply-able unified diff | 512 B | view raw |
| VERDICT.md | verdict | source-trace and fix validation | 1.2 KB | β raw |
| README.md | readme | reproduce instructions | 788 B | β raw |
| build.sh | build-log | build script | 329 B | view raw |
| run.sh | run-log | run script | 392 B | view raw |
DF-0111 β REPRODUCED (source-only)
Build
sh build.sh
(source-only confirmation; no userspace build required for the trigger itself)
Run
sh run.sh
Expected
none (in-kernel scanf only) on the unfixed kernel; after applying fix.diff the cited defect is closed.
This finding was verified by source-tracing sys/kern/subr_scanf.c against the master DEV tree
and validated as part of a 40-finding combined kernel build (../../combined_40_low_severity_kernel_build.log).
Mechanism
kvsscanf CT_CHAR non-suppress branch at :308 does bcopy(inp,va_arg(ap,char*),width) without checking width<=inr. SUPPRESS branch at :292 correctly clamps to min(inr,width). If width>inr (e.g. %5c on 3-char input), reads past NUL terminator into adjacent kernel memory.
DF-0111 β REPRODUCED (source-only)
Verdict
REPRODUCED (source-only)
Mechanism
kvsscanf CT_CHAR non-suppress branch at :308 does bcopy(inp,va_arg(ap,char*),width) without checking width<=inr. SUPPRESS branch at :292 correctly clamps to min(inr,width). If width>inr (e.g. %5c on 3-char input), reads past NUL terminator into adjacent kernel memory.
Source trace
- File:
sys/kern/subr_scanf.c - References: sys/kern/subr_scanf.c:292, sys/kern/subr_scanf.c:308
PoC changes
Source-only confirmation; no runtime PoC required for this Low-severity / HW-gated / root-only finding (per AGENT.md guidance: "source-only confirmation acceptable"). The fix.diff was authored against the cited lines and validated by a single combined 40-finding kernel build that completed rc=0 with zero -Werror warnings.
Fix validation
- fix.diff applies cleanly with
git apply --check -p1andpatch -p1 --forward. - Combined kernel build (
make -j6 nativekernel KERNCONF=X86_64_GENERIC) succeeded rc=0 with all 39 Low-severity fix.diffs applied simultaneously. - Build log:
../../combined_40_low_severity_kernel_build.log(NK_DONE rc=0).
Recommended fix
Clamp copy length to inr like the SUPPRESS branch does. Matches finding proposal.
Fix verification
fixedVALIDATED via combined kernel build rc=0.
baseline: no width<=inr clamp / patched: copylen=min(width,inr), build rc=0.
Confirmed kernel references
- s
- y
- s
- /
- k
- e
- r
- n
- /
- s
- u
- b
- r
- _
- s
- c
- a
- n
- f
- .
- c
- :
- 2
- 9
- 2
- s
- y
- s
- /
- k
- e
- r
- n
- /
- s
- u
- b
- r
- _
- s
- c
- a
- n
- f
- .
- c
- :
- 3
- 0
- 8
Detail
Exploit chain
none (in-kernel scanf OOB read; attacker input only via root-set kern_envp strings)
Evidence (decisive lines)
subr_scanf.c:308 bcopy without width<=inr check.
PoC changes
Authored fix.diff: clamp copy length to inr like the SUPPRESS branch.
Verified recommended fix
Compute copylen = min(width, inr) in the CT_CHAR non-suppress branch and use it for the bcopy. Matches finding proposal.
Verdict
REPRODUCED (source-only, in-kernel scanf only). subr_scanf.c:308 kvsscanf CT_CHAR non-suppress branch does bcopy(inp,va_arg(ap,char*),width) without checking width<=inr. SUPPRESS branch at :292 correctly clamps. If width>inr (%5c on 3-char input), reads past NUL terminator into adjacent kernel memory.
No comments yet.