Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp609700rwi; Thu, 27 Oct 2022 05:40:34 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5p0y8ELnH/fhBYLLVmYy7Ls1f2WBbT/H9uKhNGuVUCtJCTnANRp6msAvHxxr6Pp7RXpko2 X-Received: by 2002:a17:90b:3446:b0:213:4990:fa2 with SMTP id lj6-20020a17090b344600b0021349900fa2mr10299438pjb.73.1666874434380; Thu, 27 Oct 2022 05:40:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666874434; cv=none; d=google.com; s=arc-20160816; b=vas9ml9Fdg57PhSyX4N41JsDGnVG/fyfuxwGwHpph4dIpu6GlUaQjQS/2gUHkSj0Vf sD9/rV2npb0zs4F0WXlNlJajim2Kt8bdLMxDxJkKQ/lgmlvEt4DaYb68O8dsgH30mObi ZRrHeK0yIxyGZ4nzfKuKT20kc+zdj18tsWHXJ4TH85CgU6qYEVyZm03nwFaNSWfpq92l 77o7ffbnaajxs4X3nkP2jnKmbhuyBXwikEujk5tgkrGtl8Qdmc2hSt708iYSQw8Dshm6 I3ZDTqhctoYOfUzJGiEu8jlMRvbCdWSvpahhXB/TNIXVgV8RuRLZMLg9p/oc0gSBOd3d CTSA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=pWEvHLppfxWBW8+ISQe9vfLot+/ybDoyMJgUP6cuFrE=; b=oA2Lx9TeoTHPuovUfyxd50c11R1O+DjsjsqE9uLXjVX5E3M11H1N1uRkGlym0L1Lb4 EAHXadHJmj0uH5dYjxNAubZ41JRf1u70Bh6k9T9opo8UtLooX6gcJc6El4yFvpmUruvw x377MpkU/mqvaeh92AMmU+Sb4b6r6e78+giWs8U4zGwJhgAhpu8aYcb1DhswalSyVez8 HsPptksMiWznrVBWFrqeqi3oik2Cah35di7brdHu3hxPU4/RWYTBNLkTluQ4cNe6IhLh yvKxQ9Pf08nA4PCWovdZ8GQB6anzkN4lbt91rFYCZRd54boTODnw1JHT/v/ffcXI1SKq Z2RQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=QFGZm3rZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f14-20020a63554e000000b00441e10f5e3bsi1543075pgm.539.2022.10.27.05.40.22; Thu, 27 Oct 2022 05:40:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=QFGZm3rZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234688AbiJ0LkC (ORCPT + 99 others); Thu, 27 Oct 2022 07:40:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48668 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234111AbiJ0Lj6 (ORCPT ); Thu, 27 Oct 2022 07:39:58 -0400 Received: from mail-yb1-xb2e.google.com (mail-yb1-xb2e.google.com [IPv6:2607:f8b0:4864:20::b2e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DDBEC22519 for ; Thu, 27 Oct 2022 04:39:54 -0700 (PDT) Received: by mail-yb1-xb2e.google.com with SMTP id y72so1518415yby.13 for ; Thu, 27 Oct 2022 04:39:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=pWEvHLppfxWBW8+ISQe9vfLot+/ybDoyMJgUP6cuFrE=; b=QFGZm3rZ14dHWBfW+lw8P/mNPrfR5y5RthUIF/ENCUW2hh68Wr2DClFug2OMurAJtd 5mJbtbErG2P42+bmO5HxPD3uHpN9138pZoQUGiiZf4las4E81JyKK5GZwbMQf51YAuG8 mygIy8fEJTjZiCXqh0q1MCYLvRYOj8Oojbe3Wknjo5nH5zyCrbYarrW9STuzkZ4YA8QX c7Pk3JYmjiqed5CcimZt9ebZhCduc7urPX+ksaVFAkd5QlawMuaN2MLQknd2HOQe2Inl qTSSc1DhBR94anlu1XGklkGJ2tcAO2KoDOc06Z9XSAA54TU/UkEVD4XKqBbtICvCBHgx cO+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=pWEvHLppfxWBW8+ISQe9vfLot+/ybDoyMJgUP6cuFrE=; b=AiQdJoJuCt1JQgoDcBhscGfsZV6RJ2rC6oxseGiSAQp/Ltzy1WBgUpz9yk+LUL6dkX 8VwAiGplcS96ksX04TMdX2BS+DWdZOSLLc2WTmOHIE5D6ZcTS+SkCxiGUcNw3m+S6vsA 0C3tCiA3M7OFy2SsYmErcf+UU+muqmSMS309wFgjTr6g2/p8pod1cdNJEWAYo+63O2n/ N7277drHlIJrkaOF8bcdSP1SIQLYSViwV80VGL4sQ5qZxrasjgfGGCSdfZ64ZG7U47Zt aTBsEF4u3MGMQCf46Sd0fC99aDw3ripGOOVzJ8SYNE1ZsIg0YD1kMf72GqQirVTV5/OP uXUg== X-Gm-Message-State: ACrzQf0sKGftomNqPNYgbNn60NmLO+GsSjMrlI9PzFRdJGsuWDJ7G0rl OVBnK5ey8Nx9FPeMam+85nALCujmvLltPWbU+HV2lA== X-Received: by 2002:a25:32ca:0:b0:6ca:40e2:90c8 with SMTP id y193-20020a2532ca000000b006ca40e290c8mr34044036yby.55.1666870793192; Thu, 27 Oct 2022 04:39:53 -0700 (PDT) MIME-Version: 1.0 References: <20221027102449.926410-1-william.xuanziyang@huawei.com> In-Reply-To: <20221027102449.926410-1-william.xuanziyang@huawei.com> From: Eric Dumazet Date: Thu, 27 Oct 2022 04:39:42 -0700 Message-ID: Subject: Re: [PATCH net] ipv6/gro: fix an out of bounds memory bug in ipv6_gro_receive() To: Ziyang Xuan Cc: davem@davemloft.net, yoshfuji@linux-ipv6.org, dsahern@kernel.org, kuba@kernel.org, pabeni@redhat.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, herbert@gondor.apana.org.au Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Oct 27, 2022 at 3:25 AM Ziyang Xuan wrote: > > IPv6 packets without NEXTHDR_NONE extension header can make continuous > __skb_pull() until pskb_may_pull() failed in ipv6_gso_pull_exthdrs(). > That results in a big value of skb_gro_offset(), and after __skb_push() > in ipv6_gro_receive(), skb->data will less than skb->head, an out of > bounds memory bug occurs. That will trigger the problem as following: > > ================================================================== > BUG: KASAN: use-after-free in eth_type_trans+0x100/0x260 > ... > Call trace: > dump_backtrace+0xd8/0x130 > show_stack+0x1c/0x50 > dump_stack_lvl+0x64/0x7c > print_address_description.constprop.0+0xbc/0x2e8 > print_report+0x100/0x1e4 > kasan_report+0x80/0x120 > __asan_load8+0x78/0xa0 > eth_type_trans+0x100/0x260 Crash happens from eth_type_trans() , this should happen before ipv6_gro_receive() ? It seems your patch is unrelated. Please provide a repro. > napi_gro_frags+0x164/0x550 > tun_get_user+0xda4/0x1270 > tun_chr_write_iter+0x74/0x130 > do_iter_readv_writev+0x130/0x1ec > do_iter_write+0xbc/0x1e0 > vfs_writev+0x13c/0x26c > > Add comparison between skb->data - skb_gro_offset() and skb->head > and exception handler before __skb_push() to fix the bug. > > Fixes: 86911732d399 ("gro: Avoid copying headers of unmerged packets") > Signed-off-by: Ziyang Xuan > --- > net/ipv6/ip6_offload.c | 4 ++++ > 1 file changed, 4 insertions(+) > > diff --git a/net/ipv6/ip6_offload.c b/net/ipv6/ip6_offload.c > index 3ee345672849..6659ccf25387 100644 > --- a/net/ipv6/ip6_offload.c > +++ b/net/ipv6/ip6_offload.c > @@ -237,6 +237,10 @@ INDIRECT_CALLABLE_SCOPE struct sk_buff *ipv6_gro_receive(struct list_head *head, > proto = ipv6_gso_pull_exthdrs(skb, proto); > skb_gro_pull(skb, -skb_transport_offset(skb)); > skb_reset_transport_header(skb); > + if (unlikely(skb_headroom(skb) < skb_gro_offset(skb))) { This makes no sense to me. If there is a bug, it should be fixed earlier. > + kfree_skb(skb); > + return ERR_PTR(-EINPROGRESS); > + } > __skb_push(skb, skb_gro_offset(skb)); > > ops = rcu_dereference(inet6_offloads[proto]); > -- > 2.25.1 >