Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp5917877rwr; Tue, 9 May 2023 07:58:05 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5UwrUjQlkEeyPq0E+gUXfFVKpWlYvSUvMgeuaIymvDNuhiGJjb8Mm3cI8u6RzCTEX6UBnQ X-Received: by 2002:a17:90b:1d87:b0:247:9d19:311f with SMTP id pf7-20020a17090b1d8700b002479d19311fmr14533132pjb.30.1683644284642; Tue, 09 May 2023 07:58:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683644284; cv=none; d=google.com; s=arc-20160816; b=RC8hClF3vYEe87Ar7xEZtxLlddeOdQVMEHBPmSk9xrIuQX3/fRtCmGHdxUos6FPUMd T3uBGkZERBHeUl3xlSl16cWDt8pv6Eypx2PtRIBPwjJ+FTd7hzjY65o40rHr+mN3Pv/9 VXagZnVgEhZNoLK+jyrJjggqHfAyZZtwu5By8dYT9OiAJjoma3g8Y/QT8RaMTAsMdhrX 4MNYm6ZLcgoIfilBbzh12P0ysXJN/8LEdwO4f63b9GY9znQdhGoFjWQ064+tWSqfXcc3 fw6A05CfxNCQ5CRFNnWdcPrnciSH7e503fHrPYd1Efn7mIFjTIF6ocQcoCbxzZguo8Vq XbSw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=UVfjjlZkJp0IYfrXhtcCeEFdqQLI9OZif8q75MPv2cU=; b=axOTAgWVPmDpBtLOCRECyEBb3U+XI3PPWnKYuJUT9FdJWBtAXqqgAtq+ozaOmXdVw+ lcaSCJkPKdvsO4iEh78uAmV7POg9YJ3MBHHAuPMLrK79sdz5vXlhuedTKM1+nC9RDgOp 1/CY0Zq6X6Fa/yoMNZ6jJ2WrbUMkHyMtssf5zzI3i9o3OO0Ay2zgtb0JWglm69PvXCPT R7Ad4ynn+ymlxUzyPehplKWr4xTGOX+xtYHmNj8vuVRdUFiKXCS3m/RTUArAOVWLSmoS qfjBAVayLuuPmKVASonMuwrvFqhNu2TB/jkMsOov1rQX7VbnvbO/NqtFbu7jHvymv0Xq mobg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=olalahCX; 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 m4-20020a17090b068400b00248a7477a5esi15072305pjz.2.2023.05.09.07.57.49; Tue, 09 May 2023 07:58:04 -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=20221208 header.b=olalahCX; 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 S235729AbjEIObm (ORCPT + 99 others); Tue, 9 May 2023 10:31:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43856 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235495AbjEIObl (ORCPT ); Tue, 9 May 2023 10:31:41 -0400 Received: from mail-qt1-x82b.google.com (mail-qt1-x82b.google.com [IPv6:2607:f8b0:4864:20::82b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 415F0C3 for ; Tue, 9 May 2023 07:31:40 -0700 (PDT) Received: by mail-qt1-x82b.google.com with SMTP id d75a77b69052e-3f38824a025so201051cf.0 for ; Tue, 09 May 2023 07:31:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1683642699; x=1686234699; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=UVfjjlZkJp0IYfrXhtcCeEFdqQLI9OZif8q75MPv2cU=; b=olalahCXesiGetwDI0UJCDouvP+4kEGEnF+/v6CftgPAUla/oSp/Ta+Szf/a5A6wGC DFl4OdFka/jmQB/Hi9FG7FMCbpMyWWuBUOGT3olzwl1Uo88DG/d60LfCDYaD/ofRMhgM pqMzt0UfxfHLIPSKcwKRGXl3hpFO5CMcSW7Hfw7vji/ON8lLH43XJuNJ34n27qYKtCVw HNYeIAKDFK8CxxNOVJh39aw1Kth55rvRcesDX9IUUwMkHjSpxgxjgrOi/radMW+1pBGX Yz0+42hs0VjgghezD2Aru09jLJE0C55OKl0aHHI67Ai1aOV1sNQQU6KNavwLJMX5IUg2 uJqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683642699; x=1686234699; h=content-transfer-encoding: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=UVfjjlZkJp0IYfrXhtcCeEFdqQLI9OZif8q75MPv2cU=; b=iJ2oi+qN5dSVryoG4lkCfd3ZIph1vclkvGnPnnrjZngutUCR4YXY/YgmY5Q6To3s6g QhqcDzMnxk/wX4VWS7dZ66WLSUwIyUSZ9JZwQfyiujDiGn9jkZOgwfAQNmNXheWsnCD0 12DbwcUK6U2NFAbZQBupMxaTzXMF2Yb2sp7jYjWBPl8ErkMDgNjRa130p0eV/W8LzOWG ysSr4EOtMt3shzYhIAQy5TCPrck22niFg9HC1ulcF4sqOZzdwvamCveYsestR3bfgNnv w6nHnUBRC8w+pzgDNvfUoyZKauujCgVUTeZM14ta5C8DF4Fb5qE13yQJ034C+0OAJI2B xfuw== X-Gm-Message-State: AC+VfDxZDP32SINfV8gs65jtAGd6hK/lz+keg7hsBWbQlD4Cc/SBeHwk IDmFaRkhve4Yaj2/Ve6FRjn/n6liZmVZgYGb9+8ULw== X-Received: by 2002:ac8:5982:0:b0:3db:1c01:9d95 with SMTP id e2-20020ac85982000000b003db1c019d95mr470317qte.4.1683642699179; Tue, 09 May 2023 07:31:39 -0700 (PDT) MIME-Version: 1.0 References: <20230509135546.580158-1-dongchenchen2@huawei.com> In-Reply-To: <20230509135546.580158-1-dongchenchen2@huawei.com> From: Eric Dumazet Date: Tue, 9 May 2023 16:31:26 +0200 Message-ID: Subject: Re: [PATCH net, v3] net: nsh: Use correct mac_offset to unwind gso skb in nsh_gso_segment() To: Dong Chenchen Cc: kuba@kernel.org, davem@davemloft.net, pabeni@redhat.com, simon.horman@corigine.com, jbenc@redhat.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, yuehaibing@huawei.com, weiyongjun1@huawei.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=ham 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 Tue, May 9, 2023 at 3:55=E2=80=AFPM Dong Chenchen wrote: > > As the call trace shows, skb_panic was caused by wrong skb->mac_header > in nsh_gso_segment(): > > invalid opcode: 0000 [#1] PREEMPT SMP KASAN PTI > CPU: 3 PID: 2737 Comm: syz Not tainted 6.3.0-next-20230505 #1 > RIP: 0010:skb_panic+0xda/0xe0 > call Trace: > skb_push+0x91/0xa0 > nsh_gso_segment+0x4f3/0x570 > skb_mac_gso_segment+0x19e/0x270 > __skb_gso_segment+0x1e8/0x3c0 > validate_xmit_skb+0x452/0x890 > validate_xmit_skb_list+0x99/0xd0 > sch_direct_xmit+0x294/0x7c0 > __dev_queue_xmit+0x16f0/0x1d70 > packet_xmit+0x185/0x210 > packet_snd+0xc15/0x1170 > packet_sendmsg+0x7b/0xa0 > sock_sendmsg+0x14f/0x160 > > The root cause is: > nsh_gso_segment() use skb->network_header - nhoff to reset mac_header > in skb_gso_error_unwind() if inner-layer protocol gso fails. > However, skb->network_header may be reset by inner-layer protocol > gso function e.g. mpls_gso_segment. skb->mac_header reset by the > inaccurate network_header will be larger than skb headroom. > > nsh_gso_segment > nhoff =3D skb->network_header - skb->mac_header; > __skb_pull(skb,nsh_len) > skb_mac_gso_segment > mpls_gso_segment > skb_reset_network_header(skb);//skb->network_header+=3Dnsh_le= n > return -EINVAL; > skb_gso_error_unwind > skb_push(skb, nsh_len); > skb->mac_header =3D skb->network_header - nhoff; > // skb->mac_header > skb->headroom, cause skb_push panic > > Use correct mac_offset to restore mac_header to fix it. > > Fixes: c411ed854584 ("nsh: add GSO support") > Signed-off-by: Dong Chenchen > > --- > v2: > - Use skb->mac_header not skb->network_header-nhoff for mac_offset. > > v3: > - 'net' is noted in the subject. > - arrange local variable following reverse xmas tree order > --- > net/nsh/nsh.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/net/nsh/nsh.c b/net/nsh/nsh.c > index e9ca007718b7..793e0bd94558 100644 > --- a/net/nsh/nsh.c > +++ b/net/nsh/nsh.c > @@ -77,6 +77,7 @@ static struct sk_buff *nsh_gso_segment(struct sk_buff *= skb, > netdev_features_t features) > { > struct sk_buff *segs =3D ERR_PTR(-EINVAL); > + u16 mac_offset =3D skb->mac_header; > unsigned int nsh_len, mac_len; > __be16 proto; > int nhoff; > @@ -108,8 +109,7 @@ static struct sk_buff *nsh_gso_segment(struct sk_buff= *skb, > segs =3D skb_mac_gso_segment(skb, features); > if (IS_ERR_OR_NULL(segs)) { > skb_gso_error_unwind(skb, htons(ETH_P_NSH), nsh_len, > - skb->network_header - nhoff, > - mac_len); > + mac_offset, mac_len); > goto out; > } > I do not think this patch is enough ? This is still not nice, because mac_header =3D=3D 0xFFFF nhoff =3D skb->network_header - skb->mac_header; ... skb_set_mac_header(skb, -nhoff); I would simply restore mac_header with "skb->mac_header =3D mac_offset" and get rid of nhoff. (Accept the fact that GSO layer should not rely on skb mac_header being set= ) In the future, we might be able to rewrite GSO without any assumptions on skb->mac_header.