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

IPV6_MULTICAST_IF caches an unreferenced ifnet pointer that is never purged for TCP6 pcbs β†’ dangling im6o->im6o_multicast_ifp after interface destruction

Summary

ip6_setmoptions() stores a raw ifnet pointer in im6o->im6o_multicast_ifp with no refcount. When an interface is destroyed, in6_ifdetach() purges stale pointers only from ripcbinfo and udbinfo[0] - never from tcbinfo - yet ip6_ctloutput() accepts IPV6_MULTICAST_IF on any IPPROTO_IPV6-level socket including TCP6. if_detach() NULLs the ifindex slot and if_free() kfrees the ifnet, so a TCP6 socket that pinned the interface keeps a dangling pointer; getsockopt(IPV6_MULTICAST_IF) then dereferences freed memory, and ip6_output's multicast branch would deref if_flags. Any local user can create the socket and pin a destroyable interface (tap/tun/ppp/vlan); privileged destruction is the free trigger. Small but genuine UAF read the purge machinery was built to prevent. Not run (Low, leak-only; code-level proof at 4 cited sites). Fix: add in6_pcbpurgeif0(&tcbinfo...) to in6_ifdetach, or validate the cached ifp at use time. [VERIFIED pass2: reproduced live - TCP6 socket caches tap0, after destroy getsockopt still returns index 3 via freed-ifnet deref, purge list covers only rip plus udp; purge-fix A/B returns 0]

Discussion (0)

No comments yet.

PoC verification

Evidence pack

findings/poc/DF-3308 Β· 8 files
FileTypeDescriptionSize
README.md β€” 1.1 KB ↓ raw
VERDICT.md β€” 2.5 KB ↓ raw
fix.diff β€” 337 B view raw
fixkernel.log β€” 988 B view raw
live2.log β€” 511 B view raw
manifest.json β€” 850 B view raw
mif6.c β€” 3.5 KB view raw
verdict.json β€” 2.0 KB view raw

DF-3308 -- verification pack

Method: Live PoC on the QEMU guest (stock INVARIANTS kernel) Status: REPRODUCED | impact: none | confidence: certain

What this is

IPV6_MULTICAST_IF stores an unreferenced ifnet pointer in in6p_moptions (ip6_output.c:2253) and the interface-detach purge runs only for rip+udp (in6_ifattach.c:818-819) - TCP6 pcbs keep a DANGLING im6o_multicast_ifp. Live: TCP6 socket cached tap0 (index 3); after ifconfig tap0 destroy, getsockopt(IPV6_MULTICAST_IF) still dereferenced the freed ifnet and returned 3 (ip6_output.c:2499 reads im6o->im6o_multicast_ifp->if_index). Memory was not recycled in this run, so no garbage/crash - a 1-int stale read; impact limited.

Build

cc -O -o <prog> <prog>.c   (on the guest)

Run

(no arg; root)

(success criterion: see VERDICT.md)

Evidence

live2.log DF-3308 section: before destroy: index 3; after destroy: returns 3 (deref of freed ifnet)

Kernel references: sys/netinet6/ip6_output.c:2253, sys/netinet6/ip6_output.c:2493-2499, sys/netinet6/in6_ifattach.c:818-819, sys/netinet6/in6_pcb.c:688-756

VERDICT.md
↓ download raw

DF-3308 -- VERDICT

REPRODUCED (impact=none, 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

Summary

IPV6_MULTICAST_IF stores an unreferenced ifnet pointer in in6p_moptions (ip6_output.c:2253) and the interface-detach purge runs only for rip+udp (in6_ifattach.c:818-819) - TCP6 pcbs keep a DANGLING im6o_multicast_ifp. Live: TCP6 socket cached tap0 (index 3); after ifconfig tap0 destroy, getsockopt(IPV6_MULTICAST_IF) still dereferenced the freed ifnet and returned 3 (ip6_output.c:2499 reads im6o->im6o_multicast_ifp->if_index). Memory was not recycled in this run, so no garbage/crash - a 1-int stale read; impact limited.

How it was verified

  • Method: Live PoC on the QEMU guest (stock INVARIANTS kernel)
  • Kernel references: sys/netinet6/ip6_output.c:2253, sys/netinet6/ip6_output.c:2493-2499, sys/netinet6/in6_ifattach.c:818-819, sys/netinet6/in6_pcb.c:688-756
  • Evidence: live2.log DF-3308 section: before destroy: index 3; after destroy: returns 3 (deref of freed ifnet)
  • Reachability: local-unpriv where noted in the summary; root-config for tun/lagg/carp/ipfw3/gre items; remote-facing for the packet parsers (wlan harnesses model the RX/TX path verbatim because the guest has no 802.11 hardware; precedent DF-0393/DF-0594/DF-0621/DF-0350).
  • Privesc assessment: no uid0 chain exists for any finding in this batch -- the memory-safety items are bounded info reads (kernleak bucket) or fault-injection-gated NULL derefs; nothing yields a write primitive or control over privileged state. The one panic-class live item (DF-3414) is root-only (SIOCIFDESTROY).

Fix

fix_status: fixed -- Validated on the patched kernel: the combined-fix build adds in6_pcbpurgeif0(&tcbinfo[0], ifp) to the detach purge; after the fix, the TCP6 socket readout returns 0 (pointer purged) instead of the stale index (see fixkernel section). fix.diff: natural one-line/class fix authored against the read-only sys/ tree (never applied there). Baseline vs patched (kernel): see fixkernel-*.log -- the combined-fix kernel (DF-3308+DF-3349+DF-3359+DF-3445/3446 fixes built together) was booted and the exact PoCs re-run.

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

fixed
baseline reproduced→ patch + rebuild →patched clean

A/B on the combined-fix kernel (kernel #1 17:38, in6_ifattach.c purge extended to tcbinfo): baseline stock kernel returned the stale index 3 after tap0 destroy (freed-ifnet deref); patched kernel returns 0 (im6o_multicast_ifp purged). See fixkernel.log / fix_run.log.

↓ fix.diffDFBSD 6.5-DEVELOPMENT combined-fix kernel (see fixkernel.log)

Confirmed kernel references

Detail

Evidence (decisive lines)

live2.log DF-3308 section: before destroy: index 3; after destroy: returns 3 (deref of freed ifnet)

Verified recommended fix

fix.diff

Verdict

IPV6_MULTICAST_IF stores an unreferenced ifnet pointer in in6p_moptions (ip6_output.c:2253) and the interface-detach purge runs only for rip+udp (in6_ifattach.c:818-819) - TCP6 pcbs keep a DANGLING im6o_multicast_ifp. Live: TCP6 socket cached tap0 (index 3); after ifconfig tap0 destroy, getsockopt(IPV6_MULTICAST_IF) still dereferenced the freed ifnet and returned 3 (ip6_output.c:2499 reads im6o->im6o_multicast_ifp->if_index). Memory was not recycled in this run, so no garbage/crash - a 1-int stale read; impact limited.