🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #9956

Re: [PATCH net v2 2/2] net: gro: invalidate frag0 after a pull

#9956
From: Eric Dumazet
Date: Mon, 02 Nov 2026 16:18
190 lines
16576 bytes
Le lun. 2 nov. 2026 à 14:00, <netdev-bot+sashiko@kernel.org> a écrit :
>
> Thank you for your contribution! Sashiko AI review found 1 potential
> issue(s) to consider.
>
> Critical: 0 · High: 1 (1) · Medium: 0 · Low: 0
>
> If you believe none of the issues are legitimate, please reply to each
> issue of Medium severity or higher and explain why the AI is wrong.
> If any of them are legitimate and you plan to respin, please let patchwork
> know by including "pw-bot: cr" as a separate line at the end of your reply
> (one such reply per series is enough).
>
> - [High] net: gro: packet corruption in gro_pull_from_frag0() after
>   failed pull
>
> Pre-existing issues:
> - [High] This problem wasn't introduced by this patch, but
>   `napi_gro_frags()` (net/core/gro.c:783-794) never checks the result of…
>
> --
>
> net: gro: invalidate frag0 after a pull
>
> This patch adds skb_gro_frag0_invalidate(), which clears
> NAPI_GRO_CB(skb)->frag0_len. It is called before the slow pulls in
> skb_gro_header_slow(), skb_gro_receive_list(), esp4_gro_receive(),
> esp6_gro_receive() and udp_gro_receive_segment(). This keeps later GRO
> header accesses from using a frag0 pointer that the pull may have
> released or reallocated.
>
> > diff --git a/include/net/gro.h b/include/net/gro.h
> > index 00b49b6b9e74f..6f6affc8ab91c 100644
> > --- a/include/net/gro.h
> > +++ b/include/net/gro.h
> > @@ -160,9 +160,19 @@ static inline bool skb_gro_may_pull(const struct sk_buff *skb,
> >       return likely(hlen <= NAPI_GRO_CB(skb)->frag0_len);
> >  }
> >
> > +/* A pull can release the page fragment frag0 points to, or reallocate
> > + * skb->head, even if it fails. Call this before the pull, to make sure later
> > + * skb_gro_header() and skb_gro_network_header() calls no longer use frag0.
> > + */
> > +static inline void skb_gro_frag0_invalidate(struct sk_buff *skb)
> > +{
> > +     NAPI_GRO_CB(skb)->frag0_len = 0;
> > +}
> > +
> >  static inline void *skb_gro_header_slow(struct sk_buff *skb, unsigned int hlen,
> >                                       unsigned int offset)
> >  {
> > +     skb_gro_frag0_invalidate(skb);
> >       if (!pskb_may_pull(skb, hlen))
> >               return NULL;
>
> [Severity: High]
> Does clearing frag0_len here, while frag0 itself is left pointing at
> the old location, break gro_pull_from_frag0() when the slow pull in
> skb_gro_header_slow() fails?
>
> Consider an skb that enters GRO with skb_headlen(skb) == 0. In that
> case skb_gro_reset_offset() points frag0 at the start of frags[0],
> which is packet offset 0.
>
> Now add remote checksum offload nopartial: vxlan_gro_receive() or
> vxlan_gpe_gro_receive() with VXLAN_F_REMCSUM_NOPARTIAL, or
> gue_gro_receive() with FOU_F_REMCSUM_NOPARTIAL. There,
> skb_gro_remcsum_process() records grc->offset and grc->delta through
> the frag0 fast path. The inner eth_gro_receive() and
> inet_gro_receive()/ipv6_gro_receive() handlers then advance
> skb_gro_offset() through frag0 too, so skb_headlen() is still 0.
>
> Suppose the next inner header does not fit in frag0_len, for instance
> in tcp_gro_pull_header() or udp_gro_udphdr(). skb_gro_header_slow()
> now sets frag0_len to 0 and calls pskb_may_pull(). On a truncated
> packet where hlen > skb->len, this fails without pulling anything.
> That leaves skb_headlen() at 0 and frag0_len at 0.
>
> On the way out, skb_gro_flush_final_remcsum() calls
> skb_gro_remcsum_cleanup(), which does:
>
>         ptr = skb_gro_header(skb, plen, grc->offset);
>
> Before this patch that was served from frag0. Now skb_gro_may_pull()
> fails, and pskb_may_pull(skb, plen) really copies plen bytes into the
> linear area. Here plen = grc->offset + sizeof(u16), which is below
> skb_gro_offset(skb) once the inner headers were pulled. frags[0] is
> advanced by plen, but NAPI_GRO_CB(skb)->frag0 still points at packet
> offset 0.
>
> Since the skb is flushed, dev_gro_receive() ends up in
> gro_try_pull_from_frag0(). That computes
> grow = skb_gro_offset(skb) - skb_headlen(skb) > 0 and calls
> gro_pull_from_frag0():
>
>         memcpy(skb_tail_pointer(skb), NAPI_GRO_CB(skb)->frag0, grow);

Right, this was added in v2 when moving the invalidation before the
pull. After a failed pull, skb_gro_remcsum_cleanup() can pull fewer
bytes than skb_gro_offset(), while frag0 still points to the start
of the packet.

>
> This copies packet bytes 0..grow to skb->data + plen, then advances
> frags[0] by grow again. The skb handed up the stack as GRO_NORMAL
> has its inner headers overwritten with outer header bytes, and the
> real bytes at plen..skb_gro_offset() are lost. A remote sender can
> trigger this with a short encapsulated packet.
>
> gro_pull_from_frag0() assumes frag0 is the current start of frags[0],
> which only holds while skb_headlen() is 0. Should it copy from
> skb_frag_address(&pinfo->frags[0]) instead? Or should
> skb_gro_remcsum_cleanup() and gro_try_pull_from_frag0() handle a
> partially linearized skb in some other way?
>
> [Severity: High]
> This patch didn't introduce this, but since the failure path of
> skb_gro_header_slow() is being changed here: what happens in
> napi_gro_frags() when this pull fails for the Ethernet header?
>
> In net/core/gro.c, napi_frags_skb() takes the slow path and returns
> NULL when the pull fails:
>
> net/core/gro.c:napi_frags_skb() {
>     ...
>         if (unlikely(!skb_gro_may_pull(skb, hlen))) {
>                 eth = skb_gro_header_slow(skb, hlen, 0);
>                 if (unlikely(!eth)) {
>                         net_warn_ratelimited("%s: dropping impossible skb from %s\n",
>                                              __func__, napi->dev->name);
>                         napi_reuse_skb(napi, skb);
>                         return NULL;
>     ...
> }
>
> The caller doesn't check for NULL, though:
>
> net/core/gro.c:napi_gro_frags() {
>         struct sk_buff *skb = napi_frags_skb(napi);
>
>         trace_napi_gro_frags_entry(skb);
>
>         ret = napi_frags_finish(napi, skb, dev_gro_receive(&napi->gro, skb));
>     ...
> }
>
> dev_gro_receive() starts with skb_get_hash_raw(skb) and then reads
> skb->protocol. Can this be a NULL pointer dereference in NAPI softirq
> context? One way to reach it would be skb->len < ETH_HLEN, where
> pskb_may_pull() fails with PKT_TOO_SMALL. Another would be
> __pskb_pull_tail() returning NULL.
>
> napi_gro_frags() used to have an "if (!skb) return GRO_DROP;" check.
> Commit 1d11fa696733 ("net-gro: remove GRO_DROP") removed it on the
> grounds that NULL could only come from a failed napi_get_frags()
> allocation. That reasoning doesn't cover the header pull failure return
> shown above.
>
> The drivers checked so far (tun, r8152, e1000) all enforce a minimum
> frame length before calling napi_gro_frags(). The other callers have
> not been checked.
>
> Should napi_gro_frags() check for a NULL skb again?

I do not think this can happen.

napi_get_frags() allocates the skb with GRO_MAX_HEAD bytes of
tailroom, and these skbs have no frag_list, so __pskb_pull_tail()
can not fail when pulling ETH_HLEN bytes.

pskb_may_pull() can only fail if skb->len < ETH_HLEN, meaning the
driver passed a frame shorter than an Ethernet header, which drivers
must not do. tun, where the length comes from user space, checks it
in tun_get_user().

This is why napi_frags_skb() calls it an "impossible skb". This
could be cleaned up in net-next, but is not a stable fix.

pw-bot: cr
Technical Details
Message-ID: <CAL4Wiiof_AXXF1q8irJVMnqWDcZeZKtghO1V+37=_PX8gGk4_A@mail.gmail.com>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-354939-linux-kernel-netdev=dewy.ru
References: <20261030125955.3107383-3-edumazet@kernel.org> <179362441613.3131.6007536857643093308@kernel.org>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-354939-linux-kernel-netdev=dewy.ru
From: edumazet@kernel.org (Eric Dumazet)
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net v2 2/2] net: gro: invalidate frag0 after a pull
Date: Mon, 2 Nov 2026 17:18:07 +0100
Organization: Usenet Network
Message-ID: <CAL4Wiiof_AXXF1q8irJVMnqWDcZeZKtghO1V+37=_PX8gGk4_A@mail.gmail.com>
References: <20261030125955.3107383-3-edumazet@kernel.org> <179362441613.3131.6007536857643093308@kernel.org>
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Injection-Info: usenet.network;
	logging-data="3039899"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:v2CWLTkemQEE5+VTmNh7rf5vLYo= sha256:+OqlfoPJdPgSPjU5rjq/aPmycWL1z+5w7WqQasuDz7s=
	sha1:JzTmMHy13vVklhjOvYz1K/eVo0o= sha256:bBLdnjlFQd4D++FhvJ+rC/2RGr73FHKS9fmLZy/JkKk=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id 7C20211269E; Tue,  3 Nov 2026 00:55:27 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.401
X-Spam-Status: No, score=-3.401 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1,
	DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=kernel.org
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id ZXKbSvJPpUb9;
	Tue,  3 Nov 2026 00:55:25 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-354939-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114])
	by mail.dewy.ru (Postfix) with ESMTPS id C7E38112697; Tue,  3 Nov 2026 00:55:19 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by tor.lore.kernel.org (Postfix) with ESMTP id C4C9B183F64; Mon,  2 Nov 2026 17:08:22 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1793636315;
	b=yTsBkSFvxq1ggw0gMu2vheRvnPB15dhLuCk8uafbgFegAlasUVew7vwF8UAVdTACva4i
	 8FxuJut6Gq/+2PcX3tuTc9F0FJkW1Zle46qjWD+4Gtx679DEObi4BbHCZCW8ImGcaCBhY
	 S7ht/dJxkuNFy/Zb+fh+8C4VHRECMPIwVdqDv9zECBgI0B6xsOVLyxmuwI6+JJkhYJUgY
	 eDKkDwHTAetZcHnMG6PVkqCwNk3ZipoHm03V5p6Wp1WzYu4+zBtjEcno9eWtOMac6wRKf
	 /acQ4rKCGKTlf/c1xS2DlU7r/yo0ZPWsalv19T88nfnKzEEjhUqdT3/7CaCjLx5cW9A==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793636315;
	h=X-Original-To:Received:Received:DKIM-Signature:Received:
	 X-Forwarded-Encrypted:X-Gm-Message-State:X-Received:X-Mailing-List:
	 List-Id:List-Post:List-Help:List-Subscribe:List-Unsubscribe:
	 List-Owner:Precedence:MIME-Version:References:In-Reply-To:From:Date:
	 X-Gmail-Original-Message-ID:X-Gm-Features:Message-ID:Subject:To:Cc:
	 Content-Type:Content-Transfer-Encoding;
	bh=wxOeynVQGn57hjgx4QIPMlYidyQB2taD5lIeYYJfDTQ=;
	b=fYI86BlPz7TUKlFu0KakbIXRPSxMrtmBLkxKeooogM+Haj4M0bXgUxoNiAGPthBjS+X0
	 lABhK52DgnNHRpKLKLGayk/mYhpTV2Tl2g+5HFhNK7XVzsKlqxseXq+62DnHIHAwdG/bR
	 lYbASWQ1XMXFsBQHqvZug6fs//ib8kkzPbSBO8JtZnuBjb2i9kTjp/Z1V5VrAh9FDEe5t
	 KmTuo8G983Rddq7JKid/dj+AFmd+jgrRyaifnDRehbGb6xDhUPsV7J5zy7nusP8r4Du6c
	 a6OyJ9dynlu+b3/Ah++bHPPSXHwzgGLo82k4pZqnjO3nSUmRE+BKZVjCAdiDVXbROTg==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=aiwSV8pj;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id EE66B608398A;
	Mon,  2 Nov 2026 16:18:34 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key, unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=aiwSV8pj
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1793636309;
	b=xiew1YZBFu//HHbed019TwUh+YG5dCYiDm6s9SXqx/47AnpXTDzJ8HqusdZUkKQ4Rnjy
	 8BmCug4F4BRTm8/A0zb1kqEXiGvzWHbMHM10/hSzcDdx/qdb7WCxR0epSRVbl0hSwaRci
	 DGW0ZC4sshZCAGZCaiuYO5v8YlYcf06r/al8HfQS2EYe/AS3tW1mFUWcrISi/3qiq5Bys
	 y4KrK98aeRaG6TVEboMzhU4j3O08G2IWkJjJFee16i2UoiWFeZ1DyNOy7SxSOzqc8cl8B
	 qcxK+6ehtB7eam0smhPaFZUz9zhz5Y7LtdAWvO+V4oVuQJmxEzxiDXfFcv/77EQycRA==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793636309;
	h=Received:DKIM-Signature:Received:X-Forwarded-Encrypted:
	 X-Gm-Message-State:X-Received:MIME-Version:References:In-Reply-To:
	 From:Date:X-Gmail-Original-Message-ID:X-Gm-Features:Message-ID:
	 Subject:To:Cc:Content-Type:Content-Transfer-Encoding;
	bh=wxOeynVQGn57hjgx4QIPMlYidyQB2taD5lIeYYJfDTQ=;
	b=fCEo1b0dy1WPUG5oIKZsE7TSp+AuVUdu2e6LFj9jmNWfyKMKLoUj53Szx9MSc65GgB49
	 JmoIN/nXZpp7yU2rT39bM2U6Ra0HeQo2Fgiw8KP6clWhDXk9i5HOXOUiPo8aD0bdeTymT
	 MDiT6bql0teS/JAWIEiSLOA4fQfry0YF0Us663rO12UxCpgegZOw7qO8HEDMQW5zWMmfD
	 7CulX4juyx7S0wnqrlTu/32bAMv7148BkPGz7ZHd95lsbsrnD0n40SAyL3u9NR4XLWgCz
	 utAPMhccLN3LE84EEkIeWT9vh9yK1PBDF8lxYD/8GdfSpp1VqbjrwOWhnUNwhHP5x6w==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=aiwSV8pj;
	arc=none smtp.remote-ip=100.103.45.18
X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id BA22E6083996
	for <netdev@vger.kernel.org>; Mon,  2 Nov 2026 16:18:28 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 96D771F00A1A
	for <netdev@vger.kernel.org>; Mon,  2 Nov 2026 16:18:28 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1793636308;
	bh=wxOeynVQGn57hjgx4QIPMlYidyQB2taD5lIeYYJfDTQ=;
	h=References:In-Reply-To:From:Date:Subject:To:Cc;
	b=aiwSV8pjhOneh7pWpESM/lFliOIOPcx151UCGMgOzMErMnbavonl7IMSgCM2yXhz9
	 aEd3r7y2Bm36cQqGmFjg2N576eNALcMFMOR2W/qDRvODCYd5fB9ioLgHreJ+h7GKTA
	 eViiqXmxFJsNdRQMD8QO25Od+6eflrTPzMkaJJslkCtlt8Lm1EI3dP5hTjNc6C9n80
	 3FZIRYQq+uiYkfwfS3piTI//fIeNHPIm1EL7E+Ti5tnnnECi2warS99oi7zETX4Gg9
	 Qk4FAUhzIGzzya+u6gE9EOwzGlx9Wk77uMjC5Xp3rfdDMvQot2hIgRKFYJH/Vc63m0
	 NKnKr9CBX/SkA==
X-Received: by mail-oo1-f52.google.com with SMTP id 006d021491bc7-7143451981fso2309062eaf.3
        for <netdev@vger.kernel.org>; Mon, 02 Nov 2026 08:18:28 -0800 (PST)
X-Forwarded-Encrypted: i=1; AKwUvByBcpYX3iQImhd8Nk1rB0DUnD48VxdaDsUkAnTX23SQe+XIBoxO4cHa0aRWzgLRVKFN2pwe+EE=@vger.kernel.org
X-Gm-Message-State: AFq9FYJVVCo7fX5GdkCbAs1/Dk9qpJ6fVH+zJoT/tAQfpRkFZonkETAm
	0DcY5iygXW+vHCCoG9+rH0zW4td9jA27fSJMTGcvPJl530+XLCV9XsOtE8S0ybGktNalodS9Z/X
	heN7xpBnnLVJU8vIZ1QM6NnIrrtplL38=
X-Received: by 2002:a05:6820:a501:10b0:6de:1457:fe27 with SMTP id
 006d021491bc7-714f29da022mr3867489eaf.57.1793636307818; Mon, 02 Nov 2026
 08:18:27 -0800 (PST)
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list
X-In-Reply-To: <179362441613.3131.6007536857643093308@kernel.org>
X-Gmail-Original-Message-ID: <CAL4Wiiof_AXXF1q8irJVMnqWDcZeZKtghO1V+37=_PX8gGk4_A@mail.gmail.com>
X-Gm-Features: AclHuK-B5hrIDoR7c2h8vnwMbz91vdcjzng1h19upT3oyDEMHA8Uei__0DsgavE
X-Cc: davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, horms@kernel.org, 
	netdev@vger.kernel.org, willemb@google.com, steffen.klassert@secunet.com, 
	tom@herbertland.com, cenzhang@linux.microsoft.com, 
	AutonomousCodeSecurity@microsoft.com, stable@vger.kernel.org