Skip to content

Commit

Permalink
ip_tunnel: Clamp MTU to bounds on new link
Browse files Browse the repository at this point in the history
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 b96f9af
("ipv4/6: use core net MTU range checking").

Fixes: c544193 ("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>
  • Loading branch information
Stefano Brivio authored and Steffen Klassert committed Mar 19, 2018
1 parent dd1df24 commit 24fc797
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion net/ipv4/ip_tunnel.c
Original file line number Diff line number Diff line change
Expand Up @@ -1108,8 +1108,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);
out:
Expand Down

0 comments on commit 24fc797

Please sign in to comment.