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

Recursive exclusive lockmgr panic ('locking against myself') in pf_state_key_attach under pf_state_item allocation failure

Summary

For PFSTATE_STACK_GLOBAL states (every RDR translation sets it; also NAT/fixed-port cases) pf_state_key_attach() holds pf_global_statetbl_lock EXCLUSIVELY. If the pf_state_item kmalloc(M_NOWAIT) fails, the error path calls pf_state_key_detach() which re-acquires the same lock EXCLUSIVELY; the lock is initialized without LK_CANRECURSE so lockmgr panics 'locking against myself' - a memory shortage becomes a remote-packet-path kernel panic. Code-proven (unconditional panic on non-recursive exclusive re-acquire); not guest-tested (forcing mid-function M_NOWAIT failure impractical). Fix: inline the undo without re-entering the lock. [VERIFIED pass2: M_NOWAIT failure mid-function not injectable; recursive exclusive lockmgr certain by inspection; fix compile-validated]

Discussion (0)

No comments yet.

PoC verification

Evidence pack

findings/poc/DF-3265 Β· 9 files
FileTypeDescriptionSize
fix.diff β€” 1.4 KB view raw
README.md β€” 400 B ↓ raw
VERDICT.md β€” 1.7 KB ↓ raw
build.sh β€” 141 B view raw
run.sh β€” 88 B view raw
manifest.json β€” 448 B view raw
verdict.json β€” 1.4 KB view raw
fix.diff β€” 1.4 KB view raw
env.txt β€” 272 B view raw

DF-3265 -- verification pack

Finding: recursive lockmgr panic in pf_state_key_attach under allocation failure

Status: not_reproduced / impact panic / confidence certain

What was run

n/a (cannot force the M_NOWAIT failure)

How to reproduce

n/a

Expected

n/a

See VERDICT.md for the full narrative and verdict.json for the persisted machine verdict. Artifacts: fix.diff.

VERDICT.md
↓ download raw

DF-3265 verification

Kernel: DragonFly dfbsd 6.5-DEVELOPMENT #0: Thu Jul 2 06:02:54 UTC 2026 root@dfbsd:/usr/obj/usr/src/sys/X86_64_GENERIC x86_64

Bottom line

Code-proven and not injectable: for PFSTATE_STACK_GLOBAL states (every RDR translation) pf_state_key_attach holds pf_global_statetbl_lock exclusively, and if the pf_state_item kmalloc(M_NOWAIT) fails the error path calls pf_state_key_detach, which re-acquires the same lock exclusively; the lock is initialized without LK_CANRECURSE so lockmgr panics with locking against myself - a memory shortage on the packet path becomes a remote-triggered panic. Forcing a mid-function M_NOWAIT failure under memory pressure at the exact allocation is not practical on this guest. Fix releases the global lock before the detach and re-acquires it; compile-validated.

Kernel references

Exploit chain

(none: availability/correctness finding; no privilege chain)

Fix

drop and re-acquire the global lock around the error-path detach

See fix.diff in this directory (git-apply-able against the read-only sys/ tree; applied only inside the disposable verification guest).

Reproduction

build: n/a (cannot force the M_NOWAIT failure)

run: n/a

expected: n/a

Notes on the PoC (what changed vs the finding sketch)

(none)

Fix status (batch validation)

Applied with the 36 sibling fix.diffs of this batch in findings/poc/_batch41/all_fixes.patch; single in-guest make -j6 nativekernel KERNCONF=X86_64_GENERIC completed RC=0 with zero errors under -Werror (full log: findings/poc/_batch41/fix_build8.log). Behavior A/B intentionally skipped for this Info-tier item.

Fix verification

not_testable
↓ fix.diffper-fix-DF-3265

Confirmed kernel references

Detail

Evidence (decisive lines)

VERDICT.md walk over pf.c:911-917 and pf_state_key_detach at :955-985

Verified recommended fix

drop and re-acquire the global lock around the error-path detach

Verdict

Code-proven and not injectable: for PFSTATE_STACK_GLOBAL states (every RDR translation) pf_state_key_attach holds pf_global_statetbl_lock exclusively, and if the pf_state_item kmalloc(M_NOWAIT) fails the error path calls pf_state_key_detach, which re-acquires the same lock exclusively; the lock is initialized without LK_CANRECURSE so lockmgr panics with locking against myself - a memory shortage on the packet path becomes a remote-triggered panic. Forcing a mid-function M_NOWAIT failure under memory pressure at the exact allocation is not practical on this guest. Fix releases the global lock before the detach and re-acquires it; compile-validated.