//nefariousplan

CVE-2026-45251: procdesc_free Has Been Missing seldrain Since 2012. The First Auditor To Ask Was An AI.

vendor

pattern

cve

proof of concept

procdesc_free() in the FreeBSD kernel destroys a struct procdesc that holds an embedded struct selinfo. It does not call seldrain() to wake the threads blocked on that selinfo before tearing the object down. The omission has been continuously in the tree since FreeBSD 9.0, released January 2012.

CVE-2026-45251 is the consequence. Calif's audit found it on a first pass, by enumerating every selrecord() caller in the kernel and asking the same question of each one: is there a matching seldrain() on every final-free path of the owner? The audit was written by an AI. The exploits were written by an AI. The audit found fourteen other kernel bugs the same way. The bugs were the demo. The deliverable was the question.

The selrecord contract

FreeBSD's kernel supports poll(2) and select(2) on a wide variety of file descriptor types. Each type that wants to be pollable embeds a struct selinfo in its owner object and exposes a _poll callback. When userspace blocks on a pollable fd, the kernel runs the callback. The callback calls selrecord(td, &owner->selinfo). selrecord() allocates a struct selfd, sets selfd->sf_si = &owner->selinfo, and links the selfd into both the thread's per-call list and the owner's si_tdlist, so a subsequent selwakeup() or timeout can find every blocked thread and clean up after it.

The contract has two halves. The owner is responsible for both.

First, when an event occurs that should wake the waiters, the owner calls selwakeup(&owner->selinfo). selwakeup() walks si_tdlist, wakes each blocked thread, and clears the per-thread selfd's sf_si pointer so a subsequent timeout in that thread does not dereference the owner.

Second, and this is the half that recurs in the bug reports, when the owner is being freed, the owner is supposed to call seldrain(&owner->selinfo). seldrain() is a wake-and-clear pass designed for the final-free path where the owner is about to disappear. Without it, any blocked thread that wakes later, from timeout, signal, or unrelated poll-set teardown, runs selfdfree() on a stale selfd whose sf_si and sf_mtx point at memory the kernel has already returned to the allocator.

The contract is documented in tree commentary on selinfo-bearing structs and in long-standing patches that retrofitted seldrain() into other subsystems. The contract is not enforced by the type system, by the build, or by any kernel lint.

procdesc_free does not honor it

procdesc is the FreeBSD subsystem that lets a process hold a descriptor referring to another process. The descriptor is created by pdfork(2), an unprivileged syscall, and the resulting fd supports poll(2). The owner object is struct procdesc, defined in sys/sys/procdesc.h. Its selinfo field is pd->pd_selinfo.

The constructor at sys/kern/sys_procdesc.c:223 initializes it:

knlist_init_mtx(&pd->pd_selinfo.si_note, &pd->pd_lock);

The poll handler at procdesc_poll() registers the caller:

selrecord(td, &pd->pd_selinfo);

The final-free path at procdesc_free() ships the bug:

if (refcount_release(&pd->pd_refcount)) {
        ...
        knlist_destroy(&pd->pd_selinfo.si_note);
        PROCDESC_LOCK_DESTROY(pd);
        free(pd, M_PROCDESC);
}

There is no seldrain(&pd->pd_selinfo) in procdesc_free(). There never has been. The function was committed in 2012 with the procdesc subsystem, and every revision between then and the May 2026 patch shipped the same omission. The branch scan in Calif's writeup confirms the span: main, stable/15, stable/14, stable/13, stable/12, stable/11, stable/10, stable/9, and every release branch inside each, all marked VULN.

The patch is a single line. Commit 4b6a23e, authored by markjdb on 20 May 2026, title "procdesc: Make sure to drain selinfo sleepers in procdesc_free()":

 if (refcount_release(&pd->pd_refcount)) {
         ...
+        seldrain(&pd->pd_selinfo);
         knlist_destroy(&pd->pd_selinfo.si_note);
         PROCDESC_LOCK_DESTROY(pd);
         free(pd, M_PROCDESC);
 }

From timeout to kernel pointer write

The chain Calif demonstrates is end-to-end local privilege escalation. The unprivileged process does this:

  1. pdfork(2) to create a new struct procdesc and a child.
  2. Spawn two threads, each blocked in poll(2) on the procdesc fd with a finite timeout.
  3. From a third thread, close() the procdesc fd while the child remains alive.

The close drops the last fd reference, procdesc_free() runs, the struct procdesc is released back to its UMA bucket. The two blocked threads still hold struct selfd records whose sf_si and sf_mtx point into the freed memory.

The attacker reclaims the slot with SCM_RIGHTS. UNIX-domain sockets allow sending file descriptors as ancillary data. The kernel internalizes them with:

fdev = malloc(sizeof(*fdev) * oldfds, M_FILECAPS, M_WAITOK);

at sys/kern/uipc_usrreq.c:3773. struct filedescent is 0x30 bytes on the tested kernel; passing two file descriptors allocates 0x60, which lands in the same UMA bucket as the freed 0x80 procdesc. By priming the passed fd with cap_ioctls_limit(passfd, dummy, 8) before the send, the resulting filedescent has fde_caps.fc_nioctls == 8 and fde_caps.fc_ioctls pointing at an attacker-allocated 8-qword buffer. The offset of fde_caps.fc_ioctls inside struct filedescent is 0x18. The offset of pd_selinfo.si_tdlist.tqh_first inside struct procdesc is also 0x18.

When the first poll thread's timeout fires, seltdclear() calls selfdfree(), which runs:

mtx_lock(sfp->sf_mtx);
TAILQ_REMOVE(&sfp->sf_si->si_tdlist, sfp, sf_threads);
mtx_unlock(sfp->sf_mtx);
free(sfp, M_SELFD);

sfp->sf_si is the freed procdesc's selinfo address, which is the freed procdesc plus a fixed offset. The macro expansion of TAILQ_REMOVE() writes the second waiter's struct selfd * into (old_procdesc + 0x18). That offset, post-reclaim, is fdev[0].fde_caps.fc_ioctls.

The receiving end of the SCM_RIGHTS exchange now holds an fd whose Capsicum ioctl pointer is a kernel pointer to a live struct selfd. cap_ioctls_get(recvfd, leak, 8) copies 64 bytes from that pointer to userspace; the attacker has leaked the second selfd's sf_si, sf_mtx, owning thread, and poll cookie. cap_ioctls_limit(recvfd, NULL, 0) frees that selfd. cap_ioctls_limit(fakefd, fake_qwords, 8) reclaims the freed slot with attacker-controlled qwords.

When the second poll thread's timeout fires, the same TAILQ_REMOVE() runs over the attacker's forged selfd. The forged sf_threads.tqe_next and sf_threads.tqe_prev drive the macro's two writes. One is an attacker-chosen value to an attacker-chosen kernel address.

The final useful write targets a polling thread's td_ucred field. The value is the kernel address of a fake struct ucred the attacker placed inside a pipe buffer earlier in the chain. When that thread returns from poll(), its td_ucred briefly points at a forged root credential. It uses the window to chown(argv[0], 0, 0) and chmod(argv[0], 04755) on the exploit binary. The exploit then exits, the SUID-root binary remains on disk, and --shell runs /bin/sh -p to drop a root shell.

The Capsicum primitive triad

The chain uses Capsicum's per-fd ioctl allowlist API as a three-way primitive over the same fc_ioctls field. The roles, from Calif's writeup:

cap_ioctls_limit(passfd, dummy, 8)
    primes an fd so SCM_RIGHTS copies fc_nioctls=8 into fdev[0].

cap_ioctls_get(recvfd, leak, 8)
    treats corrupted fc_ioctls as a kernel pointer and copies 64 bytes
    from that address to userspace.

cap_ioctls_limit(recvfd, NULL, 0)
    frees the leaked live selfd because fc_ioctls now points at it.

cap_ioctls_limit(fakefd, fake_qwords, 8)
    allocates a fresh 64-byte M_FILECAPS ioctl array, reclaiming the
    freed selfd slot with attacker-controlled qwords.

The same field is the read source, the free target, and the reclaim destination. The Capsicum helpers were designed to constrain capabilities. In this chain they are the ladder.

The same advisory covers netmap

FreeBSD-SA-26:19 is filed against the file module with a single CVE. Commit 53a78e582a6f, by markjdb on the same day as the procdesc fix, ships in the same security release. Its title is "netmap: Drain selinfo sleepers in nm_os_selinfo_uninit()". The diff adds, at sys/dev/netmap/netmap_freebsd.c, the line:

seldrain(&si->si);

procdesc was one subsystem missing the call. netmap was another. The two patches ship together because they are the same bug class with two demonstrated instances.

This is a design-debt-driver. The selrecord/seldrain contract is a kernel invariant that every selinfo owner must independently honor. The contract is not captured by the API surface, not enforced by the type system, and not checked by any lint. Each subsystem implements its own teardown, and each one is free to forget. We have written about this shape before, where a single-line fix in one Apache Camel component left five sibling subclasses unchanged, and where a 2012-era nginx patch turned out to cover one half of its own structural class fourteen years later. The selinfo case is the same shape at kernel scope. The patch closes procdesc and netmap. The contract holds the primitive.

How many other selinfo owners across the FreeBSD tree are missing a seldrain() on a final-free path is a question the advisory does not answer. Calif's writeup names six audit properties; the first two are the question. The remaining selinfo owners are the future advisories.

Calif published fifteen bugs and one audit skill

Calif's writeup includes an "Audit Pattern Checklist". It enumerates six properties the procdesc bug matched:

  • Embedded struct selinfo / knlist owner lifetime requires waiter drain before owner free.
  • Every selrecord() path requires a matching seldrain() on every final-free path of its owner.
  • selwakeup() is insufficient unless guaranteed on every free path.
  • selfdfree() stale TAILQ_REMOVE() is a controlled write primitive.
  • SCM_RIGHTS struct filedescent[] allocations are a same-bucket reclaim target.
  • Capsicum cap_ioctls_get() and cap_ioctls_limit() are read, free, and reclaim primitives over fc_ioctls.

The first three are auditor rules. The last three are exploit primitives. Together they are a portable recipe. Calif's blog post says they shared "the audit skill" with the FreeBSD team. The deliverable was the recipe.

The same audit produced fifteen kernel bugs on a first pass: five LPEs, three RCEs, one bhyve guest-to-host escape, and several memory disclosures and DoS. Three of the LPEs, including this one, were published with full exploits and writeups. The blog post that announces the work thanks "OpenAI and Anthropic, for the tokens."

The path embedded in Calif's writeup names its working directory: /home/x/kernel/codex_fbsd_exec/procdesc_filecaps_lpe15.c. codex_fbsd_exec is the working directory of OpenAI's Codex coding system, executing against a local FreeBSD 15 build. The exploit is 882 lines of C, with kernel offsets, UMA-bucket reclaim arithmetic, and a thread-borrowing credential primitive. Calif publishes it verbatim, with the stated intent of keeping the AI text "as-is, as a historical artifact showing what AI vulnerability research looked like in 2026."

Every FreeBSD release between January 2012 and May 2026 shipped this one-line UAF. No human auditor reading sys_procdesc.c ever asked the question that found it. The patch closes procdesc and netmap. The question Calif wrote down does not.

PoC: califio/publications

Every kernel that ships a selrecord-shaped primitive has a new auditor pointed at it. The auditor scales with tokens.