net: fix fanout UAF in packet_release() via NETDEV_UP race
Subsystems (3)
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.
--- net/packet/af_packet.c | 1 + 1 file changed, 1 insertion(+)
net/packet/af_packet.c +1 -0
@@ -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
Quoted 15 lines · Yochai Eisenrich
packet_release()has a race window whereNETDEV_UPcan re-register a socket into a fanout group'sarr[]array. The re-registration is not cleaned up byfanout_release(), leaving a dangling pointer in the fanout array.packet_release()does NOT zeropo->numin itsbind_locksection. After releasingbind_lock,po->numis still non-zero andpo->ifindexstill matches the bound device. A concurrentpacket_notifier(NETDEV_UP)that already found the socket insklistcan re-register the hook. For fanout sockets, this re-registration calls__fanout_link(sk, po)which adds the socket back intof->arr[]and incrementsf->num_members, but does NOT incrementf->sk_ref.The fix sets
po->numto zero inpacket_releasewhilebind_lockis held to preventNETDEV_UPfrom 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")Signed-off-by Yochai Eisenrich <[email protected]>
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 whereNETDEV_UPcan re-register a socket into a fanout group'sarr[]array. The re-registration is not cleaned up byfanout_release(), leaving a dangling pointer in the fanout array.packet_release()does NOT zeropo->numin itsbind_locksection. After releasingbind_lock,po->numis still non-zero andpo->ifindexstill matches the bound device. A concurrentpacket_notifier(NETDEV_UP)that already found the socket insklistcan re-register the hook. For fanout sockets, this re-registration calls__fanout_link(sk, po)which adds the socket back intof->arr[]and incrementsf->num_members, but does NOT incrementf->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