Skip to content

Commit 302c74b

Browse files
wdebruijwtarreau
authored andcommitted
tun: read vnet_hdr_sz once
commit e1edab8 upstream. 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. Read this value once and cache locally, as it can be updated between the test and use (TOCTOU). [js] we have TUN_VNET_HDR in 3.12 Signed-off-by: Willem de Bruijn <[email protected]> Reported-by: Dmitry Vyukov <[email protected]> CC: Eric Dumazet <[email protected]> Acked-by: Eric Dumazet <[email protected]> Signed-off-by: David S. Miller <[email protected]> Signed-off-by: Jiri Slaby <[email protected]> [wt: s/READ_ONCE/ACCESS_ONCE] Signed-off-by: Willy Tarreau <[email protected]>
1 parent 58e4633 commit 302c74b

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

drivers/net/tun.c

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

10891089
if (tun->flags & TUN_VNET_HDR) {
1090-
if (len < tun->vnet_hdr_sz)
1090+
int vnet_hdr_sz = ACCESS_ONCE(tun->vnet_hdr_sz);
1091+
1092+
if (len < vnet_hdr_sz)
10911093
return -EINVAL;
1092-
len -= tun->vnet_hdr_sz;
1094+
len -= vnet_hdr_sz;
10931095

10941096
if (memcpy_fromiovecend((void *)&gso, iv, offset, sizeof(gso)))
10951097
return -EFAULT;
@@ -1100,7 +1102,7 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile,
11001102

11011103
if (gso.hdr_len > len)
11021104
return -EINVAL;
1103-
offset += tun->vnet_hdr_sz;
1105+
offset += vnet_hdr_sz;
11041106
}
11051107

11061108
if ((tun->flags & TUN_TYPE_MASK) == TUN_TAP_DEV) {
@@ -1275,7 +1277,7 @@ static ssize_t tun_put_user(struct tun_struct *tun,
12751277
int vnet_hdr_sz = 0;
12761278

12771279
if (tun->flags & TUN_VNET_HDR)
1278-
vnet_hdr_sz = tun->vnet_hdr_sz;
1280+
vnet_hdr_sz = ACCESS_ONCE(tun->vnet_hdr_sz);
12791281

12801282
if (!(tun->flags & TUN_NO_PI)) {
12811283
if ((len -= sizeof(pi)) < 0)

0 commit comments

Comments
 (0)