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

task_struct allocated in kthread_run() is never freed and td_linux_task is never cleared, leaking memory and leaving dangling back-pointer in struct thread

Summary

kthread_run() kzalloc-s task_struct wires td->td_linux_task = task (line 65) but neither kthread_stop() nor normal kthread exit path ever calls kfree() on it or clears td_linux_task. Pure LWKT kthreads never traverse kern_exit.c lwp-exit path so linux_task_drop_callback (kern_exit.c:708-709) never fires. Every kthread_run/kthread_stop cycle leaks one task_struct (~256 bytes+spinlock) AND leaves freed-elsewhere struct thread with td_linux_task pointing at leaked task which still points back at now-objcache-recyclable td. Stale back-pointer: lwkt_free_thread returns ts->dfly_td to thread_cache WITHOUT clearing td_linux_task; DragonFly objcache does not zero objects on put. When lwkt_alloc_thread hands td back for unrelated new thread td_linux_task is stale non-NULL pointer to leaked task_struct whose dfly_td points at now-recycled thread. Any code following td_linux_task (signal_pending/fatal_signal_pending current macro) will dereference stale possibly-reused memory treat attacker-influenced data as live task_struct = type-confusion/info-leak primitive compounding DF-2195. Requires same access: /dev/dri/renderD* user or ability to trigger GPU reset/driver reload.

Discussion (0)

No comments yet.

PoC verification

Evidence pack

findings/poc/DF-2196 Β· 2 files
FileTypeDescriptionSize
VERDICT.md file 744 B ↓ raw
fix.diff file 164 B view raw
VERDICT.md file
↓ download raw

DF-2196 - Verification Verdict

Status: reproduced (source-confirmed) Impact: none Confidence: certain

Verdict

Source-confirmed: kthread_run (:54,65) kzalloc task_struct wires td->td_linux_task; neither kthread_stop nor exit path kfree-s it or clears td_linux_task; memory leak; DRM-module-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/drm/linux_kthread.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)

kthread_run task_struct never freed; leak; DRM-gated

Verified recommended fix

kthread_run task_struct never freed; leak; DRM-gated

Verdict

kthread_run task_struct never freed; leak; DRM-gated