Skip to content

Commit 837585a

Browse files
wdebruijdavem330
authored andcommitted
macvtap: read vnet_hdr_size once
When IFF_VNET_HDR is enabled, a virtio_net header must precede data. Data length is verified to be greater than or equal to expected header length tun->vnet_hdr_sz before copying. Macvtap functions read the value once, but unless READ_ONCE is used, the compiler may ignore this and read multiple times. Enforce a single read and locally cached value to avoid updates between test and use. Signed-off-by: Willem de Bruijn <[email protected]> Suggested-by: Eric Dumazet <[email protected]> Acked-by: Eric Dumazet <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent e1edab8 commit 837585a

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

drivers/net/macvtap.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,7 @@ static ssize_t macvtap_get_user(struct macvtap_queue *q, struct msghdr *m,
681681
size_t linear;
682682

683683
if (q->flags & IFF_VNET_HDR) {
684-
vnet_hdr_len = q->vnet_hdr_sz;
684+
vnet_hdr_len = READ_ONCE(q->vnet_hdr_sz);
685685

686686
err = -EINVAL;
687687
if (len < vnet_hdr_len)
@@ -820,7 +820,7 @@ static ssize_t macvtap_put_user(struct macvtap_queue *q,
820820

821821
if (q->flags & IFF_VNET_HDR) {
822822
struct virtio_net_hdr vnet_hdr;
823-
vnet_hdr_len = q->vnet_hdr_sz;
823+
vnet_hdr_len = READ_ONCE(q->vnet_hdr_sz);
824824
if (iov_iter_count(iter) < vnet_hdr_len)
825825
return -EINVAL;
826826

0 commit comments

Comments
 (0)