Big Fish: Exploiting a 37-Year-Old Kernel Bug in OpenBSD | Calif
Open main menu
Home
Services
Research
The Crew
Join Us
Blog
Contact
← Research Big Fish: Exploiting a 37-Year-Old Kernel Bug in OpenBSD Big fish. Small counter. Root shell.
Andrew Griffiths October 16, 2026 openbsdmadbugs
ContentsThe exploitExploit mitigation
Calif frequently publishes our offensive research and work, but we otherwise don't draw much attention to the defensive work we do — assisting open source projects with remediation, patch generation, cryptographic improvements, and internal engineering projects we carry out for our clients. Earlier this year, we reported some vulnerabilities, often along with suggested patches to OpenBSD. One traced back roughly 37 years to the original BSD sources, where a shared memory attachment counter was defined as a signed 16-bit short. Repeatedly forking a process with shared memory attachment records could push that counter past its maximum value of 32,767, causing it to wrap to a negative value. This integer overflow could lead to a use-after-free via a race condition; combined with a separate out-of-bounds write in the kernel, it allowed local privilege escalation to root. The issues were addressed in errata 026 and 018, respectively. The exploit
We managed to get local root in OpenBSD with KARL / SMAP / SMEP enabled without the use of an information disclosure vulnerability via the following path: Map 127 SysV shared memory segments, unmap them via munmap(), and fork 259 processes to wrap the shared memory attach count to -32,643. Perform heap grooming and layout, using metrics from sysctl(KERN_MALLOCSTATS) (such as kb_total and kb_totalfree) to track allocations and determine when new pages are allocated. Win the race condition using IPC_RMID in one process while attaching a new size-confused shared memory segment in a helper process. Align IP socket allocations and set IP_MULTICAST_TTL to a non-default value of 2 to allocate a persistent 16-byte struct ip_moptions. Its final word packs two 16-bit counters: imo + 12 = imo_num_memberships | imo_max_memberships << 16. Trigger the conditional -1 out-of-bounds write to overwrite both the number of memberships and maximum memberships fields. close() the socket to traverse the group members, triggering atomic decrements that modify the PTE self-referential mapping twice, switching it from user to supervisor accessible mapping, and achieving kernel code execution by overwriting a predictable kernel pointer. Clean up shared memory accounting and restore the overwritten kernel pointer to obtain a root shell. That's the short of the matter, the longer version is more interesting, including the history of the vulnerability, as a short shm_nattch can be traced back ~37 years ago, in the original BSD sources. Taking a step back, this vulnerability ended up getting code execution via a write what where primitive, where the write was caused by a TAILQ_REMOVE, the what was our userland memory mapping that was made supervisor mode accessible to bypass SMAP/SMEP, and the where was a predictable kernel pointer location. Exploit mitigation While OpenBSD's KARL relinks the kernel binary to randomize both function and data addresses, the kernel's memory allocators remain deterministic. Both the boot-time allocator and the best-fit allocator lack base address randomization. Consequently, early boot allocations consistently land at predictable locations across boots on the same hardware. When these predictable structure allocations contain function pointers, they become ideal targets for exploitation. For instance, the exploit reliably targets the lo0 and enc0 ioctl handlers, overwriting one to gain control flow and using the other to restore the overwritten pointer. Aside from the aforementioned errata fixes, there's several other approaches that can be taken to either eliminate or reduce the likelihood of those avenues being used again. Firstly, we can implement safe-unlinking, a technique that checks doubly linked list invariants before performing the unlink memory writes. If the invariants are violated, then a suitable abort() or panic() is called, depending on if user mode or kernel mode, preventing memory corruption from occurring. An example implementation is here. FreeBSD and NetBSD have an implementation of safe-unlinking in their sys/queue.h implementation. Secondly, we can randomize the self-referential PTE map allocation address so that the targeted atomic decrement locations would not be possible. This is done by using a random byte (.openbsd.randomdata) and selecting a PML4 slot (320 + (random_byte & 127)) at boot time, and installing the recursive entry at that location. The PTE_BASE definition becomes a runtime expression, yielding bases from 0xffffa00000000000 through 0xffffdf8000000000 at 512-GiB intervals. An example implementation is here. In case randomization is not suitable, other options might suffice, such as marking the PTE as read-only, and changing CR0.WP during modification. Thirdly, the kernel allocator can be made non-deterministic using two approaches; by randomizing the base address where memory allocations occur at boot time, and additionally randomizing the allocation order at run time. The base address randomization is effectively free as the gap it creates can still be used later on; while runtime randomization does incur some overhead during allocation - it may be possible that more in-depth allocator changes could alleviate this impact. Either approach would be sufficient to break the predictable pointer location without additional vulnerabilities, be it software or hardware. Furthermore, there are existing and upcoming compiler features that can be used to mitigate against entire vulnerabilities, from array bounds sanitizer (a subset of Undefined Behaviour sanitizer) which can eliminate out of bounds fixed size array accesses. Calif has suggested to FreeBSD that the array bounds sanitizer may make a useful exploit mitigation that can be enabled in release builds, along with privately reporting 21 issues that the array bounds sanitizer would have caught; some with local privilege escalation security impact. An upcoming compiler feature that can be used to help mitigate against heap issues is Alloc Tokens, which can be used to isolate pointer containing allocations from non-pointer allocations. This isolation can make overflows from the non-pointer containing allocation much more difficult to exploit by preventing pointer access, along with making vulnerability classes like Use-after-Free unable to use the opposite type of allocation as the replacement memory allocation. Since its inception, OpenBSD has consistently championed proactive security through source code auditing, the replacement of insecure APIs, advanced password hashing, cryptography, privilege separation, sandboxing, along with memory safety via ASLR and W^X; frequently setting the standard for system and network hardening. By proactively hardening, and adapting new and existing mitigation options, we can often systematically neutralize entire classes of exploitation primitives; or at the very least, increase the attacker's cost (i.e. additional time investment, additional vulnerabilities needed to exploit an issue, find alternative avenues, etc). Investing in defensive improvements before vulnerabilities are actively targeted raises the bar for attackers, helping ensure robust protection and long-term resilience. In the age of AI-assisted vulnerability discovery, mitigating against entire vulnerability classes, combined with increasing attack complexity only becomes more critical. Code and PoC →
About Calif
We push offensive security research to its limits, understand what is becoming possible with AI, and use those insights to help our customers defend themselves.
Get in touch, and subscribe to our newsletter for more research like this:
Subscribe
Check your inbox to confirm.
Related researchCVE-2026-86950: The Great Glyph GriftSeptember 30, 2026OEMpocalypse Now: A Generic Exploitation Strategy from Android untrusted app to rootAugust 31, 2026Password FictionAugust 10, 2026
← All research
ContentsThe exploitExploit mitigation
Connect With Us
help@calif.io +1-408-868-8233 Signal: Calif.10
Services
AI Security Neocloud Security Security Engineering Due Diligence Security for the Public Good
Home
Research
The Crew
Join Us
Blog
Contact
Services
AI Security Neocloud Security Security Engineering Due Diligence Security for the Public Good
Connect with us
help@calif.io +1-408-868-8233 Signal: Calif.10
© 2026 Calif. All Rights Reserved. |
A vulnerability in the OpenBSD kernel stems from an integer overflow in a shared memory attachment counter, a flaw indirectly traceable to the original BSD sources approximately thirty-seven years ago. This vulnerability arose because the shared memory attachment counter was defined as a signed 16-bit short. Repeatedly forking a process with shared memory attachment records could cause this counter to exceed its maximum value of thirty-two thousand seven hundred sixty-seven, resulting in an integer wrap to a negative value. This integer overflow was critical because, when combined with a separate out-of-bounds write in the kernel, it facilitated a use-after-free condition dependent on a race condition. This chain of events ultimately allowed an attacker to achieve local privilege escalation to root.
The exploit pathway involved a complex sequence of operations to achieve kernel code execution while operating under security mitigations like KARL, SMAP, and SMEP. The exploit relied on manipulating shared memory segments, unmapping them, and forking processes to set the shared memory attach count to a specific negative value. Further steps included heap grooming and utilizing metrics from sysctl(KERN_MALLOCSTATS) to track memory allocations. The race condition was leveraged by interacting with IPC_RMID while attaching a size-confused shared memory segment in a helper process. The attacker also controlled IP socket allocations and set the IP_MULTICAST_TTL to a non-default value to allocate a persistent sixteen-byte structure. The final stage involved triggering a conditional out-of-bounds write to overwrite memory locations specifying the number of memberships and maximum memberships. By closing the socket, the exploit triggered atomic decrements that modified the page table entry self-referential mapping twice, switching the mapping from user-mode to supervisor-accessible, which allowed the attacker to overwrite a predictable kernel pointer and ultimately execute kernel code.
The core mechanism for code execution involved a write caused by a TAILQ_REMOVE operation, which targeted a userland memory mapping that had been made supervisor mode accessible to circumvent SMAP/SMEP, coupled with knowledge of a predictable kernel pointer location.
Defensive strategies against this class of exploitation focus heavily on eliminating the predictability of kernel memory structures. Although OpenBSD utilizes KARL to randomize kernel binary addresses, the memory allocators, both the boot-time allocator and the best-fit allocator, lack base address randomization. Consequently, early boot allocations frequently occupy predictable locations across successive boots on the same hardware, making these structures ideal targets if they contain function pointers. Specifically, the exploit reliably targets the lo0 and enc0 ioctl handlers for control flow hijacking.
Several mitigation approaches can be implemented to reduce the likelihood of such memory corruption. One approach is to implement safe-unlinking, which mandates checking doubly linked list invariants prior to performing unlink memory writes, aborting the operation if invariants are violated to prevent memory corruption. Another technique involves randomizing the self-referential Page Table Entry mapping address by selecting a random byte at boot time to establish the recursive entry location, which yields variable base addresses for PTEs. Alternatively, marking the Page Table Entry as read-only and changing CR0.WP during modification can also be employed. A third method involves making the kernel allocator non-deterministic by randomizing the base address where memory allocations occur at boot time, and additionally randomizing the allocation order at runtime, which can effectively break predictable pointer locations without introducing additional vulnerabilities.
Beyond these low-level fixes, modern compiler features offer further protection. The array bounds sanitizer, a subset of Undefined Behavior sanitizer, can eliminate out-of-bounds fixed-size array accesses. Furthermore, the upcoming Alloc Tokens feature can isolate pointer-containing allocations from non-pointer allocations, making overflows from non-pointer allocations difficult to exploit by restricting pointer access and preventing use-after-free scenarios involving conflicting allocation types. OpenBSD has historically championed proactive security through source code auditing, adopting memory safety measures like Address Space Layout Randomization and Write XOR Execute policies, consistently setting a high standard for system hardening. This proactive approach, focusing on mitigating entire classes of vulnerabilities and increasing the overall complexity for attackers through defensive improvements, enhances the long-term resilience of systems. |