]> git.hungrycats.org Git - linux/commitdiff
ip_tunnel: Clamp MTU to bounds on new link
authorStefano Brivio <sbrivio@redhat.com>
Thu, 15 Mar 2018 16:16:28 +0000 (17:16 +0100)
committerBen Hutchings <ben@decadent.org.uk>
Sat, 16 Jun 2018 21:22:43 +0000 (22:22 +0100)
commit 24fc79798b8ddfd46f2dd363a8d29072c083b977 upstream.

Otherwise, it's possible to specify invalid MTU values directly
on creation of a link (via 'ip link add'). This is already
prevented on subsequent MTU changes by commit b96f9afee4eb
("ipv4/6: use core net MTU range checking").

Fixes: c54419321455 ("GRE: Refactor GRE tunneling code.")
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Acked-by: Sabrina Dubroca <sd@queasysnail.net>
Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
[bwh: Backported to 3.16: Add definition of ETH_MIN_MTU]
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
include/uapi/linux/if_ether.h
net/ipv4/ip_tunnel.c

index eadc8ba59e3d49ec0ba499a0f4ec98d9d12c9b1e..b2d0ffdd637a4640cde78b62edbb74156e251c6f 100644 (file)
@@ -36,6 +36,8 @@
 #define ETH_FRAME_LEN  1514            /* Max. octets in frame sans FCS */
 #define ETH_FCS_LEN    4               /* Octets in the FCS             */
 
+#define ETH_MIN_MTU    68              /* Min IPv4 MTU per RFC791      */
+
 /*
  *     These are the defined Ethernet Protocol ID's.
  */
index 51dd1605f9442be350aa426bce856b55a351a1f7..9fda4be5cd8ac356b901b5b070ea9561676ae4a4 100644 (file)
@@ -968,8 +968,14 @@ int ip_tunnel_newlink(struct net_device *dev, struct nlattr *tb[],
                eth_hw_addr_random(dev);
 
        mtu = ip_tunnel_bind_dev(dev);
-       if (!tb[IFLA_MTU])
+       if (tb[IFLA_MTU]) {
+               unsigned int max = 0xfff8 - dev->hard_header_len - nt->hlen;
+
+               dev->mtu = clamp(dev->mtu, (unsigned int)ETH_MIN_MTU,
+                                (unsigned int)(max - sizeof(struct iphdr)));
+       } else {
                dev->mtu = mtu;
+       }
 
        ip_tunnel_add(itn, nt);