Linux Kernel Exploitation: Attack of the Vsock
A reference count mishandling in the Linux kernel's vsock implementation allowed a freed socket object to remain in the bind table, leading to a use-after-free. An attacker could exploit this to escalate privileges to root.
hoefler.dev
Published on hoefler.dev
While browsing the public spreadsheet of submissions, I saw an interesting entry: exp237. The bug patch seemed incredibly simple, and I was amazed that a researcher was able to leverage the issue for privilege escalation.
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 vsock_remove_sock function incorrectly decremented the reference count of an unbound socket during transport reassignment, causing premature free while the socket remained in the bind table.
Impact
An attacker could exploit the use-after-free to achieve kernel code execution and escalate privileges to root, though the exploit required bypassing AppArmor and defeating KASLR.
What the attacker needed
Local access to the system; kernel with vsock support; AppArmor enabled (bypass required)
The fix
The bug was fixed by ensuring that vsock_remove_bound is only called if the socket is marked as dead, preventing incorrect reference count decrements.
How it was found
- Create a vsock socket and bind it to a local port.
- Create multiple sockets bound to consecutive ports.
- Close the first socket and create a new socket.
- Attempt to connect the new socket to the first port, which fails but sets a transport.
- Attempt to connect to a non-existent CID, which fails and unsets the transport, dropping the reference count.
- Bind the socket again, which may trigger a crash or use-after-free.
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 frees memory but keeps using it, letting an attacker control what goes there. Here, a bug in the kernel's vsock networking code freed a socket object but left it in a list, so an attacker could reclaim that memory and trick the kernel into running their code with 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.