Skip to content

Commit 1576919

Browse files
committed
net/packet: fix a race in packet_set_ring() and packet_notifier()
JIRA: https://issues.redhat.com/browse/RHEL-115601 Upstream Status: net-next.git commit 01d3c84 commit 01d3c84 Author: Quang Le <quanglex97@gmail.com> Date: Fri Aug 1 13:54:16 2025 -0400 net/packet: fix a race in packet_set_ring() and packet_notifier() When packet_set_ring() releases po->bind_lock, another thread can run packet_notifier() and process an NETDEV_UP event. This race and the fix are both similar to that of commit 15fe076 ("net/packet: fix a race in packet_bind() and packet_notifier()"). There too the packet_notifier NETDEV_UP event managed to run while a po->bind_lock critical section had to be temporarily released. And the fix was similarly to temporarily set po->num to zero to keep the socket unhooked until the lock is retaken. The po->bind_lock in packet_set_ring and packet_notifier precede the introduction of git history. Fixes: 1da177e ("Linux-2.6.12-rc2") Cc: stable@vger.kernel.org Signed-off-by: Quang Le <quanglex97@gmail.com> Signed-off-by: Willem de Bruijn <willemb@google.com> Link: https://patch.msgid.link/20250801175423.2970334-1-willemdebruijn.kernel@gmail.com Signed-off-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: Davide Caratti <dcaratti@redhat.com>
1 parent 1c3682f commit 1576919

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

net/packet/af_packet.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4562,10 +4562,10 @@ static int packet_set_ring(struct sock *sk, union tpacket_req_u *req_u,
45624562
spin_lock(&po->bind_lock);
45634563
was_running = packet_sock_flag(po, PACKET_SOCK_RUNNING);
45644564
num = po->num;
4565-
if (was_running) {
4566-
WRITE_ONCE(po->num, 0);
4565+
WRITE_ONCE(po->num, 0);
4566+
if (was_running)
45674567
__unregister_prot_hook(sk, false);
4568-
}
4568+
45694569
spin_unlock(&po->bind_lock);
45704570

45714571
synchronize_net();
@@ -4597,10 +4597,10 @@ static int packet_set_ring(struct sock *sk, union tpacket_req_u *req_u,
45974597
mutex_unlock(&po->pg_vec_lock);
45984598

45994599
spin_lock(&po->bind_lock);
4600-
if (was_running) {
4601-
WRITE_ONCE(po->num, num);
4600+
WRITE_ONCE(po->num, num);
4601+
if (was_running)
46024602
register_prot_hook(sk);
4603-
}
4603+
46044604
spin_unlock(&po->bind_lock);
46054605
if (pg_vec && (po->tp_version > TPACKET_V2)) {
46064606
/* Because we don't support block-based V3 on tx-ring */

0 commit comments

Comments
 (0)