Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b7ed8794 authored by Prashant Bhole's avatar Prashant Bhole Committed by David S. Miller
Browse files

net: ip6_gre: get ipv6hdr after skb_cow_head()



A KASAN:use-after-free bug was found related to ip6-erspan
while running selftests/net/ip6_gre_headroom.sh

It happens because of following sequence:
- ipv6hdr pointer is obtained from skb
- skb_cow_head() is called, skb->head memory is reallocated
- old data is accessed using ipv6hdr pointer

skb_cow_head() call was added in e41c7c68 ("ip6erspan: make sure
enough headroom at xmit."), but looking at the history there was a
chance of similar bug because gre_handle_offloads() and pskb_trim()
can also reallocate skb->head memory. Fixes tag points to commit
which introduced possibility of this bug.

This patch moves ipv6hdr pointer assignment after skb_cow_head() call.

Fixes: 5a963eb6 ("ip6_gre: Add ERSPAN native tunnel support")
Signed-off-by: default avatarPrashant Bhole <bhole_prashant_q7@lab.ntt.co.jp>
Reviewed-by: default avatarGreg Rose <gvrose8192@gmail.com>
Acked-by: default avatarWilliam Tu <u9012063@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 6e8cfd6d
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -927,7 +927,6 @@ static netdev_tx_t ip6gre_tunnel_xmit(struct sk_buff *skb,
static netdev_tx_t ip6erspan_tunnel_xmit(struct sk_buff *skb,
					 struct net_device *dev)
{
	struct ipv6hdr *ipv6h = ipv6_hdr(skb);
	struct ip6_tnl *t = netdev_priv(dev);
	struct dst_entry *dst = skb_dst(skb);
	struct net_device_stats *stats;
@@ -1010,6 +1009,8 @@ static netdev_tx_t ip6erspan_tunnel_xmit(struct sk_buff *skb,
			goto tx_err;
		}
	} else {
		struct ipv6hdr *ipv6h = ipv6_hdr(skb);

		switch (skb->protocol) {
		case htons(ETH_P_IP):
			memset(&(IPCB(skb)->opt), 0, sizeof(IPCB(skb)->opt));