A Race Within a Race: Exploiting CVE-2025-38617 in Linux Packet Sockets
A use-after-free race in the Linux packet socket subsystem lets an unprivileged local attacker who can obtain CAP_NET_RAW re-hook a socket while its ring buffer is being freed, then access the freed ring buffer. The write-up describes chaining this into arbitrary kernel page read/write and privilege escalation with container escape.
blog.calif.io
Published on blog.calif.io
CVE-2025-38617 is a use-after-free vulnerability in the Linux kernel’s packet socket subsystem, caused by a race condition between packetsetring() and packetnotifier(). The bug has existed since Linux 2.6.12 (2005) and was fixed in kernel version 6.16.
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 protocol number is only zeroed when the socket was already running, so a socket that was not running keeps a non-zero value and the interface-up handler re-registers the hook while the ring buffer is being swapped.
Impact
An unprivileged local attacker with CAP_NET_RAW via user namespaces could achieve full privilege escalation and container escape, though the exploit targets a specific hardened kernel build.
What the attacker needed
Local access to the machine; CAP_NET_RAW via user namespaces; ability to bring an interface up and down
The fix
The bug was fixed in kernel 6.16 with a two-line change.
How it was found
- Bind the packet socket to an interface that is down so it is not running.
- Call packet_set_ring() to free the existing receive ring buffer.
- After the bind lock is released but before the ring lock is taken, bring the interface up so the notifier re-registers the hook.
- Send a packet to the interface so the receive path reads the stale ring buffer metadata.
- Let packet_set_ring() free the old ring buffer, leaving the receive path with a dangling pointer.
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 packet socket is a way for programs to read raw network traffic. The kernel keeps a shared memory buffer for it, and when the buffer is being replaced the socket is supposed to be temporarily disconnected from the network card. A timing mistake means the socket can be reconnected during that swap, so the kernel later writes into memory it has already given back, which an attacker can turn into control of the machine.
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.