Skip to content

Commit 432d4f8

Browse files
committed
Merge branch 'read-vnet_hdr_sz-once'
Willem de Bruijn says: ==================== read vnet_hdr_sz once Tuntap devices allow concurrent use and update of field vnet_hdr_sz. Read the field once to avoid TOCTOU. ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents ccf7abb + 837585a commit 432d4f8

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
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

drivers/net/tun.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1170,9 +1170,11 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile,
11701170
}
11711171

11721172
if (tun->flags & IFF_VNET_HDR) {
1173-
if (len < tun->vnet_hdr_sz)
1173+
int vnet_hdr_sz = READ_ONCE(tun->vnet_hdr_sz);
1174+
1175+
if (len < vnet_hdr_sz)
11741176
return -EINVAL;
1175-
len -= tun->vnet_hdr_sz;
1177+
len -= vnet_hdr_sz;
11761178

11771179
if (!copy_from_iter_full(&gso, sizeof(gso), from))
11781180
return -EFAULT;
@@ -1183,7 +1185,7 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile,
11831185

11841186
if (tun16_to_cpu(tun, gso.hdr_len) > len)
11851187
return -EINVAL;
1186-
iov_iter_advance(from, tun->vnet_hdr_sz - sizeof(gso));
1188+
iov_iter_advance(from, vnet_hdr_sz - sizeof(gso));
11871189
}
11881190

11891191
if ((tun->flags & TUN_TYPE_MASK) == IFF_TAP) {
@@ -1335,7 +1337,7 @@ static ssize_t tun_put_user(struct tun_struct *tun,
13351337
vlan_hlen = VLAN_HLEN;
13361338

13371339
if (tun->flags & IFF_VNET_HDR)
1338-
vnet_hdr_sz = tun->vnet_hdr_sz;
1340+
vnet_hdr_sz = READ_ONCE(tun->vnet_hdr_sz);
13391341

13401342
total = skb->len + vlan_hlen + vnet_hdr_sz;
13411343

0 commit comments

Comments
 (0)