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.
CVE-2026-7270: FreeBSD's Exec Pool Staged the Payload
vendor
patterns
cve
proof of concept
The patch is parentheses
The 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:
int
exec_args_adjust_args(struct image_args *args, size_t consume, ssize_t extend)
{
ssize_t offset;
KASSERT(args->endp != NULL, ("endp not initialized"));
KASSERT(args->begin_argv != NULL, ("begin_argp not initialized"));
offset = extend - consume;
if (args->stringspace < offset)
return (E2BIG);
memmove(args->begin_argv + extend, args->begin_argv + consume,
args->endp - args->begin_argv + consume); /* BUG */
...
}The 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:
- args->endp - args->begin_argv + consume);
+ args->endp - (args->begin_argv + consume));The 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.
The bug shipped in late 2013 alongside imgact_binmisc. It has been wrong for thirteen years.
Two callers, one of them passes zero
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:
/* sys/kern/imgact_binmisc.c */
error = exec_args_adjust_args(imgp->args, 0, offset);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.
The other caller is imgact_shell.c, the activator for #!-prefixed shell scripts:
/* sys/kern/imgact_shell.c, exec_shell_imgact */
error = exec_args_adjust_args(imgp->args, length, offset);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.
It 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.
The 2,024 bytes the trigger did not write
The OOB write is the interesting part. Walk the arithmetic at the byte level.
A 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.
After exec_copyin_args finishes, entry K holds:
base_K + 0: "/tmp/e21.sh\0" fname, 12 bytes (fname_len = 12)
base_K + 12: <- begin_argv
base_K + 12: "AAAA...AAAA\0" argv[0], 265,186 bytes (= consume)
base_K + 265,198: "T=1\0" env[0], 4 bytes
base_K + 265,202: <- endpThe buggy memmove computes:
dst = begin_argv + extend = base_K + 12 + 20 = base_K + 32
src = begin_argv + consume = base_K + 12 + 265,186 = base_K + 265,198
size = endp - begin_argv + consume = 265,190 + 265,186 = 530,376The 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).
Now 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:
i = 528,352: source = base_K + 793,550 = base_K + 528,384 + 265,166 = K+1 offset 265,166
i = 530,375: source = base_K + 795,573 = base_K + 528,384 + 267,189 = K+1 offset 267,189The 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:
K+1 effect: K+1[0 .. 2024) <- K+1[265166 .. 267190)This 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.
The pool keeps the bytes
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.
This is intentional. The pool exists to spare execve the cost of pmap_entering and pmap_removeing 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.
The watermark is small. For sshd-session, the kernel writes:
fname: "/usr/libexec/sshd-session\0" 26 bytes
argv[0]: "/usr/libexec/sshd-session\0" 26 bytes
argv[1]: "-R\0" 3 bytes
env: LISTENERS_IPV4=..., a handful ~100 bytesRoughly 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.
babyshen's exploit installs the payload by execveing /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.
The trigger exec does not write those bytes. The kernel does, from a recording the pool kept of an earlier unprivileged user's write.
issetugid returns zero
The 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.
sshd'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:
int s = open("/bin/sh", O_RDONLY);
int d = open("/tmp/rootsh", O_WRONLY|O_CREAT|O_TRUNC, 0755);
/* copy /bin/sh into /tmp/rootsh */
chown("/tmp/rootsh", 0, 0);
chmod("/tmp/rootsh", 04755);A suid root shell at /tmp/rootsh. The unprivileged user runs /tmp/rootsh -p and is root.
This 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.
The fix is one commit. The exploit is four orthogonal designs.
The 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:
- The
exec_mappool 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. - The
exec_mappool'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. - sshd calls
execv, notexecve, when launching sshd-session, so the child inherits the environment the OOB just rewrote. - The FreeBSD runtime linker honors
LD_PRELOADwheneverissetugid() == 0, independent of effective UID. A root-to-root exec qualifies.
This 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.
Thirteen years
The 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.
The 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.
The patch is parentheses. The exploit is the pool.