Skip to content

Commit 63364a5

Browse files
wdebruijgregkh
authored andcommitted
packet: fix tp_reserve race in packet_set_ring
[ Upstream commit c27927e372f0785f3303e8fad94b85945e2c97b7 ] Updates to tp_reserve can race with reads of the field in packet_set_ring. Avoid this by holding the socket lock during updates in setsockopt PACKET_RESERVE. This bug was discovered by syzkaller. Fixes: 8913336 ("packet: add PACKET_RESERVE sockopt") Reported-by: Andrey Konovalov <andreyknvl@google.com> Signed-off-by: Willem de Bruijn <willemb@google.com> Signed-off-by: David S. Miller <davem@davemloft.net> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 37d5c6e commit 63364a5

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

net/packet/af_packet.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3622,14 +3622,19 @@ packet_setsockopt(struct socket *sock, int level, int optname, char __user *optv
36223622

36233623
if (optlen != sizeof(val))
36243624
return -EINVAL;
3625-
if (po->rx_ring.pg_vec || po->tx_ring.pg_vec)
3626-
return -EBUSY;
36273625
if (copy_from_user(&val, optval, sizeof(val)))
36283626
return -EFAULT;
36293627
if (val > INT_MAX)
36303628
return -EINVAL;
3631-
po->tp_reserve = val;
3632-
return 0;
3629+
lock_sock(sk);
3630+
if (po->rx_ring.pg_vec || po->tx_ring.pg_vec) {
3631+
ret = -EBUSY;
3632+
} else {
3633+
po->tp_reserve = val;
3634+
ret = 0;
3635+
}
3636+
release_sock(sk);
3637+
return ret;
36333638
}
36343639
case PACKET_LOSS:
36353640
{

0 commit comments

Comments
 (0)