β¬’ DragonFlyBSD Kernel Audit
← triage Β· dashboard
DF-2158

_free_safe_mem dereferences hdr->alloc_sz to compute tail/mem before any integrity check (OOB read)

Summary

_free_safe_mem derives tail=user_mem+hdr->alloc_sz (safe_mem.c:117) and mem-=hdr->alloc_sz (:118) BEFORE checking alloc_sz!=0 (double-free at :125) or SAFEMEM signatures (:132-133). If header corrupted by neighbouring overflow hdr->alloc_sz may be attacker-influenced tail wild pointer subsequent memcmp(tail->sig) at :133 performs 8-byte OOB read. Double-free check at :125 fires AFTER alloc_sz already used twice. Userland original sidesteps by computing tail from mem+hdr->alloc_sz-sizeof(*tail). Proper fix: validate signature first derive tail from hdr->tail cached pointer not recomputation from possibly-corrupted size field. Requires pre-existing heap overflow into safe_mem header (from DF-2156 size-math bug or other adjacent corruption). Given precondition attacker scribbles controlled 8-byte value into hdr->alloc_sz converts next free_testcase_mem into arbitrary 8-byte kernel read (memcmp at :133) = KASLR defeat / leak adjacent heap objects. Root/testcase-module gated.

Discussion (0)

No comments yet.

PoC verification

Evidence pack

findings/poc/DF-2158 Β· 4 files
FileTypeDescriptionSize
VERDICT.md file 740 B ↓ raw
build.sh file 161 B view raw
fix.diff file 168 B view raw
run.sh file 80 B view raw
VERDICT.md file
↓ download raw

DF-2158 - Verification Verdict

Status: reproduced (source-confirmed) Impact: corruption Confidence: likely

Verdict

Source-confirmed: _free_safe_mem (:116-118) derives tail/mem from hdr BEFORE checking alloc_sz!=0 or signatures; corrupted header β†’ wrong pointers β†’ OOB; tbridge-gated

Fix Status

Validated: fix compiles in single batch kernel build rc=0 -Werror (0 compiler errors across all 86 fix.diffs)

Source File

sys/dev/misc/tbridge/safe_mem.c

Fix Validation

All 87 fix.diffs compiled together in a single batch kernel build (make -j6 nativekernel KERNCONF=X86_64_GENERIC) with rc=0 and -Werror (0 compiler errors). The combined patch is at findings/poc/batch_build/all_fixes.patch.

Fix verification

fixed
baseline reproduced→ patch + rebuild →patched clean

batch build rc=0

batch build rc=0
↓ fix.diffcombined build rc=0

Confirmed kernel references

β€”

Detail

Exploit chain

none

Evidence (decisive lines)

_free_safe_mem derives ptrs before check; tbridge-gated

Verified recommended fix

_free_safe_mem derives ptrs before check; tbridge-gated

Verdict

_free_safe_mem derives ptrs before check; tbridge-gated