net: erspan: reload pointer after pskb_may_pull
authorWilliam Tu <u9012063@gmail.com>
Fri, 15 Dec 2017 22:27:44 +0000 (14:27 -0800)
committerDavid S. Miller <davem@davemloft.net>
Mon, 18 Dec 2017 20:11:25 +0000 (15:11 -0500)
pskb_may_pull() can change skb->data, so we need to re-load pkt_md
and ershdr at the right place.

Fixes: 94d7d8f29287 ("ip6_gre: add erspan v2 support")
Fixes: f551c91de262 ("net: erspan: introduce erspan v2 for ip_gre")
Signed-off-by: William Tu <u9012063@gmail.com>
Cc: Haishuang Yan <yanhaishuang@cmss.chinamobile.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/ipv4/ip_gre.c
net/ipv6/ip6_gre.c

index b3a32a98024051ae5063ae606187b89f593e19b3..fd4d6e96da7e953b8bb24758a5a691051a3e1e6a 100644 (file)
@@ -279,7 +279,6 @@ static int erspan_rcv(struct sk_buff *skb, struct tnl_ptk_info *tpi,
         * Use ERSPAN 10-bit session ID as key.
         */
        tpi->key = cpu_to_be32(ntohs(ershdr->session_id) & ID_MASK);
-       pkt_md = (struct erspan_metadata *)(ershdr + 1);
        tunnel = ip_tunnel_lookup(itn, skb->dev->ifindex,
                                  tpi->flags | TUNNEL_KEY,
                                  iph->saddr, iph->daddr, tpi->key);
@@ -289,6 +288,9 @@ static int erspan_rcv(struct sk_buff *skb, struct tnl_ptk_info *tpi,
                if (unlikely(!pskb_may_pull(skb, len)))
                        return PACKET_REJECT;
 
+               ershdr = (struct erspan_base_hdr *)(skb->data + gre_hdr_len);
+               pkt_md = (struct erspan_metadata *)(ershdr + 1);
+
                if (__iptunnel_pull_header(skb,
                                           len,
                                           htons(ETH_P_TEB),
index b3e4e0384f361bd5b089dedd7f7e87c2d12e0bd2..87b9892dfa235ecc7cfcdeade3505781d826fb5f 100644 (file)
@@ -515,7 +515,6 @@ static int ip6erspan_rcv(struct sk_buff *skb, int gre_hdr_len,
 
        ver = (ntohs(ershdr->ver_vlan) & VER_MASK) >> VER_OFFSET;
        tpi->key = cpu_to_be32(ntohs(ershdr->session_id) & ID_MASK);
-       pkt_md = (struct erspan_metadata *)(ershdr + 1);
 
        tunnel = ip6gre_tunnel_lookup(skb->dev,
                                      &ipv6h->saddr, &ipv6h->daddr, tpi->key,
@@ -526,6 +525,9 @@ static int ip6erspan_rcv(struct sk_buff *skb, int gre_hdr_len,
                if (unlikely(!pskb_may_pull(skb, len)))
                        return PACKET_REJECT;
 
+               ershdr = (struct erspan_base_hdr *)skb->data;
+               pkt_md = (struct erspan_metadata *)(ershdr + 1);
+
                if (__iptunnel_pull_header(skb, len,
                                           htons(ETH_P_TEB),
                                           false, false) < 0)