mirror of
git://git.yoctoproject.org/linux-yocto.git
synced 2025-10-23 07:23:12 +02:00
net/packet: fix a race in packet_set_ring() and packet_notifier()
commit01d3c8417b
upstream. 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 commit15fe076ede
("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:1da177e4c3
("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: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
546cebccfe
commit
7de0770500
|
@ -4541,10 +4541,10 @@ static int packet_set_ring(struct sock *sk, union tpacket_req_u *req_u,
|
||||||
spin_lock(&po->bind_lock);
|
spin_lock(&po->bind_lock);
|
||||||
was_running = po->running;
|
was_running = po->running;
|
||||||
num = po->num;
|
num = po->num;
|
||||||
if (was_running) {
|
|
||||||
WRITE_ONCE(po->num, 0);
|
WRITE_ONCE(po->num, 0);
|
||||||
|
if (was_running)
|
||||||
__unregister_prot_hook(sk, false);
|
__unregister_prot_hook(sk, false);
|
||||||
}
|
|
||||||
spin_unlock(&po->bind_lock);
|
spin_unlock(&po->bind_lock);
|
||||||
|
|
||||||
synchronize_net();
|
synchronize_net();
|
||||||
|
@ -4576,10 +4576,10 @@ static int packet_set_ring(struct sock *sk, union tpacket_req_u *req_u,
|
||||||
mutex_unlock(&po->pg_vec_lock);
|
mutex_unlock(&po->pg_vec_lock);
|
||||||
|
|
||||||
spin_lock(&po->bind_lock);
|
spin_lock(&po->bind_lock);
|
||||||
if (was_running) {
|
|
||||||
WRITE_ONCE(po->num, num);
|
WRITE_ONCE(po->num, num);
|
||||||
|
if (was_running)
|
||||||
register_prot_hook(sk);
|
register_prot_hook(sk);
|
||||||
}
|
|
||||||
spin_unlock(&po->bind_lock);
|
spin_unlock(&po->bind_lock);
|
||||||
if (pg_vec && (po->tp_version > TPACKET_V2)) {
|
if (pg_vec && (po->tp_version > TPACKET_V2)) {
|
||||||
/* Because we don't support block-based V3 on tx-ring */
|
/* Because we don't support block-based V3 on tx-ring */
|
||||||
|
|
Loading…
Reference in New Issue
Block a user