Skip to content

Commit 723c4bc

Browse files
committed
net/packet: fix a race in packet_set_ring() and packet_notifier()
JIRA: https://issues.redhat.com/browse/RHEL-115650 Upstream Status: net.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 c51a5dd commit 723c4bc

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
@@ -4500,10 +4500,10 @@ static int packet_set_ring(struct sock *sk, union tpacket_req_u *req_u,
45004500
spin_lock(&po->bind_lock);
45014501
was_running = packet_sock_flag(po, PACKET_SOCK_RUNNING);
45024502
num = po->num;
4503-
if (was_running) {
4504-
WRITE_ONCE(po->num, 0);
4503+
WRITE_ONCE(po->num, 0);
4504+
if (was_running)
45054505
__unregister_prot_hook(sk, false);
4506-
}
4506+
45074507
spin_unlock(&po->bind_lock);
45084508

45094509
synchronize_net();
@@ -4535,10 +4535,10 @@ static int packet_set_ring(struct sock *sk, union tpacket_req_u *req_u,
45354535
mutex_unlock(&po->pg_vec_lock);
45364536

45374537
spin_lock(&po->bind_lock);
4538-
if (was_running) {
4539-
WRITE_ONCE(po->num, num);
4538+
WRITE_ONCE(po->num, num);
4539+
if (was_running)
45404540
register_prot_hook(sk);
4541-
}
4541+
45424542
spin_unlock(&po->bind_lock);
45434543
if (pg_vec && (po->tp_version > TPACKET_V2)) {
45444544
/* Because we don't support block-based V3 on tx-ring */

0 commit comments

Comments
 (0)