net/packet: fix overflow in check for tp_reserve 09/155209/1
authorAndrey Konovalov <andreyknvl@google.com>
Wed, 29 Mar 2017 14:11:22 +0000 (16:11 +0200)
committerSeung-Woo Kim <sw0312.kim@samsung.com>
Thu, 12 Oct 2017 09:37:10 +0000 (18:37 +0900)
commit bcc5364bdcfe131e6379363f089e7b4108d35b70 upstream.

When calculating po->tp_hdrlen + po->tp_reserve the result can overflow.

Fix by checking that tp_reserve <= INT_MAX on assign.

Signed-off-by: Andrey Konovalov <andreyknvl@google.com>
Acked-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Willy Tarreau <w@1wt.eu>
[sw0312.kim: cherry-pick from linux-3.10.y to fix CVE-2017-7308]
Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
Change-Id: I7654b253882584ad30f5dbd38dcf315446e98a48

net/packet/af_packet.c

index afde201..22f2a3d 100644 (file)
@@ -3180,6 +3180,8 @@ packet_setsockopt(struct socket *sock, int level, int optname, char __user *optv
                        return -EBUSY;
                if (copy_from_user(&val, optval, sizeof(val)))
                        return -EFAULT;
+               if (val > INT_MAX)
+                       return -EINVAL;
                po->tp_reserve = val;
                return 0;
        }