net/packet: annotate accesses to po->xmit
[ Upstream commit b9d83ab8a708f23a4001d60e9d8d0b3be3d9f607 ]
po->xmit can be set from setsockopt(PACKET_QDISC_BYPASS),
while read locklessly.
Use READ_ONCE()/WRITE_ONCE() to avoid potential load/store
tearing issues.
Fixes: d346a3fae3 ("packet: introduce PACKET_QDISC_BYPASS socket option")
Signed-off-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
committed by
Greg Kroah-Hartman
parent
ba6d56b20e
commit
8bb81a925a
@@ -269,7 +269,8 @@ static void packet_cached_dev_reset(struct packet_sock *po)
|
|||||||
|
|
||||||
static bool packet_use_direct_xmit(const struct packet_sock *po)
|
static bool packet_use_direct_xmit(const struct packet_sock *po)
|
||||||
{
|
{
|
||||||
return po->xmit == packet_direct_xmit;
|
/* Paired with WRITE_ONCE() in packet_setsockopt() */
|
||||||
|
return READ_ONCE(po->xmit) == packet_direct_xmit;
|
||||||
}
|
}
|
||||||
|
|
||||||
static u16 packet_pick_tx_queue(struct sk_buff *skb)
|
static u16 packet_pick_tx_queue(struct sk_buff *skb)
|
||||||
@@ -2825,7 +2826,8 @@ tpacket_error:
|
|||||||
packet_inc_pending(&po->tx_ring);
|
packet_inc_pending(&po->tx_ring);
|
||||||
|
|
||||||
status = TP_STATUS_SEND_REQUEST;
|
status = TP_STATUS_SEND_REQUEST;
|
||||||
err = po->xmit(skb);
|
/* Paired with WRITE_ONCE() in packet_setsockopt() */
|
||||||
|
err = READ_ONCE(po->xmit)(skb);
|
||||||
if (unlikely(err != 0)) {
|
if (unlikely(err != 0)) {
|
||||||
if (err > 0)
|
if (err > 0)
|
||||||
err = net_xmit_errno(err);
|
err = net_xmit_errno(err);
|
||||||
@@ -3028,7 +3030,8 @@ static int packet_snd(struct socket *sock, struct msghdr *msg, size_t len)
|
|||||||
virtio_net_hdr_set_proto(skb, &vnet_hdr);
|
virtio_net_hdr_set_proto(skb, &vnet_hdr);
|
||||||
}
|
}
|
||||||
|
|
||||||
err = po->xmit(skb);
|
/* Paired with WRITE_ONCE() in packet_setsockopt() */
|
||||||
|
err = READ_ONCE(po->xmit)(skb);
|
||||||
if (unlikely(err != 0)) {
|
if (unlikely(err != 0)) {
|
||||||
if (err > 0)
|
if (err > 0)
|
||||||
err = net_xmit_errno(err);
|
err = net_xmit_errno(err);
|
||||||
@@ -3979,7 +3982,8 @@ packet_setsockopt(struct socket *sock, int level, int optname, sockptr_t optval,
|
|||||||
if (copy_from_sockptr(&val, optval, sizeof(val)))
|
if (copy_from_sockptr(&val, optval, sizeof(val)))
|
||||||
return -EFAULT;
|
return -EFAULT;
|
||||||
|
|
||||||
po->xmit = val ? packet_direct_xmit : dev_queue_xmit;
|
/* Paired with all lockless reads of po->xmit */
|
||||||
|
WRITE_ONCE(po->xmit, val ? packet_direct_xmit : dev_queue_xmit);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
|||||||
Reference in New Issue
Block a user