Skip to content

Commit 01d3c84

Browse files
quanglex97kuba-moo
authored andcommitted
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: [email protected] Signed-off-by: Quang Le <[email protected]> Signed-off-by: Willem de Bruijn <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 5a40f8a commit 01d3c84

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
@@ -4573,10 +4573,10 @@ static int packet_set_ring(struct sock *sk, union tpacket_req_u *req_u,
45734573
spin_lock(&po->bind_lock);
45744574
was_running = packet_sock_flag(po, PACKET_SOCK_RUNNING);
45754575
num = po->num;
4576-
if (was_running) {
4577-
WRITE_ONCE(po->num, 0);
4576+
WRITE_ONCE(po->num, 0);
4577+
if (was_running)
45784578
__unregister_prot_hook(sk, false);
4579-
}
4579+
45804580
spin_unlock(&po->bind_lock);
45814581

45824582
synchronize_net();
@@ -4608,10 +4608,10 @@ static int packet_set_ring(struct sock *sk, union tpacket_req_u *req_u,
46084608
mutex_unlock(&po->pg_vec_lock);
46094609

46104610
spin_lock(&po->bind_lock);
4611-
if (was_running) {
4612-
WRITE_ONCE(po->num, num);
4611+
WRITE_ONCE(po->num, num);
4612+
if (was_running)
46134613
register_prot_hook(sk);
4614-
}
4614+
46154615
spin_unlock(&po->bind_lock);
46164616
if (pg_vec && (po->tp_version > TPACKET_V2)) {
46174617
/* Because we don't support block-based V3 on tx-ring */

0 commit comments

Comments
 (0)