Skip to contentSkip to conversation

net: fix fanout UAF in packet_release() via NETDEV_UP race

PATCH Applied Yochai Eisenrich 3 participants 3 messages Mar 19 – Mar 24

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: fix fanout UAF in packet_release() via NETDEV_UP race

packet_release() has a race window where NETDEV_UP can re-register a socket into a fanout group's arr[] array. The re-registration is not cleaned up by fanout_release(), leaving a dangling pointer in the fanout array.
packet_release() does NOT zero po->num in its bind_lock section. After releasing bind_lock, po->num is still non-zero and po->ifindex still matches the bound device. A concurrent packet_notifier(NETDEV_UP) that already found the socket in sklist can re-register the hook. For fanout sockets, this re-registration calls __fanout_link(sk, po) which adds the socket back into f->arr[] and increments f->num_members, but does NOT increment f->sk_ref.

The fix sets po->num to zero in packet_release while bind_lock is held to prevent NETDEV_UP from linking, preventing the race window.

This bug was found following an additional audit with Claude Code based on CVE-2025-38617.

Fixes ce06b03e60fc ("packet: Add helpers to register/unregister ->prot_hook")
---
 net/packet/af_packet.c | 1 +
 1 file changed, 1 insertion(+)
net/packet/af_packet.c +1 -0
index 72d0935139f0..bb2d88205e5a 100644
@@ -3135,6 +3135,7 @@ static int packet_release(struct socket *sock)
 
 	spin_lock(&po->bind_lock);
 	unregister_prot_hook(sk, false);
+	WRITE_ONCE(po->num, 0);
 	packet_cached_dev_reset(po);
 
 	if (po->prot_hook.dev) {

--
2.53.0

maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 15 lines · Yochai Eisenrich

packet_release() has a race window where NETDEV_UP can re-register a socket into a fanout group's arr[] array. The re-registration is not cleaned up by fanout_release(), leaving a dangling pointer in the fanout array.
packet_release() does NOT zero po->num in its bind_lock section. After releasing bind_lock, po->num is still non-zero and po->ifindex still matches the bound device. A concurrent packet_notifier(NETDEV_UP) that already found the socket in sklist can re-register the hook. For fanout sockets, this re-registration calls __fanout_link(sk, po) which adds the socket back into f->arr[] and increments f->num_members, but does NOT increment f->sk_ref.

The fix sets po->num to zero in packet_release while bind_lock is held to prevent NETDEV_UP from linking, preventing the race window.

Quoted 7 lines

This bug was found following an additional audit with Claude Code based on CVE-2025-38617.

Fixes ce06b03e60fc ("packet: Add helpers to register/unregister ->prot_hook")
#2 lore raw
In reply to Yochai Eisenrich
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:

Quoted 12 lines · On Thu, 19 Mar 2026 22:06:10 +0200 you wrote:

packet_release() has a race window where NETDEV_UP can re-register a socket into a fanout group's arr[] array. The re-registration is not cleaned up by fanout_release(), leaving a dangling pointer in the fanout array.
packet_release() does NOT zero po->num in its bind_lock section. After releasing bind_lock, po->num is still non-zero and po->ifindex still matches the bound device. A concurrent packet_notifier(NETDEV_UP) that already found the socket in sklist can re-register the hook. For fanout sockets, this re-registration calls __fanout_link(sk, po) which adds the socket back into f->arr[] and increments f->num_members, but does NOT increment f->sk_ref.

Quoted 1 line

[...]

Here is the summary with links:
- net: fix fanout UAF in packet_release() via NETDEV_UP race

    https://git.kernel.org/netdev/net/c/42156f93d123

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html