CVE-2023-52447 - Exploit Technique
A BPF program can hold a reference to an array map without incrementing its refcount, allowing a race condition where another thread frees and reallocates the map. The exploit uses this to achieve out-of-bounds read/write, overwrite core_pattern, and escape the container as root.
github.com
Published on github.com
History
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 BPF verifier did not ensure that maps obtained from an array-of-maps have their reference count incremented when stored in a register, allowing use-after-free.
Impact
An attacker could escape the container and execute code as root in the root namespace.
What the attacker needed
Ability to load BPF programs; Linux kernel with vulnerable BPF
The fix
The vulnerability was fixed by ensuring that maps obtained from array-of-maps have their reference count incremented.
How it was found
- Create a BPF program that loads a map from an array-of-maps into a register without increasing its refcount.
- Use a time-consuming operation like bpf_ringbuf_output with a large buffer to widen the race window.
- In another thread, free the map and spray array-of-maps to reclaim the freed memory.
- Use the BPF program to leak kernel addresses and calculate the KASLR base.
- Modify the victim map's max_entries and index_mask to enable out-of-bounds access.
- Overwrite core_pattern to execute a payload on coredump, achieving container escape.
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.
BPF is a technology in the Linux kernel that lets programs run safely. A reference count tracks how many places use an object; if it's wrong, the object can be freed while still in use. Here, a BPF program could keep a pointer to a map without telling the kernel, so another thread could free it and replace it with a different object, leading to memory corruption and container escape.
What is Race condition?
Parallel requests reach a state the code assumed could not happen: a coupon used twice, a limit overrun, a check skipped.