-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256 NEFARIOUSPLAN-CANONICAL-V1 {"body_md":"## The patch is parentheses\n\nThe function is `exec_args_adjust_args` in `sys/kern/kern_exec.c`. It is called during `execve()` of a shebang script to splice the interpreter path into the argument buffer. The body, with the bug intact:\n\n```c\nint\nexec_args_adjust_args(struct image_args *args, size_t consume, ssize_t extend)\n{\n ssize_t offset;\n\n KASSERT(args->endp != NULL, (\"endp not initialized\"));\n KASSERT(args->begin_argv != NULL, (\"begin_argp not initialized\"));\n\n offset = extend - consume;\n if (args->stringspace < offset)\n return (E2BIG);\n memmove(args->begin_argv + extend, args->begin_argv + consume,\n args->endp - args->begin_argv + consume); /* BUG */\n ...\n}\n```\n\nThe third argument to `memmove` is the copy size. The expression is read by the C compiler left to right at the same precedence level, so it evaluates as `(args->endp - args->begin_argv) + consume`. The correct grouping, the one the patch ships:\n\n```diff\n- args->endp - args->begin_argv + consume);\n+ args->endp - (args->begin_argv + consume));\n```\n\nThe same three operands, one set of parentheses. The original arithmetic overshoots by `2 * consume`. With `consume` equal to the length of the caller's `argv[0]`, an unprivileged process that hands the kernel a 265,186-byte `argv[0]` produces a 530,376-byte `memmove` into a 528,384-byte destination buffer. The overflow is 2,024 bytes.\n\nThe bug shipped in late 2013 alongside `imgact_binmisc`. It has been wrong for thirteen years.\n\n## Two callers, one of them passes zero\n\n`exec_args_adjust_args` has exactly two callers in the FreeBSD tree. One is `imgact_binmisc.c`, the miscellaneous binary image activator that runs Linux ELFs and other foreign formats. It invokes the function to prepend a registered interpreter:\n\n```c\n/* sys/kern/imgact_binmisc.c */\nerror = exec_args_adjust_args(imgp->args, 0, offset);\n```\n\n`consume` is 0. The buggy arithmetic, `endp - begin_argv + 0`, equals the correct arithmetic, `endp - begin_argv - 0`. Operator precedence does not matter when one operand is zero. The `imgact_binmisc` path has never been wrong.\n\nThe other caller is `imgact_shell.c`, the activator for `#!`-prefixed shell scripts:\n\n```c\n/* sys/kern/imgact_shell.c, exec_shell_imgact */\nerror = exec_args_adjust_args(imgp->args, length, offset);\n```\n\n`length` is the length of the caller's original `argv[0]`, the string the user passed to `execve` in the first slot. The shebang path is the only path that ever calls `exec_args_adjust_args` with a non-zero `consume`. Every shebang exec on every FreeBSD release since 2013 has been computing the wrong `memmove` size. The bug fired silently on every one.\n\nIt did not weaponize because normal shebang execs put a 15-byte script path in `argv[0]`, the overflow comes out negative, and the `memmove` does nothing. The bug requires a caller who deliberately hands the kernel a 265-kilobyte `argv[0]`. Nothing legitimate does that. babyshen's PoC does.\n\n## The 2,024 bytes the trigger did not write\n\nThe OOB write is the interesting part. Walk the arithmetic at the byte level.\n\nA 4-CPU box gets `8 * 4 = 32` exec_map entries, each 528,384 bytes, preallocated as one contiguous slab of kernel virtual address space with no guard pages between entries. Call them entry 0 through entry 31. The trigger process occupies entry K. The entry that lives immediately after K in the slab is K+1.\n\nAfter `exec_copyin_args` finishes, entry K holds:\n\n```\nbase_K + 0: \"/tmp/e21.sh\\0\" fname, 12 bytes (fname_len = 12)\nbase_K + 12: <- begin_argv\nbase_K + 12: \"AAAA...AAAA\\0\" argv[0], 265,186 bytes (= consume)\nbase_K + 265,198: \"T=1\\0\" env[0], 4 bytes\nbase_K + 265,202: <- endp\n```\n\nThe buggy `memmove` computes:\n\n```\ndst = begin_argv + extend = base_K + 12 + 20 = base_K + 32\nsrc = begin_argv + consume = base_K + 12 + 265,186 = base_K + 265,198\nsize = endp - begin_argv + consume = 265,190 + 265,186 = 530,376\n```\n\nThe destination range is `[base_K + 32, base_K + 530,408)`. Entry K ends at `base_K + 528,384`. The last 2,024 bytes of the write land in entry K+1 at offsets `[0, 2024)`.\n\nNow the source range. The 2,024 bytes that land in K+1 correspond to copy indices `i` in `[528,352, 530,376)`. Each index reads from `src + i = base_K + 265,198 + i`:\n\n```\ni = 528,352: source = base_K + 793,550 = base_K + 528,384 + 265,166 = K+1 offset 265,166\ni = 530,375: source = base_K + 795,573 = base_K + 528,384 + 267,189 = K+1 offset 267,189\n```\n\nThe overflow's *source* is also in entry K+1, at offsets 265,166 through 267,189. The `memmove` is a self-copy of K+1's tail onto K+1's head:\n\n```\nK+1 effect: K+1[0 .. 2024) <- K+1[265166 .. 267190)\n```\n\nThis is the part that does not match the official description. The trigger process's `argv[0]` lives in entry K, not entry K+1. The trigger's argv buffer never reaches offsets > 265,202 inside entry K, never mind 265,166 inside entry K+1. The bytes the kernel copies into K+1's head are not bytes the trigger process wrote. They are bytes that some prior caller of the pool left in K+1's tail.\n\n## The pool keeps the bytes\n\n`exec_args_alloc` returns an entry from one of two structures: a per-CPU `DPCPU` cache (one entry per CPU, swapped via `atomic_swap`) and a global SLIST freelist (LIFO). When the exec finishes, `exec_args_free` returns the entry to the same structure. Look at `kern_exec.c` for the return path. There is no `bzero`. There is no `explicit_bzero`. The pool does not erase entries on release. The next caller of `exec_args_alloc` who gets that entry sees whatever the previous caller wrote into it.\n\nThis is intentional. The pool exists to spare `execve` the cost of `pmap_enter`ing and `pmap_remove`ing 528 kilobytes of KVA on every exec, and zeroing the buffer would erase the saved cost. The contract that protects callers from each other's leftover bytes is that `exec_copyin_args` always begins writing at offset 0 and writes only the bytes it received from userspace, and `exec_copyout_strings` always reads from offset 0 forward to `endp`. As long as both functions stay below `endp - base_K`, anything past that watermark is private.\n\nThe watermark is small. For sshd-session, the kernel writes:\n\n```\nfname: \"/usr/libexec/sshd-session\\0\" 26 bytes\nargv[0]: \"/usr/libexec/sshd-session\\0\" 26 bytes\nargv[1]: \"-R\\0\" 3 bytes\nenv: LISTENERS_IPV4=..., a handful ~100 bytes\n```\n\nRoughly 155 bytes. The other 528,229 bytes of the entry are whatever the prior caller left. An unprivileged user on the same machine who runs an exec that writes attacker-chosen bytes at offset 265,166, then releases the entry, has installed a payload that the next caller of the same entry will inherit silently. sshd-session inherits it the next time it gets that entry. Its own writes never reach 265,166, so the payload is intact when the buggy `memmove` reads it.\n\nbabyshen's exploit installs the payload by `execve`ing `/usr/bin/true` with a crafted `envp` whose layout, after `exec_copyin_args` packs it into the entry, places `LD_PRELOAD=/tmp/evil.so` at offset 265,166 + 57. Because the pool keeps the bytes, this preseed survives sshd-session's reuse of the entry, the buggy `memmove`'s self-copy, and the runtime linker's exec finalize. The 2,024 bytes that land at `K+1[0..2024)` are the preseed payload, reformatted as sshd-session's `fname`, `argv`, and `envp` from the kernel's point of view.\n\nThe trigger exec does not write those bytes. The kernel does, from a recording the pool kept of an earlier unprivileged user's write.\n\n## issetugid returns zero\n\nThe cross-process write into sshd-session's exec buffer is only a privilege escalation if sshd-session honors something an unprivileged user can plant. It does, because the runtime linker on FreeBSD honors `LD_PRELOAD` whenever `issetugid()` returns 0, regardless of what the effective UID is. `issetugid()` returns 0 when real UID, effective UID, real GID, and effective GID are unchanged from the parent across the exec.\n\nsshd's master process runs as root. When a TCP connection lands on port 22, the master forks and calls `execv(\"/usr/libexec/sshd-session\", ...)`. `execv`, not `execve`, because sshd-session is supposed to inherit the master's environment. Both parent and child are uid 0, euid 0, gid 0, egid 0. No setuid transition occurs. `issetugid()` returns 0 in the child. The runtime linker honors `LD_PRELOAD=/tmp/evil.so`. Its constructor runs as uid 0 before sshd-session's `main()`. babyshen's `evil.so` constructor does the only thing that matters:\n\n```c\nint s = open(\"/bin/sh\", O_RDONLY);\nint d = open(\"/tmp/rootsh\", O_WRONLY|O_CREAT|O_TRUNC, 0755);\n/* copy /bin/sh into /tmp/rootsh */\nchown(\"/tmp/rootsh\", 0, 0);\nchmod(\"/tmp/rootsh\", 04755);\n```\n\nA suid root shell at `/tmp/rootsh`. The unprivileged user runs `/tmp/rootsh -p` and is root.\n\nThis is not a sshd bug. sshd is doing exactly what sshd has been designed to do since 1999. `execv` of sshd-session, with its environment inherited, is documented behavior. `issetugid` returning 0 for a process whose UIDs all match its parent's is exactly what the syscall is specified to do. The runtime linker honoring `LD_PRELOAD` when `issetugid` is 0 is the documented contract. None of those decisions is a bug. They compose into one because the kernel let an unprivileged user write into a root process's exec buffer.\n\n## The fix is one commit. The exploit is four orthogonal designs.\n\nThe FreeBSD patch is one set of parentheses in `kern_exec.c`. The exploitability of the typo, the part that decides whether the bug is a 530-kilobyte self-DoS or a local root, is decided by four other choices, none of which the patch changes:\n\n1. The `exec_map` pool returns entries to the freelist without erasing them. This is the **pool-retains-prior-writes** decision: every unprivileged user's exec leaves a recording in the entry past the kernel's normal write watermark, available to whichever process gets the entry next.\n2. The `exec_map` pool's entries are laid out as a contiguous KVA slab with no guard pages between them. A 2,024-byte OOB walks into the next entry instead of into an unmapped page that would page-fault and panic. The PoC's authors note this explicitly: P(entry 31, the last) = 1/32, which is the only configuration where the OOB panics. Every other K is silent corruption.\n3. sshd calls `execv`, not `execve`, when launching sshd-session, so the child inherits the environment the OOB just rewrote.\n4. The FreeBSD runtime linker honors `LD_PRELOAD` whenever `issetugid() == 0`, independent of effective UID. A root-to-root exec qualifies.\n\nThis is the shape **emergent-primitive** describes. The kernel's exec-pool team owns choices 1 and 2. The OpenSSH project owns choice 3. The FreeBSD runtime linker maintainers own choice 4. The arithmetic bug is in `exec_args_adjust_args`, and that is the patch. The primitive that converts the arithmetic bug into local root is the composition of four decisions made independently across two codebases over thirty years. The disclosure pipeline knows how to file a CVE against `kern_exec.c`. It does not know how to file a CVE against the intersection.\n\n## Thirteen years\n\nThe git blame on `exec_args_adjust_args` is unchanged since the function was first written. The arithmetic has been wrong on every FreeBSD release since 11.0. The shebang execs that fire it have run hundreds of millions of times across the install base. None of them noticed, because none of them used a 265-kilobyte `argv[0]`, because nothing legitimate does. The kernel's pool absorbed the wrong write every time, silently, into the next entry of an identical buffer, with no fault and no log.\n\nThe thing that makes this CVE interesting is not the typo. The thing that makes it interesting is that the typo could survive for thirteen years inside a kernel data structure that was designed to make the typo invisible. The pool's no-zero policy is a performance optimization that, in the presence of any bounded write that overruns one entry into another, becomes a persistent cross-process staging area. The contract between callers is documentation. The kernel does not enforce it. babyshen wrote 521 lines of C that demonstrate what the absence of enforcement is worth.\n\nPoC: [babyshen/freebsd-CVE-2026-7270](https://github.com/babyshen/freebsd-CVE-2026-7270)","closing_line":"The patch is parentheses. The exploit is the pool.","hook_md":"The FreeBSD administrator who runs a multi-user shell host, a university lab, a build farm, a hosting VPS with more than one Unix account, has been sitting on a local-root path since 2013. The bug is one character. A `+` where there should be a `-`, in the third argument of a `memmove` in `sys/kern/kern_exec.c`. The FreeBSD Project shipped that line on every release from 11.0 through 14.4-RELEASE-p1, the version current at disclosure, with no fix in `main`, `stable/14`, `stable/13`, or `releng/14.4`. The reason CVE-2026-7270 took thirteen years to weaponize is not the typo. The reason is the exec_map pool, which keeps an unprivileged user's earlier writes across the boundary between processes and replays them into a root exec.","post_id":359,"slug":"freebsd-cve-2026-7270-exec-pool-staged-the-payload","title":"CVE-2026-7270: FreeBSD's Exec Pool Staged the Payload","type":"initial","unreadable_sentence":"The 2,024 bytes that wrote LD_PRELOAD into a root process were not supplied by the trigger exec. They were left in the pool by an earlier unprivileged process, and the kernel copied them into place."} -----BEGIN PGP SIGNATURE----- iHUEARYIAB0WIQRf0htP5+SjynlxywneZjl4jgkQJgUCavyXxgAKCRDeZjl4jgkQ Jle3AQD5Bks0O63bnZSPMPuIHpDWzLm3f36YPO6g/6C7Sn6MBwEA5Z3FilXVcJ35 Q1Fm74YvelFRJFyGIGVoEEp9FN5P1Qg= =sDjG -----END PGP SIGNATURE-----