🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #7241

Re: [PATCH net v3] net: gso: validate transport header before computing segment length

#7241
From: Eric Dumazet
Date: Sun, 25 Oct 2026 19:40
214 lines
17053 bytes
Le dim. 25 oct. 2026 à 17:51, Michael S. Tsirkin <mst@redhat.com> a écrit :
>
> On Sun, Oct 25, 2026 at 04:16:44AM +0000, netdev-bot+sashiko@kernel.org wrote:
> > Thank you for your contribution! Sashiko AI review found 1 potential
> > issue(s) to consider.
> >
> > Critical: 0 · High: 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] The patch is incomplete for the producer its own commit message
> >   names.
> >
> > --
> >
> > net: gso: validate transport header before computing segment length
> >
> > This patch makes the GSO segment length helpers in net/core/gso.c check
> > the TCP header before they read it. If the transport header is unset, or
> > the TCP header is not in the linear data, skb_gso_validate_network_len()
> > and skb_gso_validate_mac_len() now report that the skb does not fit. It
> > also adds two helpers, skb_inner_transport_header_was_set() and
> > skb_transport_header_linear(), to include/linux/skbuff.h.
> >
> > > diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
> > > index d6894f463bf43..11c8b295bd260 100644
> > > --- a/include/linux/skbuff.h
> > > +++ b/include/linux/skbuff.h
> >
> > [ ... ]
> >
> > > @@ -3250,6 +3257,29 @@ static inline int skb_transport_offset(const struct sk_buff *skb)
> > >     return skb_transport_header(skb) - skb->data;
> > >  }
> > >
> > > +/* Is the (inner) transport header, as specified by
> > > + * skb->transport_header/inner_transport_header, in the linear data?
> > > + */
> > > +static inline bool skb_transport_header_linear(const struct sk_buff *skb,
> > > +                                          unsigned int hlen)
> > > +{
> > > +   int thoff;
> > > +
> > > +   if (!skb_transport_header_was_set(skb))
> > > +           return false;
> > > +
> > > +   if (skb->encapsulation) {
> > > +           if (!skb_inner_transport_header_was_set(skb))
> > > +                   return false;
> > > +
> > > +           thoff = skb_inner_transport_offset(skb);
> > > +   } else {
> > > +           thoff = skb_transport_offset(skb);
> > > +   }
> > > +
> > > +   return thoff >= 0 && thoff + hlen <= skb_headlen(skb);
> >
> > [Severity: High]
> >
> > The commit message names bpf_skb_adjust_room() as a way to leave a bad
> > transport header behind. It also says:
> >
> >     Qdisc length estimation has carried a guard against exactly this since
> >
> > Is that guard enough for the bpf_skb_adjust_room() case? In
> > qdisc_pkt_len_segs_init(), the only check is for an unset transport
> > header. Nothing there matches the thoff >= 0 check added here:
> >
> > net/core/dev.c:qdisc_pkt_len_segs_init() {
> >     ...
> >       if (!skb->encapsulation) {
> >               if (unlikely(!skb_transport_header_was_set(skb)))
> >                       return SKB_NOT_DROPPED_YET;
> >               hdr_len = skb_transport_offset(skb);
> >       } else {
> >               hdr_len = skb_inner_transport_offset(skb);
> >       }
> >       /* + transport layer */
> >       if (likely(shinfo->gso_type & (SKB_GSO_TCPV4 | SKB_GSO_TCPV6))) {
> >               const struct tcphdr *th;
> >
> >               if (!pskb_may_pull(skb, hdr_len + sizeof(struct tcphdr)))
> >                       return SKB_DROP_REASON_SKB_BAD_GSO;
> >
> >               th = (const struct tcphdr *)(skb->data + hdr_len);
> >               tlen = __tcp_hdrlen(th);
> >     ...
> > }
> >
> > bpf_skb_net_hdr_pop() moves mac_header and network_header forward. It
> > leaves transport_header where it was, unless it was equal to
> > network_header:
> >
> > net/core/filter.c:bpf_skb_net_hdr_pop() {
> >     ...
> >               skb->mac_header += len;
> >               skb->network_header += len;
> >               if (trans_same)
> >                       skb->transport_header = skb->network_header;
> >     ...
> > }
> >
> > When the DECAP_L4 or DECAP_IPXIP flags remove the last tunnel GSO bit,
> > bpf_skb_net_shrink() also clears skb->encapsulation.
> >
> > Take a locally VXLAN-encapsulated TCP TSO skb whose transport_header
> > points at the outer UDP header. If a tc program calls
> > bpf_skb_adjust_room(skb, -50, BPF_ADJ_ROOM_MAC,
> > BPF_F_ADJ_ROOM_DECAP_L4_UDP | ...), the transport offset ends up at -16
> > and encapsulation is 0.
> >
> > A simpler BPF_ADJ_ROOM_NET shrink of 40 bytes on a plain Ethernet/IPv4
> > TSO skb gives an offset of -6.
> >
> > If the program then redirects to egress with bpf_redirect(), this path
> > runs before any of the validators hardened in this patch:
> >
> > __bpf_tx_skb()
> >   dev_queue_xmit()
> >     __dev_queue_xmit()
> >       qdisc_pkt_len_segs_init()
> >
> > In that function hdr_len is an unsigned int, so -16 becomes 0xfffffff0.
> > hdr_len + sizeof(struct tcphdr) is then truncated to 4 when passed as the
> > unsigned int len argument of pskb_may_pull(), so the pull succeeds.
> >
> > Wouldn't __tcp_hdrlen(th) then read about 4GB past skb->data on 64-bit?
> >
> > Should qdisc_pkt_len_segs_init() get the same check, for example by
> > using skb_transport_header_linear()? If not, could the commit message
> > be changed so it does not say the qdisc path already guards against
> > this?
> >
> > > +}
> > > +
> > >  static inline u32 skb_network_header_len(const struct sk_buff *skb)
> > >  {
> > >     DEBUG_NET_WARN_ON_ONCE(!skb_transport_header_was_set(skb));
> >
> > [ ... ]
> >
>
>
> Indeed. Not nice.
>
> Eric, you seem to have strong opinions about how to fix these
> bugs, so, before I spend time testing: a fix like the below, acceptable?

The report looks valid, but this patches _one_ consumer of a broken
transport_header, not its _producer_.

bpf_skb_net_hdr_pop() adjusts mac_header and network_header, but leaves
transport_header alone unless it was equal to network_header. If the
popped region covers the transport header (BPF_ADJ_ROOM_NET shrink,
or a DECAP_* shrink in BPF_ADJ_ROOM_MAC mode), we keep a stale offset.
It can be negative, or positive and pointing to the wrong bytes.

qdisc_pkt_len_segs_init() is only one reader. TSO drivers
(skb_tcp_all_headers(), tcp_hdr() in ndo_features_check()/ndo_start_xmit())
and the GSO validators would read the same stale offset.
A 'hdr_len < 0' test does not catch the positive case either.

bpf_skb_net_grow() already sets the transport header properly,
the shrink side should do the same. Something like (untested):

diff --git a/net/core/filter.c b/net/core/filter.c
--- a/net/core/filter.c
+++ b/net/core/filter.c
@@ static int bpf_skb_net_hdr_pop(struct sk_buff *skb, u32 off, u32 len)
 {
        bool trans_same = skb->transport_header == skb->network_header;
+       bool trans_popped = false;
        int ret;

+       if (!trans_same && skb_transport_header_was_set(skb)) {
+               int thoff = skb_transport_offset(skb);
+
+               trans_popped = thoff >= (int)off && thoff < (int)(off + len);
+       }
+
        /* Same here, __skb_push()/__skb_pull() pair not needed. */
        ret = bpf_skb_generic_pop(skb, off, len);
        if (likely(!ret)) {
                skb->mac_header += len;
                skb->network_header += len;
                if (trans_same)
                        skb->transport_header = skb->network_header;
+               else if (trans_popped)
+                       skb_set_transport_header(skb, off);
        }

        return ret;
 }

For the decap case, BPF folks might prefer to restore the transport header
from skb->inner_transport_header when skb->encapsulation is cleared.
Technical Details
Message-ID: <CAL4Wiiqk9Gq5=JKk7j=uK9oNbCd7GCcHUm8BmgZ4hGCqjjo45g@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-351603-linux-kernel-netdev=dewy.ru
References: <52b8bfe4ee848aff8ace47752352de486171d45f.1792595507.git.mst@redhat.com> <179290180493.3134.5235549211177646736@kernel.org> <20261025124546-mutt-send-email-mst@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-351603-linux-kernel-netdev=dewy.ru
From: edumazet@kernel.org (Eric Dumazet)
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net v3] net: gso: validate transport header before
 computing segment length
Date: Sun, 25 Oct 2026 20:40:57 +0100
Organization: Usenet Network
Message-ID: <CAL4Wiiqk9Gq5=JKk7j=uK9oNbCd7GCcHUm8BmgZ4hGCqjjo45g@mail.gmail.com>
References: <52b8bfe4ee848aff8ace47752352de486171d45f.1792595507.git.mst@redhat.com>
 <179290180493.3134.5235549211177646736@kernel.org> <20261025124546-mutt-send-email-mst@kernel.org>
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Injection-Info: usenet.network;
	logging-data="1113789"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:NKcxb5vIJfeJffCSAa3cmKtFYWs= sha256:8r0/tOxvPZ2l3BQW6tnrqjnoVul017hqE0Lf3PXuj8o=
	sha1:z3nQV10ThA1nGBJETyjjD1JXK6Y= sha256:XGSwlR+ccV/lKlfiatbXIKx97IrJhcaBq6oBAvulRRc=
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 894F3125B4A; Sun, 25 Oct 2026 22:41:42 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.739
X-Spam-Status: No, score=-3.739 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.339, 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 kQsW2RIQLftH;
	Sun, 25 Oct 2026 22:41:39 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=104.64.211.4; helo=sin.lore.kernel.org; envelope-from=netdev+bounces-351603-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 sin.lore.kernel.org (sin.lore.kernel.org [104.64.211.4])
	by mail.dewy.ru (Postfix) with ESMTPS id 8F4B1125B43; Sun, 25 Oct 2026 22:41:30 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sin.lore.kernel.org (Postfix) with ESMTP id 6156D24078; Sun, 25 Oct 2026 19:41:16 +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=1792957271;
	b=Q2NRuf7x9a3IXMVgz/FTvlXww0sehpmj8nPxOEHmyT0BzZ/sVkfya09WdvDHS2nxC8Fn
	 cOlyDILbn2nii4gaTk1KoFzKFiel7X7YArhdzw6KhVkd7ZHRypHgyOpX23gnDnEqDhoAX
	 6IqNJM9CqwYfiC0JHmOknFk9vBq8hEV5xx/QgXwxGdGAnbyCe3H+yh02qYqM8vlTj3eaM
	 d1PTUTeNUw80a7PtHeJH/Ho0tBAOyy7W6Embj0WqsQwCw2tZWLoqn4+qtz1tBE9+Dq7JS
	 rNI/6KXykcZZQQxTTU2lUXOEmyd4AwB5XYd8OMtGZzj0mIKHCgu5wBE2SCPXqA8QyEA==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1792957271;
	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=/ZjG9Xr/HMX/i7oEyIrYTz+RcRkHVl/XZuBXEaWa+5I=;
	b=OFu4ObLaOm7q+hQiUiIhgH+pl1BPaumttdjyOQxBbQ5X9Wr2qrRfk7qUlLrnPLQDLhoD
	 NmeeKl2LyOmDqs3YGr99EHzjx45O6AtiDo3raldlX56kgngkQYO6Y/24lV2rjVIG76Ivs
	 GH4KkNEu7luftrT9kQBwVfNM88S/vKfkPbBnq4oZuF5CIJZcOak5dJ4g0/n6OOxUAH2SO
	 BkpNa5Eb4btbwHfJCExsNA1yeqyz/1TSEIlqhLRIcZcTBslK7mzuXThKsUO2mHoHwZyNF
	 kH0CWfW1u/5U40GC1NKiivuvrSK/11s2hNBlT3S//EYDhkCandebxt75RjxXCaFqXLw==
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="gpios/A9";
	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 32F30606A332;
	Sun, 25 Oct 2026 19:41:11 +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=gpios/A9
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=1792957270;
	b=AZfKRYEfPf2LH83PKKqLzPgGe+ZYkUCOStF3Zj2reQkKeoWa80fR2U+zQHrIO/eaCuaI
	 A5ae/ixNNpSv4hH4lSIhBke/KUCP2KqljNOMhFJO2KmjJhC6f9OqZTxrpCUZE8Gc+5vuq
	 oE2Ge8FLnMw1qoBhUqls+3Pm+Sqy3jVzBZP4PY8AWXZ6vg3+S+VrUEDV2o2P+WkHxinJp
	 XxK3FjpF3y5KkkafUW9JE7G+ovxGfr8JMemTP2KOzcDjaaI+dWPsNj8BYBI4gYGGk0FoT
	 dOcYbbqS0yVwStPZOtfhWw3jYKPipnJVhBNvycXMtzNLUX7SJ2wxMA4HfZz6O1D5jhQ==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1792957270;
	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=/ZjG9Xr/HMX/i7oEyIrYTz+RcRkHVl/XZuBXEaWa+5I=;
	b=eMCWMQtPFfc37UCtaTIxhECXsl2lv/lSohrkP5KzbAacKTUebvs3HRtZMncjW1m0k7+J
	 0fOMYB1dKkSuhR25crbclQQHcf4ZNjRKb3YWkCalQMTM97LqWaK/OFzMReFqEW3Y/E5RE
	 skz9zxDkq1QgJlIx3QopsyaYdbrren2DTicKzlVg/BGDf5UwzV6F00peD5TUYHytXK3lB
	 6mmHLIc89uIyzj0eY1kyg/bh5W81Gls2VZ/GkCv+yvqcXY6U/mtpYzhHaJRLmH26LVGm/
	 n0fcJklwp4wErQwRCola98Ijg8t0hreeXlob4A3MBwB+tSt9g+0YuLkSmfZ/stSEu3A==
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="gpios/A9";
	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) server-digest SHA256)
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9E5C2606A31A
	for <netdev@vger.kernel.org>; Sun, 25 Oct 2026 19:41:09 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 41A6A1F01828
	for <netdev@vger.kernel.org>; Sun, 25 Oct 2026 19:41:09 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1792957269;
	bh=/ZjG9Xr/HMX/i7oEyIrYTz+RcRkHVl/XZuBXEaWa+5I=;
	h=References:In-Reply-To:From:Date:Subject:To:Cc;
	b=gpios/A9gSMoFlsDvZvnQHGLFQUe/zFMno7I9/mf9JZ0tE+O3UYT2vYbPp/SClDHa
	 YWf976KgiTRSk0fCB1c/WMQ7I/mPg2nJPPMx2c4/vHE5FNsoZPFDFGhyEpBCIVPTIv
	 7F2/Z+GdzFgcb7lAT+BKovQOJBu6b5hAAQDuLUY9ynyUPYi/CrStc8fOzxnScRIxIV
	 EaYRQIfwC/niuZuF2oLYLszDu1bVChXQuGPL5Qgvl2hRDboSbYLuNon2fsvWaIQARY
	 ZiNAWxYqUBvtqbjTEKlRmXSInMw7rw7Wr8KrcZ2lbD9IjgxWO7rTojxuy7wvgucK7x
	 tUMGMz10gOrNw==
X-Received: by mail-oa1-f52.google.com with SMTP id 586e51a60fabf-4a755bbe158so1347521fac.0
        for <netdev@vger.kernel.org>; Sun, 25 Oct 2026 12:41:09 -0700 (PDT)
X-Forwarded-Encrypted: i=1; AKwUvBy56XzmD/aI1yUvWnRLAWdVHuxdUot2AF8CcQeWUujLLBP0k2rFN0KGmPP0kxQqj4dO+sxFa14=@vger.kernel.org
X-Gm-Message-State: AFq9FYIIqxCzWdPL9LSFM9v8NQD1/aAdRdRqCr2jTEGaLwB/gwNaqtSU
	p7I57meFdhjxMfCvysN5Pxoi3dM8Y2/BYkVhomOUcQkx7JgqhWtVcoOH6c4XyfY9I4W4zJNq/9m
	je+b0a1p2ZYW6+cZfNtKan+Jh7vb77ow=
X-Received: by 2002:a05:6870:7014:b0:48f:e0f6:bfef with SMTP id
 586e51a60fabf-4a83fa78ea7mr2212450fac.27.1792957268483; Sun, 25 Oct 2026
 12:41:08 -0700 (PDT)
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: <20261025124546-mutt-send-email-mst@kernel.org>
X-Gmail-Original-Message-ID: <CAL4Wiiqk9Gq5=JKk7j=uK9oNbCd7GCcHUm8BmgZ4hGCqjjo45g@mail.gmail.com>
X-Gm-Features: AclHuK8DDEtJU8OQu3ulpdptWl65cK4vWpgyXH294HkBKAHMWmRkO2A5xVy3Bd4
X-Cc: netdev-bot+sashiko@kernel.org, linux-kernel@vger.kernel.org, 
	willemb@google.com, davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, 
	horms@kernel.org, maxk@qualcomm.com, rusty@rustcorp.com.au, 
	netdev@vger.kernel.org, bpf@vger.kernel.org