CVE-2022-22265 Samsung npu driver
A double-free in the Samsung NPU driver's format and stream-off ioctls lets a local attacker free the same kernel buffer twice. The author turns this into a use-after-free, cross-cache and page-table attack to gain physical read/write, disable SELinux and inject code into a root process.
soez.github.io
Published on soez.github.io
I wanted to exploit a bug in Samsung-based Android and I chose this CVE from a Google Project Zero report: https://googleprojectzero.github.io/0days-in-the-wild//0day-RCAs/2022/CVE-2022-22265.html. It is well explained, once you read it, you’ll notice that it involves a double free vulnerability.
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 format ioctl frees the queue's format array on an invalid format but leaves the pointer and state set, so the stream-off cleanup frees it a second time.
Impact
A local attacker could escalate to kernel-level physical read/write, disable SELinux and inject code into the init process to get a root shell, though the driver is restricted to the shell SELinux context and the tested firmware had the bug patched.
What the attacker needed
Shell SELinux context access; modified firmware interface code; Samsung device with vulnerable NPU driver
The fix
The text does not describe the patch, but the double free should be fixed by clearing the format pointer and state after the first free so cleanup cannot free it again.
How it was found
- Send the graph ioctl, then a format ioctl to set the format state on the input queue.
- Send the graph ioctl again, then a format ioctl with an invalid format to trigger the first free.
- Send the graph ioctl to set the graph state, then a format ioctl on the output queue to set the format state.
- Send the stream-on ioctl to set the stream-on state.
- Send the stream-off ioctl to trigger the second free of the input queue buffer.
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 driver keeps a small block of kernel memory for a video queue. When you send a bad format it frees that block, but it forgets to clear the pointer, so a later cleanup command frees the same block again. An attacker who can talk to the driver can then reuse that freed memory for their own purposes and eventually take over the device.
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.