Skip to content

Commit 15718ea

Browse files
Dan Carpenterdavem330
authored andcommitted
tun: signedness bug in tun_get_user()
The recent fix d9bf5f1 "tun: compare with 0 instead of total_len" is not totally correct. Because "len" and "sizeof()" are size_t type, that means they are never less than zero. Signed-off-by: Dan Carpenter <[email protected]> Acked-by: Michael S. Tsirkin <[email protected]> Acked-by: Neil Horman <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent d1fcc17 commit 15718ea

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

drivers/net/tun.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,17 +1074,19 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile,
10741074
u32 rxhash;
10751075

10761076
if (!(tun->flags & TUN_NO_PI)) {
1077-
if ((len -= sizeof(pi)) < 0)
1077+
if (len < sizeof(pi))
10781078
return -EINVAL;
1079+
len -= sizeof(pi);
10791080

10801081
if (memcpy_fromiovecend((void *)&pi, iv, 0, sizeof(pi)))
10811082
return -EFAULT;
10821083
offset += sizeof(pi);
10831084
}
10841085

10851086
if (tun->flags & TUN_VNET_HDR) {
1086-
if ((len -= tun->vnet_hdr_sz) < 0)
1087+
if (len < tun->vnet_hdr_sz)
10871088
return -EINVAL;
1089+
len -= tun->vnet_hdr_sz;
10881090

10891091
if (memcpy_fromiovecend((void *)&gso, iv, offset, sizeof(gso)))
10901092
return -EFAULT;

0 commit comments

Comments
 (0)