Return-Path: Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:35972 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726686AbeLIVze (ORCPT ); Sun, 9 Dec 2018 16:55:34 -0500 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, "Cong Wang" , "Paolo Abeni" , "David S. Miller" Date: Sun, 09 Dec 2018 21:50:33 +0000 Message-ID: Subject: [PATCH 3.16 263/328] ip_tunnel: be careful when accessing the inner header In-Reply-To: Sender: stable-owner@vger.kernel.org List-ID: 3.16.62-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: Paolo Abeni commit ccfec9e5cb2d48df5a955b7bf47f7782157d3bc2 upstream. Cong noted that we need the same checks introduced by commit 76c0ddd8c3a6 ("ip6_tunnel: be careful when accessing the inner header") even for ipv4 tunnels. Fixes: c54419321455 ("GRE: Refactor GRE tunneling code.") Suggested-by: Cong Wang Signed-off-by: Paolo Abeni Signed-off-by: David S. Miller Signed-off-by: Ben Hutchings --- net/ipv4/ip_tunnel.c | 9 +++++++++ 1 file changed, 9 insertions(+) --- a/net/ipv4/ip_tunnel.c +++ b/net/ipv4/ip_tunnel.c @@ -551,6 +551,7 @@ void ip_tunnel_xmit(struct sk_buff *skb, const struct iphdr *tnl_params, const u8 protocol) { struct ip_tunnel *tunnel = netdev_priv(dev); + unsigned int inner_nhdr_len = 0; const struct iphdr *inner_iph; struct flowi4 fl4; u8 tos, ttl; @@ -561,6 +562,14 @@ void ip_tunnel_xmit(struct sk_buff *skb, int err; bool connected; + /* ensure we can access the inner net header, for several users below */ + if (skb->protocol == htons(ETH_P_IP)) + inner_nhdr_len = sizeof(struct iphdr); + else if (skb->protocol == htons(ETH_P_IPV6)) + inner_nhdr_len = sizeof(struct ipv6hdr); + if (unlikely(!pskb_may_pull(skb, inner_nhdr_len))) + goto tx_error; + inner_iph = (const struct iphdr *)skb_inner_network_header(skb); connected = (tunnel->parms.iph.daddr != 0);