Exploiting CVE-2022-42703 Bringing back the stack attack
A use-after-free in the Linux kernel's memory management allows an attacker to corrupt a saved register on a non-randomised exception stack, causing an over-copy that leaks the stack cookie and KASLR slide, then a stack buffer overflow that can lead to kernel code execution.
googleprojectzero.blogspot.com
Published on googleprojectzero.blogspot.com
This blog post details an exploit for CVE-2022-42703 (P0 issue 2351 - Fixed 5 September 2022), a bug Jann Horn found in the Linux kernel's memory management (MM) subsystem that leads to a use-after-free on struct anonvma. As the bug is very complex (I certainly struggle to understand it!), a future blog post will…
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 a use-after-free in the kernel's anon_vma handling, where a freed anon_vma is reclaimed with attacker-controlled data, allowing a down_read_trylock() call to write to an attacker-chosen address.
Impact
A local attacker could achieve kernel code execution on x86 Linux, and the prefetch side channel defeats KASLR and CPU entry area randomisation on modern CPUs where kPTI is disabled.
What the attacker needed
Local access to the system; ability to trigger the use-after-free; x86-64 Linux kernel
The fix
The bug was fixed on 5 September 2022, and the author suggests randomising the percpu cpu_entry_area and performing in-stack randomisation to make exploitation harder.
How it was found
- Fork a process Y from process X.
- Process X ptraces process Y, then sets a hardware breakpoint at a known virtual address in process Y.
- Process Y makes a large number of calls to uname(2), which calls copy_to_user from a kernel stack buffer to that address, triggering the DB exception handler.
- Simultaneously make many arbitrary writes at the known location of the DB exception stack's saved rcx value, which is Process Y's copy_to_user's saved length.
- After corrupting the length, the kernel copies much of the task's stack back to userland, leaking the stack cookie and return addresses.
- Invert the technique to attack a copy_from_user call (prctl(2)) to generate a stack buffer overflow and overwrite the return address.
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 use-after-free happens when a program keeps using memory after it has been freed. Here, the kernel's memory manager frees a structure but later reads a pointer from it, and the attacker can fill that freed memory with their own data. By making the kernel write to a chosen address, the attacker can change a saved value on a special stack that has a fixed address, which then makes the kernel copy too much data and leak secrets or overwrite a return address.
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.