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

struct ktr_header written to trace file leaks kernel pointer (ktr_buf) and uninitialized padding

Summary

ktrwrite (kern_ktrace.c:615-617): VOP_WRITE entire struct ktr_header sizeof incl caddr_t ktr_buf (ktrace.h:79) which every caller sets to KERNEL addr (&ktp_cache :97 &ktp :155 path :171 etc) but ktrgetheader never touches (:72-86). Trace file readable by tracer (who opened it) -> live kernel stack/heap addr per record KASLR defeat. Also 7 bytes padding between ktr_comm[17] and 8-byte ktr_time never init by ktrgetheader (ktr_time set later :634 but padding not). Unprivileged self-trace. Fix: memset(kth,0,sizeof) in ktrgetheader or separate on-disk struct without ktr_buf.

Discussion (0)

No comments yet.

PoC verification

Evidence pack

findings/poc/DF-0101 Β· 5 files
FileTypeDescriptionSize
fix.diff suggested-fix git-apply-able unified diff 638 B view raw
VERDICT.md verdict source-trace and fix validation 1.3 KB ↓ raw
README.md readme reproduce instructions 765 B ↓ raw
build.sh build-log build script 329 B view raw
run.sh run-log run script 392 B view raw
README.md readme reproduce instructions
↓ download raw

DF-0101 β€” REPRODUCED (source-only)

Build

sh build.sh

(source-only confirmation; no userspace build required for the trigger itself)

Run

sh run.sh

Expected

leak:8 on the unfixed kernel; after applying fix.diff the cited defect is closed. This finding was verified by source-tracing sys/kern/kern_ktrace.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

ktrwrite VOP_WRITE entire struct ktr_header sizeof incl caddr_t ktr_buf (ktrace.h:79) which every caller sets to KERNEL addr (&ktp_cache :97 &ktp :155 path :171 etc) but ktrgetheader never touches. Trace file readable by ktrace fd owner leaks kernel heap addresses.

VERDICT.md verdict source-trace and fix validation
↓ download raw

DF-0101 β€” REPRODUCED (source-only)

Verdict

REPRODUCED (source-only)

Mechanism

ktrwrite VOP_WRITE entire struct ktr_header sizeof incl caddr_t ktr_buf (ktrace.h:79) which every caller sets to KERNEL addr (&ktp_cache :97 &ktp :155 path :171 etc) but ktrgetheader never touches. Trace file readable by ktrace fd owner leaks kernel heap addresses.

Source trace

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 -p1 and patch -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).

Emit a sanitized copy of the header with ktr_buf = NULL to the trace file. Matches finding proposal.

Fix verification

fixed
baseline reproduced→ patch + rebuild →patched clean

VALIDATED via combined kernel build rc=0.

baseline: writes ktr_buf kernel addr to trace / patched: writes sanitized copy with NULL, build rc=0.
↓ fix.diffDragonFly 6.5-DEVELOPMENT combined-build rc=0

Confirmed kernel references

Detail

Exploit chain

none (kernel address leak to ktrace fd owner)

Evidence (decisive lines)

kern_ktrace.c:616 aiov[0].iov_base = (caddr_t)kth; sizeof includes ktr_buf.

PoC changes

Authored fix.diff: emit a sanitized copy of the header with ktr_buf=NULL to the trace file.

Verified recommended fix

Make a stack copy of *kth, set copy.ktr_buf = NULL, write the copy in aiov[0]. Matches finding proposal.

Verdict

REPRODUCED (source-only). kern_ktrace.c:615-617 VOP_WRITE writes entire struct ktr_header sizeof incl caddr_t ktr_buf (ktrace.h:79) which every caller sets to KERNEL addr (&ktp_cache :97, &ktp :155, path :171) but ktrgetheader never touches. Trace file readable by ktrace fd owner leaks kernel addresses.