CVE-2020-8835: Linux kernel privilege escalation via improper eBPF verification
The Linux kernel's eBPF verifier made an unjustified assumption when narrowing the known bits of a register after a 32-bit conditional jump, so a crafted program could make the verifier believe a register was zero when it actually held one. Combined with weak runtime ALU sanitation limits, this gave an unprivileged local user out-of-bounds read and write in kernel memory, leading to root.
thezdi.com
Published on thezdi.com
This blog explains the technical details of an exploit using the Linux eBPF feature to achieve local privilege escalation. Due to the nature of the bug(s), which are rather subtle misbehaviors of a safety-critical feature called the “verifier”, some explanations about the inner workings of eBPF need to be provided…
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 verifier's 32-bit jump handling derived known bits for the low half of a register from the unsigned minimum and maximum alone, ignoring values in between, and ALU sanitation set per-operation limits that were safe individually but not in combination.
Impact
An unprivileged local user could gain out-of-bounds read and write in kernel memory and escalate to root; the text notes that in a container the attacker would first need to locate the relevant namespace.
What the attacker needed
Local unprivileged user account; ability to load eBPF programs via a socket
The fix
It was fixed by a kernel patch released on 30 March 2020.
How it was found
- Load a value from a map so the verifier knows nothing about the register.
- Use conditional jumps to set the register's unsigned minimum to 1 and maximum to 2^32+1.
- Execute a 32-bit conditional jump on the register to make the verifier mark the low bits as known.
- Apply an AND and a right shift so the verifier believes the register is 0 while it is really 1.
- Multiply that register to fabricate offsets and add or subtract them from a map pointer, passing each runtime limit check.
- Use the resulting out-of-bounds read and write to leak kernel addresses and overwrite structures for root.
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.
eBPF lets ordinary users hand small programs to the Linux kernel, which runs them for speed after a checker called the verifier proves they cannot touch memory they should not. The verifier here reasoned incorrectly about the possible values in a register, so a program it approved could reach outside its own memory. Because that memory sits in the kernel, a normal user could then read and change kernel data and become root.
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.