Skip to content

Commit ccfec9e

Browse files
Paolo Abenidavem330
authored andcommitted
ip_tunnel: be careful when accessing the inner header
Cong noted that we need the same checks introduced by commit 76c0ddd ("ip6_tunnel: be careful when accessing the inner header") even for ipv4 tunnels. Fixes: c544193 ("GRE: Refactor GRE tunneling code.") Suggested-by: Cong Wang <xiyou.wangcong@gmail.com> Signed-off-by: Paolo Abeni <pabeni@redhat.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent d8e2262 commit ccfec9e

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

net/ipv4/ip_tunnel.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,7 @@ void ip_tunnel_xmit(struct sk_buff *skb, struct net_device *dev,
627627
const struct iphdr *tnl_params, u8 protocol)
628628
{
629629
struct ip_tunnel *tunnel = netdev_priv(dev);
630+
unsigned int inner_nhdr_len = 0;
630631
const struct iphdr *inner_iph;
631632
struct flowi4 fl4;
632633
u8 tos, ttl;
@@ -636,6 +637,14 @@ void ip_tunnel_xmit(struct sk_buff *skb, struct net_device *dev,
636637
__be32 dst;
637638
bool connected;
638639

640+
/* ensure we can access the inner net header, for several users below */
641+
if (skb->protocol == htons(ETH_P_IP))
642+
inner_nhdr_len = sizeof(struct iphdr);
643+
else if (skb->protocol == htons(ETH_P_IPV6))
644+
inner_nhdr_len = sizeof(struct ipv6hdr);
645+
if (unlikely(!pskb_may_pull(skb, inner_nhdr_len)))
646+
goto tx_error;
647+
639648
inner_iph = (const struct iphdr *)skb_inner_network_header(skb);
640649
connected = (tunnel->parms.iph.daddr != 0);
641650

0 commit comments

Comments
 (0)