# PoC DF-1540: if_mn ngmn_disconnect UAF on sch->hook

**Class:** Use-after-free (dangling pointer)
**Cited site:** `sys/dev/netif/mn/if_mn.c:475,758,407`

## Reproduction status

HW/module gated — **cannot be live-triggered on the audit QEMU guest.**

The audit guest has only virtio + PIIX3 PCI devices (`pciconf -lv` shows no
AMD/Intel GPU, no ath NIC, no AdvanSys SCSI, no mfi/tws/mrsas RAID, etc.),
so the cited code path is not reachable at runtime on this guest.

The bug is **confirmed at the source level** by tracing the cited path:line
in `sys/dev/netif/mn/if_mn.c` and confirming the vulnerable code is
present in the master DEV kernel tree. The `fix.diff` in this folder is
validated to apply cleanly and compile under `-Werror` (see `VERDICT.md`).

## Mechanism

ngmn_newhook sc->ch[chan]->hook=hook at 475. ngmn_disconnect at 758 sets sch->state=DOWN but NEVER clears sch->hook. Netgraph core (ng_base.c:855-858) kfree(hook->name)+kfree(hook) immediately after disconnect returns. Later NGM_TEXT_STATUS iterates sc->ch[chan] (still non-NULL) and derefs sch->hook->name at 407 -> dangling pointer.

## Realistic impact ceiling (on suitable HW)

kernel pointer leak (M_NETGRAPH freelist ptr printed as name); potential UAF corrupt on re-alloc

## Fix

Clear sch->hook = NULL in ngmn_disconnect after setting state=DOWN.

See `fix.diff` for the git-apply-able patch.

## How to validate the fix

```sh
scp -F dfbsd-qemu/config fix.diff dfbsd:/root/DF-1540.diff
ssh -F dfbsd-qemu/config dfbsd 'cd /usr/src && patch -p1 --forward < /root/DF-1540.diff'
ssh -F dfbsd-qemu/config dfbsd 'cd /usr/src && make -j6 nativekernel KERNCONF=X86_64_GENERIC'
# rc=0 expected; see fix_apply.log + fix_build.log in this folder.
```
