-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256 NEFARIOUSPLAN-CANONICAL-V1 {"body_md":"## `sizeof(*groups)` where `groups` has type `gid_t **`\n\nThe bug fits in one expression. `kern_setcred_copyin_supp_groups()` was added to `sys/kern/kern_prot.c` on December 16, 2024 by commit `ddb3eb4efe55`, in the same patch that introduced `setcred(2)` and its supporting MAC hooks. The function's signature gives `groups` the type `gid_t **`:\n\n```c\nstatic int\nkern_setcred_copyin_supp_groups(struct setcred *const wcred,\n const u_int flags, gid_t *const smallgroups, gid_t **const groups)\n{\n ...\n *groups = wcred->sc_supp_groups_nb < CRED_SMALLGROUPS_NB ?\n smallgroups : malloc((wcred->sc_supp_groups_nb + 1) *\n sizeof(*groups), M_TEMP, M_WAITOK);\n error = copyin(wcred->sc_supp_groups, *groups + 1,\n wcred->sc_supp_groups_nb * sizeof(*groups));\n```\n\nOn LP64, `sizeof(*groups)` evaluates to `sizeof(gid_t *) == 8`, not the intended `sizeof(gid_t) == 4`. The expression appears in two places. The `malloc` on line 530 over-allocates by a factor of two, which is wasteful and safe. The `copyin` on line 533 writes twice as many bytes as the destination can hold, which is CVE-2026-45250.\n\nThe destination depends on whether `sc_supp_groups_nb` exceeds `CRED_SMALLGROUPS_NB` (16). When it doesn't, `*groups` is set to the caller's `smallgroups`, which is `gid_t smallgroups[CRED_SMALLGROUPS_NB]` declared on `user_setcred()`'s stack, 64 bytes. The `copyin` writes to `*groups + 1`, i.e. `&smallgroups[1]`, leaving 60 bytes of usable space. With `sc_supp_groups_nb == 15`, the call writes `15 * 8 == 120` bytes into a 60-byte window. The overflowing 60 bytes are read verbatim from a userspace pointer in the caller's `wcred`.\n\n## The overflow runs at line 528. The privilege check runs at line 813.\n\n`kern_setcred_copyin_supp_groups()` is called from `user_setcred()` at line 604. That call is the data-marshaling phase: read the userspace `wcred`, copy in the supplementary groups, prepare the new credential. Authorization, the call into `priv_check_cred(PRIV_CRED_SETCRED)`, doesn't happen until line 813 inside `kern_setcred()`, which `user_setcred()` invokes at line 623.\n\nThe overflow happens two hundred and nine lines before the kernel asks who is calling. The bug is reachable to any unprivileged user via a single syscall:\n\n```c\nstruct setcred wcred = SETCRED_INITIALIZER;\nconst int nb = 15;\ngid_t *buf = malloc(nb * sizeof(gid_t *)); /* 120 bytes */\nmemset(buf, 0x41, nb * sizeof(gid_t *));\nwcred.sc_supp_groups_nb = nb;\nwcred.sc_supp_groups = buf;\nsyscall(SYS_setcred, SETCREDF_SUPP_GROUPS, &wcred, sizeof(wcred));\n```\n\nThat is `poc_dos.c` in the published exploit drop, minus the print statements. Any user with shell access on a 14.4-RELEASE box panics the kernel. The CVE-2026-45250 CVSS vector is `AV:L/AC:L/PR:L/UI:N`. PR:L credits the syscall with a privilege precondition. The overflow does not have one. The fact that the syscall is named `setcred` and ordinarily wants credentials does not constrain who reaches the line that overflows.\n\n## The chain is one syscall to uid=0\n\nThe 60 overflowing bytes land inside `user_setcred()`'s callee-saved register spills. The byte mapping on 14.4 GENERIC is:\n\n```\nbuf[60..67] mac.m_buflen\nbuf[68..75] mac.m_string\nbuf[76..83] spilled td pointer\nbuf[84..91] saved rbx\nbuf[92..99] saved r12 <- propagates up the stack\nbuf[100..107] saved r13\nbuf[108..115] saved r14\nbuf[116..119] low 32 bits of saved r15\n```\n\n`sys_setcred()`, the layer between `user_setcred()` and the syscall dispatcher, saves `rbp`, `r14`, and `rbx` in its prologue. It does not save `r12`. The corrupted `r12` popped by `user_setcred()`'s epilogue propagates unchanged through `sys_setcred()`'s epilogue and out into `amd64_syscall()`. At `amd64_syscall+0x155`:\n\n```\nmov rcx, [r12 + 0x3f8] ; rcx loaded from attacker-controlled memory\nmov rdi, rbx ; rdi = curthread\nmov esi, eax ; esi = setcred retval\ncall [rcx + 0xc8] ; two-level indirect call\n```\n\nBoth indirections take their source from a userspace-driven write. The kernel's only constraint is that the two qword reads have to succeed.\n\nOn a 14.4 box with SMAP off, satisfying that constraint is trivial. Stage fake structures in user memory at known addresses, point `r12` at a fake `proc`, point `proc->p_sysent` at a fake `sysentvec`, set `sv_set_syscall_retval` (offset `0xc8`) to a userspace shellcode page that reads `gs:[0]` for the real curthread, walks to `td_ucred`, and zeroes `cr_uid`, `cr_ruid`, `cr_svuid`. Single syscall from uid 1000 to uid 0. `exp2_lpe_no_smap.c` in the published drop is forty lines of structure setup around a forty-byte shellcode.\n\nProduction boxes run with SMAP and SMEP on. The same `r12 → rcx → call [rcx+0xc8]` primitive still works; every dereferenced address now has to lie inside kernel memory the attacker has already written to. Frasunek's path to that requirement uses `setproctitle(2)`, which is unprivileged. `setproctitle` allocates a 256-byte `pargs` slab in the UMA heap and copies up to 244 user-supplied bytes verbatim into the slab's `ar_args` field. The slab's kernel address is then readable to the calling process via `kinfo_proc`'s `ki_args` field, also unprivileged.\n\nThe parent process plants a fake `struct ucred` at known offsets within its own pargs slab: `cr_uid=0`, `cr_prison=&prison0`, `cr_groups=&prison0` (so `cr_groups[0]` reads `pr_id == 0 == wheel` without a NULL dereference), `cr_ref=0x7fffffff` to defeat `crfree()`, plus a function pointer at offset `0xc7`. A child process plants a single qword, `P_base - 1`, at offset `0xd0` of its own pargs slab. The child triggers the overflow with `r12 = C_base + 0xd0 - 0x3f8`. The chain primitive reads `[r12+0x3f8] = K1 = P_base - 1` and calls `[K1+0xc8] = *[P_base + 0xc7]`, which the parent populated with the address of `ZSTD_initCStream_advanced` in `zfs.ko`.\n\n`ZSTD_initCStream_advanced`'s prologue contains the gadget by accident:\n\n```\nlea rdx, [rcx + 1] ; rdx = K1 + 1 = P_base\ncmovne rax, rdx ; rax = P_base\nmov qword ptr [rdi + 0x180], rax ; td->td_ucred = P_base\n```\n\nAfter the call returns, the calling thread's effective credential is the fake `ucred` the parent staged in its own pargs slab. Every subsequent privilege check on this thread reads `cr_uid=0`. The exploit does not call `setuid(0)` because the fake `cr_uidinfo` is NULL and `uifind()` would panic; it `chmod`s a setuid-root wrapper onto disk and `execve`s out of the corrupted thread before the scheduler reaches it.\n\nThe `ZSTD_initCStream_advanced` address is not baked in. The exploit resolves it at startup via the unprivileged `kldsym(2)` / `kldnext(2)` interface, skipping `fileid=1` (the kernel image, whose own ZSTD library has incompatible offsets) and matching the symbol in a loaded module. `prison0` resolves the same way. The chain requires no kernel info-leak. FreeBSD has no kernel ASLR; the kernel base is fixed by the linker script. The two kernel symbols the exploit needs are exposed to unprivileged callers by design.\n\nThe portable binary works against every 14.4 patch level with `zfs.ko` loaded. ZFS is loaded on every FreeBSD installation with a ZFS root pool, which is the FreeBSD installer's default for production servers and is universal across the hosting providers that ship FreeBSD images.\n\n## The fix landed in main as a refactor side effect\n\nThe same author who introduced the bug removed it. Olivier Certner committed `kern_setcred_copyin_supp_groups()` on December 16, 2024 in `ddb3eb4efe55` (\"New setcred() system call and associated MAC hooks\"). On November 27, 2025, three hundred and forty-six days later, Certner committed `000d5b52c19f`, titled:\n\n```\nsetcred(2): Fix a panic on too many groups from latest commit\n```\n\nThe diff replaces `kern_setcred_copyin_supp_groups()` with a renamed `user_setcred_copyin_supp_groups()`, removes the `preallocated_groups` machinery the double-pointer existed to support, changes the `groups` argument from `gid_t **` to `gid_t *`, and as a consequence rewrites both `sizeof(*groups)` expressions as `sizeof(gid_t)`. The commit message names a panic the author observed. It does not name what made the panic possible: that the unprivileged caller chooses how many bytes get copied and what those bytes contain, into a fixed-size buffer on a kernel stack frame, before any check that the caller is allowed to be calling.\n\nThe refactor sat in main. main is the development branch. The branches users install are stable/14, releng/14.4, releng/14.3, and the 15.0 series. The fix was not backported to any of them. No advisory was filed. No EN. No SA. The CVE database knew nothing about this code path until May 21, 2026, when CVE-2026-45250 was assigned.\n\nOne hundred and sixty-seven days after the November commit, on May 13, 2026, Frasunek emailed `secteam@freebsd.org` with the DoS PoC and a description of the overflow. secteam replied the same day. The reply is one of the artifacts of this case the genre asks the prosecution to read into the record:\n\n> at first glance, it appears to be a duplicate issue that we are already working on\n\nThe \"duplicate issue\" secteam was \"already working on\" had been committed to main, in its corrected form, for one hundred and sixty-seven days. The corrected code was visible to any reader of `freebsd-src` on GitHub. The released branches were not corrected. The advisory FreeBSD-SA-26:18.setcred did not exist yet; it would be cut on May 21, the same day Frasunek went public, with backports landing on releng/14.4-p5 and releng/14.3-p14 the day before.\n\n## The pattern: the CVE covers four branches, the patch covered one\n\nThis is the [backport-gap](/patterns/backport-gap) pattern. Apache MINA's [CVE-2026-42779](/posts/mina-fix-shipped-on-one-branch) is the canonical exhibit. 2.0.28 carried the bypass fix from a commit dated the day before; 2.1.11 and 2.2.6 shipped from coordinated maintenance branches on the same day without it. The CVE record applied to all three. The patch applied to one. The gap closed five days later when \"Added a missing fix\" landed on the other two branches.\n\nFreeBSD's gap is the same shape with two amplifications. The fixed branch is main, which essentially nobody runs in production. The unfixed branches are every release the project ships to administrators. And the gap is not five days; it is one hundred and sixty-seven days from commit on main to the disclosure-day backport on releng/14.4, plus another year and a half of releng/14.3 maintenance. During that window, the fix existed in the public source tree as a refactor titled \"Fix a panic.\" A reader who diffed `sys/kern/kern_prot.c` between main and releng/14.4 would have found the type still spelled `gid_t **` in releng and the `copyin` still spelling its third argument `sc_supp_groups_nb * sizeof(*groups)`. The pre-disclosure window for an attacker reading public commits to find unbackported security fixes was one hundred and sixty-seven days wide. The commit that produced the window is titled in a way that does not invite scrutiny.\n\nThe pattern's mechanism clause talks about \"a coordinated multi-branch release\" shipping the fix on one branch. FreeBSD's case is the variant where there was no coordinated release. The fix was committed to main, characterized as a panic fix, and left there. The mechanism that produces the gap is the same: a project that maintains multiple parallel release branches has to decide, at every fix, which branches the fix touches. When the decision is \"main only\" and the bug is reachable on stable, the fix's existence in main is a publication of the vulnerability against stable. The longer the fix sits in one branch and not the others, the wider the disclosure window the project has authored against itself.\n\nThe pattern's playbook clause for backport-gap is operational on both sides. For defenders, diff your installed branch against the same project's upstream development branch for files under `sys/kern/`, `kernel/`, `src/main/`, or whatever your project's name is for the directory where security-relevant code lives. Anything fixed upstream and not fixed in your branch is a window you are inside. For maintainers, every commit to a development branch in a security-relevant path should answer the question \"does this need a backport\" out loud, in the commit message, so that the release-engineering pass that picks fixes for the next point release can read the answer instead of inferring it.\n\nThe setcred(2) bug had a one-line answer in November 2025. The commit did not write it down. The wrapper at `/tmp/rsh` that `exp_setcred_smap_zfs.c` installs on every FreeBSD 14.4 server running ZFS, between November 27, 2025 and May 21, 2026, is the consequence of the line not getting written.\n\nPoC: [venglin/setcred](https://github.com/venglin/setcred). Writeup: [fatgid.io](https://fatgid.io). Advisory: FreeBSD-SA-26:18.setcred.","closing_line":"The fix landed in main on November 27. It did not land on releng/14.4 until May 20, one day before the CVE went public. The CVE record covers both branches.","hook_md":"On November 27, 2025, Olivier Certner committed `000d5b52c19f` to FreeBSD's main branch with the message \"setcred(2): Fix a panic on too many groups from latest commit.\" The diff changed one argument's type from `gid_t **` to `gid_t *` and replaced two instances of `sizeof(*groups)` with `sizeof(gid_t)`. The commit did not say \"security.\" It did not request a backport. One hundred and sixty-seven days later, every FreeBSD 14.4 administrator running ZFS was running a 60-byte kernel stack overflow reachable from any local shell, single-syscall to uid=0. When Przemyslaw Frasunek emailed `secteam@freebsd.org` to report it, secteam replied the same day: \"at first glance, it appears to be a duplicate issue that we are already working on.\" The duplicate they were already working on had been sitting in main, fixed, since November. The CVE record, CVE-2026-45250, would not be assigned for another eight days.","post_id":433,"slug":"freebsd-setcred-fix-in-main-since-november","title":"CVE-2026-45250: FreeBSD's setcred(2) Fix Has Been in main Since November. releng/14.4 Shipped the Bug for 167 More Days.","type":"initial","unreadable_sentence":"The duplicate they were already working on had been sitting in main, fixed, since November."} -----BEGIN PGP SIGNATURE----- iHUEARYIAB0WIQRf0htP5+SjynlxywneZjl4jgkQJgUCamOlKQAKCRDeZjl4jgkQ JlAzAP9od+zmS45eoejGohkXFc5HQI/cqxynZjkxqCozR3gu0gD/SXYvbVJ7flNh 2ut1vURIikp8Jo4fX5qdFFlKTCKUPA0= =1+Vc -----END PGP SIGNATURE-----