Big Fish: Exploiting a 37-Year-Old Kernel Bug in OpenBSD
A signed 16-bit shared memory attachment counter in OpenBSD could be overflowed by repeatedly forking processes, wrapping to a negative value. Combined with a separate out-of-bounds write, this allowed a local attacker to escalate privileges to root.
calif.io
Published on calif.io
openbsdmadbugspatch-the-planet
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the shared memory attachment counter was a signed 16-bit short that could overflow, and a separate out-of-bounds write in the kernel allowed memory corruption.
What the attacker needed
Local access to the system; ability to fork many processes
How it was found
- Map 127 SysV shared memory segments, unmap them, and fork 259 processes to wrap the attach count to a negative value.
- Perform heap grooming using sysctl metrics to track allocations.
- Win a race condition using IPC_RMID while attaching a new size-confused shared memory segment.
- Align IP socket allocations and set IP_MULTICAST_TTL to allocate a persistent struct ip_moptions.
- Trigger a conditional out-of-bounds write to overwrite membership counters.
- Close the socket to trigger atomic decrements that modify the PTE mapping, achieving kernel code execution.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
A counter that tracks how many processes are attached to a shared memory segment was stored in a small signed number, so it could overflow and become negative. Separately, a kernel bug allowed writing one value out of bounds. Together, a local user could corrupt kernel memory and gain root privileges.
What is Memory corruption?
Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.