Missing e_shentsize validation causes heap OOB read on shdr[] array
All 7 are root-only (kldload needs SYSCAP_NOKLD), defense-in-depth (root
already owns the kernel via a valid .ko's SYSINIT), and several are analogues
of the link_elf_obj.c findings DF-0040/41/42 in this sibling file.
DF-0057 β Missing e_shentsize validation β heap OOB read on shdr[]
| Field | Value |
|---|---|
| Severity | Low |
kmalloc(e_shnum*e_shentsize) (:593) but no e_shentsize == sizeof(Elf_Shdr)
check; shdr[i] indexed with 64-byte stride. If e_shentsize < 64 the allocation
is too small β shdr[i] OOB read. Sibling link_elf_obj.c:499 validates; this
file omits. Fix: reject e_shentsize != sizeof(Elf_Shdr).
DF-0058 β Unbounded sh_link β symstrindex OOB read (DF-0040 analogue, worse)
| Field | Value |
|---|---|
| Severity | Low |
symstrindex = shdr[i].sh_link (Elf64_Word) set with no bounds check vs
e_shnum (DF-0040 in link_elf_obj.c had an off-by-one >; this file has zero
check). shdr[symstrindex].sh_size/sh_offset deref at :612/:620 is OOB if
symstrindex >= e_shnum. Fix: if (shdr[i].sh_link >= hdr->e_shnum) continue;.
DF-0059 β Uninitialized segs[1]/segs[0] dereference when fewer than 2 PT_LOAD
| Field | Value |
|---|---|
| Severity | Low |
segs[2] uninitialized stack (:399); :531 checks phdyn != NULL but not
nsegs == 2; :541-542 unconditionally derefs segs[0]/segs[1]. Crafted ELF
with PT_DYNAMIC but 0/1 PT_LOAD β wild deref β panic. Fix: require
nsegs == 2 before the derefs.
DF-0060 β DT_HASH d_ptr dereferenced without bounds β wild kernel read
| Field | Value |
|---|---|
| Severity | Low |
parse_dynamic DT_HASH: hashtab = ef->address + dp->d_un.d_ptr with no
d_ptr < lf->size check; immediate hashtab[0]/hashtab[1] deref β wild read
from ef->address + arbitrary_offset. Same gap in DT_STRTAB/DT_SYMTAB/DT_REL/
DT_RELA/DT_JMPREL/DT_PLTGOT. Fix: if (dp->d_un.d_ptr >= lf->size) return ENOEXEC;
in each case.
DF-0061 β Relocation r_offset never bounds-checked (DF-0042 analogue, wild write)
| Field | Value |
|---|---|
| Severity | Low |
relocate_file dispatches each rel/rela to elf_reloc with no
r_offset < lf->size check; arch helper (elf_machdep.c:90) writes
*(relocbase + r_offset). Crafted r_offset yields wild write of symbol-resolved
value past the module buffer. Same gap in link_elf_reloc_local (:1024-1051).
Fix: skip r_offset >= lf->size entries.
DF-0062 β Unbounded st_name into strtab (DF-0041 analogue, OOB read via strcmp)
| Field | Value |
|---|---|
| Severity | Low |
Every strtab name site does ef->strtab + symp->st_name without checking
st_name < ef->strsz; strtab has no guaranteed NUL; crafted st_name >= strsz
β strcmp walks off the allocation (panic / heap info-leak). Fix: guard
st_name < strsz/ddbstrcnt at each site; NUL-terminate the strtab allocation.
DF-0063 β Hash-chain cycle in link_elf_lookup_symbol β infinite-loop DoS
| Field | Value |
|---|---|
| Severity | Low |
while (symnum != STN_UNDEF) follows ef->chains[symnum] (attacker-controlled
module buffer); the bounds check at :813 only rejects symnum >= nchains, no
cycle detection; crafted 2-cycle (chains[1]=2, chains[2]=1) β infinite loop
pinning a CPU during relocate_file. Fix: cap iterations at nchains
(a valid chain visits each symbol at most once).
Common notes
All 7 are root-only defense-in-depth. Each has a concrete, one-line or few-line
fix. The fixes for DF-0058/0061/0062 mirror the fixes already proposed for
DF-0040/0042/0041 in the sibling link_elf_obj.c.
Discussion (0)
PoC verification
Evidence pack
findings/poc/DF-0057 Β· 5 files| File | Type | Description | Size | |
|---|---|---|---|---|
| fix.diff | suggested-fix | git-apply-able unified diff | 498 B | view raw |
| VERDICT.md | verdict | source-trace and fix validation | 1.2 KB | β raw |
| README.md | readme | reproduce instructions | 735 B | β raw |
| build.sh | build-log | build script | 329 B | view raw |
| run.sh | run-log | run script | 392 B | view raw |
DF-0057 β REPRODUCED (source-only, root-only kldload)
Build
sh build.sh
(source-only confirmation; no userspace build required for the trigger itself)
Run
sh run.sh
Expected
none (root-only) on the unfixed kernel; after applying fix.diff the cited defect is closed.
This finding was verified by source-tracing sys/kern/link_elf.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
link_elf_load_file at :590 does kmalloc(e_shnum*e_shentsize) but no e_shentsize==sizeof(Elf_Shdr) check; shdr[i] indexed with 64-byte stride. If e_shentsize<64 the allocation is too small β shdr[i] OOB read.
DF-0057 β REPRODUCED (source-only, root-only kldload)
Verdict
REPRODUCED (source-only, root-only kldload)
Mechanism
link_elf_load_file at :590 does kmalloc(e_shnum*e_shentsize) but no e_shentsize==sizeof(Elf_Shdr) check; shdr[i] indexed with 64-byte stride. If e_shentsize<64 the allocation is too small β shdr[i] OOB read.
Source trace
- File:
sys/kern/link_elf.c - References: sys/kern/link_elf.c:590, sys/kern/link_elf.c:593
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
Reject e_shentsize != sizeof(Elf_Shdr). Matches finding proposal.
Fix verification
fixedVALIDATED via combined kernel build rc=0.
baseline: no e_shentsize check / patched: e_shentsize != sizeof(Elf_Shdr) reject, build rc=0.
Confirmed kernel references
- s
- y
- s
- /
- k
- e
- r
- n
- /
- l
- i
- n
- k
- _
- e
- l
- f
- .
- c
- :
- 5
- 9
- 0
- s
- y
- s
- /
- k
- e
- r
- n
- /
- l
- i
- n
- k
- _
- e
- l
- f
- .
- c
- :
- 5
- 9
- 3
Detail
Exploit chain
none (root-only kldload)
Evidence (decisive lines)
link_elf.c:591 checks nbytes==0 but not e_shentsize validity.
PoC changes
Authored fix.diff: reject e_shentsize != sizeof(Elf_Shdr).
Verified recommended fix
Reject e_shentsize != sizeof(Elf_Shdr) at link_elf.c:591. Matches finding proposal.
Verdict
REPRODUCED (source-only, root-only kldload). link_elf.c:590 kmalloc(e_shnum*e_shentsize) but no e_shentsize==sizeof(Elf_Shdr) check; shdr[i] indexed with 64-byte stride. Crafted e_shentsize<64 makes allocation too small β shdr[i] OOB read.
No comments yet.