From mboxrd@z Thu Jan 1 00:00:00 1970 From: Gregory Rose Subject: Re: [PATCH net-next] net: ip6_gre: get ipv6hdr after skb_cow_head() Date: Fri, 13 Jul 2018 13:45:12 -0700 Message-ID: References: <20180713054050.5656-1-bhole_prashant_q7@lab.ntt.co.jp> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Cc: Alexey Kuznetsov , Hideaki YOSHIFUJI , William Tu , netdev@vger.kernel.org To: Prashant Bhole , "David S . Miller" Return-path: Received: from mail-pf0-f195.google.com ([209.85.192.195]:38502 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731564AbeGMVBa (ORCPT ); Fri, 13 Jul 2018 17:01:30 -0400 Received: by mail-pf0-f195.google.com with SMTP id v15-v6so3250984pff.5 for ; Fri, 13 Jul 2018 13:45:15 -0700 (PDT) In-Reply-To: <20180713054050.5656-1-bhole_prashant_q7@lab.ntt.co.jp> Content-Language: en-US Sender: netdev-owner@vger.kernel.org List-ID: On 7/12/2018 10:40 PM, Prashant Bhole wrote: > 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 e41c7c68ea77 ("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: 5a963eb61b7c ("ip6_gre: Add ERSPAN native tunnel support") > Signed-off-by: Prashant Bhole Good catch. LGTM Reviewed-by: Greg Rose > --- > net/ipv6/ip6_gre.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c > index 367177786e34..fc7dd3a04360 100644 > --- a/net/ipv6/ip6_gre.c > +++ b/net/ipv6/ip6_gre.c > @@ -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; > @@ -1012,6 +1011,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));