# DF-0166 — syscap_set INPARENT: uid/prison checked without p_token

**Verdict:** REPRODUCED (source-only confirmation, Low severity)
**Impact:** none / defense-in-depth / latent (see below)
**Confidence:** certain
**Guest:** DragonFly dfbsd 6.5-DEVELOPMENT DragonFly 6.5-DEVELOPMENT #0: Thu Jul  2 06:02:54 UTC 2026     root@dfbsd:/usr/obj/usr/src/sys/X86_64_GENERIC  x86_64

## Mechanism (source-traced)

CONFIRMED by source trace. sys_syscap_set INPARENT(:164-178) calls pfind(:165) then checks uid/prison(:168-169) WITHOUT p_token; token acquired only at :177. Race: parent changes uid/prison between check and mutation. One-way ratchet (only ORs restriction bits). PID recycling risk.

## Kernel references (confirmed)
- `sys/kern/kern_caps.c:165`
- `sys/kern/kern_caps.c:168`
- `sys/kern/kern_caps.c:177`

## Fix

Hold p_token across the uid/prison authorization check. Supersedes finding proposal.

The standalone git-apply-able diff is in `fix.diff`.

## Build validation

`fix.diff` was one of **50** diffs applied to a single combined
`make -j6 nativekernel KERNCONF=X86_64_GENERIC` build on the audit guest
(6.5-DEVELOPMENT #0, INVARIANTS ON). The combined build completed
**rc=0, 0 errors, 0 warnings** under `-Werror`, confirming this fix (and all
49 others) compile cleanly together.

- Combined build log (35649 lines): `findings/poc/DF-0166/../../_combined_build.log` (reference; full log at audit time).
- Combined kernel.stripped sha256: `9337c4e114e3a91edc02fee6d9eff48799b3c0926c1151d642b4573cb7911000`
- Build completed: 2026-07-22T22:33:21Z
