🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #7499

Re: [PATCH net v3 2/6] net/sched: act_mpls: pull the inner Ethernet header after POP

#7499
From: Eric Dumazet
Date: Mon, 26 Oct 2026 13:10
175 lines
15914 bytes
Le lun. 26 oct. 2026 à 11:32, Jamal Hadi Salim <jhs@mojatatu.com> a écrit :
>
> On Mon, Oct 26, 2026 at 5:42 AM Jamal Hadi Salim <jhs@mojatatu.com> wrote:
> >
> > On Sat, Oct 24, 2026 at 10:28 AM Jamal Hadi Salim <jhs@mojatatu.com> wrote:
> > >
> > > The issue:
> > > When the configured inner protocol is ETH_P_TEB, act_mpls POP can leave
> > > the inner Ethernet header in a page fragment after skb_mpls_pop(), either
> > > on an L3 device (mac_len == 0) or chained after act_vlan POP_ETH.  A
> > > following eth_type_trans() can then BUG in __skb_pull().
> > >
> > > The Fix:
> > > After the pop, pull the inner Ethernet header into the linear area only
> > > when p->tcfm_proto is ETH_P_TEB; drop the packet only when that pull
> > > fails.  Other inner protocols (IP, MPLS, ...) have no inner Ethernet
> > > header and must not be required to carry one.  The pull is a no-op when
> > > the header is already linear.
> > >
> > > Conditions to recreate the bug:
> > > - egress tc filter on lo: action vlan pop_eth action mpls pop protocol teb
> > >   (chained), or on an L3 device where mac_len == 0.
> > > - AF_PACKET SOCK_RAW with PACKET_VNET_HDR, hdr_len=28, and a non-linear
> > >   eth / mpls / inner-eth frame.
> > > - The inner header is in page frags; a following eth_type_trans() can BUG
> > >   in __skb_pull().
> > >
> > > Fixes: 2a2ea50870ba ("net: sched: add mpls manipulation actions to TC")
> > > Reported-by: Vega <vega@nebusec.ai>
> > > Link: https://lore.kernel.org/r/40fe2d7dfce13411bfbe9271c0f7c54fb7e88e3b.1782548651.git.bronzed_45_vested@icloud.com/
> > > Link: https://lore.kernel.org/netdev/CAL4WiiqSMdYQYeeW0Fk_GK6ekR4xiS4zPrGKrbB9wZknpqf1-w@mail.gmail.com/
> > > Link: https://lore.kernel.org/netdev/willemdebruijn.kernel.26d1ddb3bd2ae@gmail.com/
> > > Cc: stable@vger.kernel.org
> > > Suggested-by: Jakub Kicinski <kuba@kernel.org>
> > > Suggested-by: Willem de Bruijn <willemdebruijn.kernel@gmail.com>
> > > Suggested-by: Eric Dumazet <edumazet@kernel.org>
> > > Reviewed-by: Victor Nogueira <victor@mojatatu.com>
> > > Signed-off-by: Jamal Hadi Salim <jhs@mojatatu.com>
> > >
> >
> > For the series
> >
> > pw-bot: cr
> >
> > Eric, you are reading this? See the discussion with Willem.
> >
>
> And to be clear, I am suggesting we fix both the producers and consumers.

I don't think we need to touch loopback / eth_type_trans() directly
(that's the per-driver cost I pushed back on for tun). There is a single
natural choke point: the egress fall-through in sch_handle_egress(),
right before the skb goes back to the driver's ndo_start_xmit(). A
device advertises how much link-layer header it needs via
dev->min_header_len, and that is exactly the amount eth_type_trans()
will pull. One check there covers act_vlan, act_mpls with any inner
protocol, act_ife, pedit, and BPF, now and in the future:

diff --git a/net/core/dev.c b/net/core/dev.c
index 1a09e7869118059e92b53e00ed873dfc7485ffc3..ffc8c4c0dfa35fc6eee12bec799809b0e2476270
100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -4757,6 +4757,16 @@ sch_handle_egress(struct sk_buff *skb, int
*ret, struct net_device *dev)
        }
        bpf_net_ctx_clear(bpf_net_ctx);

+       /* Egress actions and programs can pop or shrink the link-layer
+        * header. Drivers expect dev->min_header_len bytes in the linear
+        * area (e.g. eth_type_trans() in loopback_xmit()).
+        */
+       if (unlikely(!pskb_may_pull(skb, dev->min_header_len))) {
+               kfree_skb_reason(skb, SKB_DROP_REASON_PKT_TOO_SMALL);
+               *ret = NET_XMIT_DROP;
+               return NULL;
+       }
+
        return skb;
 }
 #else

It is cheap: only runs when an egress tc/tcx program is attached, it is
an inline compare, and pskb_may_pull() is a no-op when the header is
already linear. For non-Ethernet devices min_header_len is 0 so nothing
changes. It is the same dev->min_header_len gate your act_mirred patch
already uses, just at the other exit point.

I applied *only* this hunk on top of net (none of patches 1, 2) and ran
your three reproducers on lo egress under PANIC_ON_OOPS=y:

  1) vlan pop_eth + bpf skb_adjust_room(-1, BPF_ADJ_ROOM_MAC)
  2) vlan pop_eth + mpls pop protocol ip
  3) vlan pop_eth alone, non-linear inner eth (AF_PACKET+PACKET_VNET_HDR)

Unpatched: all three BUG in eth_type_trans() via loopback_xmit().
With the hunk above: all three are dropped cleanly, no BUG.

So for v4 I'd suggest:
  - drop patches 1 and 2 (the egress check subsumes them, and the
    ETH_P_TEB taste question goes away);
  - keep patch 3 (act_mirred) - that's the redirect boundary, a
    different exit;
  - keep patch 4 (act_ife) - it fixes the egress frame, not just the
    crash;
  - keep patches 5 and 6 (OVS) as-is - OVS actions can't run arbitrary
    BPF, those producer fixes are correct and already reviewed, and they
    can go in independently.

One gap this does not cover: the BPF redirect path
(__bpf_redirect_common() in net/core/filter.c) only checks
mac_header < network_header, so a 1-byte "mac header" still reaches
eth_type_trans() via __dev_forward_skb2()/loopback_xmit(). I haven't
reproduced it yet but it looks like the same bug and the same
dev->min_header_len guard would close it. Can look into that separately.

Thanks,

>
>
> cheers,
> jamal
>
> >
> > > ---
> > > v2 -> v3:
> > >   - drop the pre-pop mac_len gate.  The pull is a no-op when the header
> > >     is already linear, so the gate only avoided a cheap call (Willem de
> > >     Bruijn).
> > >   - restrict the pull to ETH_P_TEB.  act_mpls POP can target IP, MPLS,
> > >     etc.; those inner protocols have no Ethernet header and must not be
> > >     required to carry one (Willem de Bruijn).
> > > ---
> > >  net/sched/act_mpls.c | 3 +++
> > >  1 file changed, 3 insertions(+)
> > >
> > > diff --git a/net/sched/act_mpls.c b/net/sched/act_mpls.c
> > > index 4ea8b2e08c3a..35a6d27f76a4 100644
> > > --- a/net/sched/act_mpls.c
> > > +++ b/net/sched/act_mpls.c
> > > @@ -79,6 +79,9 @@
> > >                 if (skb_mpls_pop(skb, p->tcfm_proto, mac_len,
> > >                                  skb->dev && skb->dev->type == ARPHRD_ETHER))
> > >                         goto drop;
> > > +               if (p->tcfm_proto == htons(ETH_P_TEB) &&
> > > +                   !pskb_may_pull(skb, ETH_HLEN))
> > > +                       goto drop;
> > >                 break;
> > >         case TCA_MPLS_ACT_PUSH:
> > >                 new_lse = tcf_mpls_get_lse(NULL, p, !eth_p_mpls(skb_protocol(skb, true)));
> > > --
> > > 2.43.0
Technical Details
Message-ID: <CAL4WiirtOb9t7DHTk_bawuhAUeKYTQL_p0DvOZDL-HhuKr+h2w@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-351911-linux-kernel-netdev=dewy.ru
References: <ACT-N6N4.v3.r0.20261023200137@mojatatu.com> <ACT-N6N4.v3.r0.20261023200137-1@mojatatu.com> <ACT-N6N4.v3.r0.20261023200137-2@mojatatu.com> <CAM0EoMnjxmnoZ3a4XCB9YERcCwYhYW8-jKw1UZ79YzhFct9+KQ@mail.gmail.com> <CAM0EoMkct9bMMZHPRKh3xZ-L5GTX0SeLdnp_NQd+C_QWspHW8w@mail.gmail.com>

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-351911-linux-kernel-netdev=dewy.ru
From: edumazet@kernel.org (Eric Dumazet)
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net v3 2/6] net/sched: act_mpls: pull the inner Ethernet
 header after POP
Date: Mon, 26 Oct 2026 14:10:20 +0100
Organization: Usenet Network
Message-ID: <CAL4WiirtOb9t7DHTk_bawuhAUeKYTQL_p0DvOZDL-HhuKr+h2w@mail.gmail.com>
References: <ACT-N6N4.v3.r0.20261023200137@mojatatu.com> <ACT-N6N4.v3.r0.20261023200137-1@mojatatu.com>
 <ACT-N6N4.v3.r0.20261023200137-2@mojatatu.com> <CAM0EoMnjxmnoZ3a4XCB9YERcCwYhYW8-jKw1UZ79YzhFct9+KQ@mail.gmail.com>
 <CAM0EoMkct9bMMZHPRKh3xZ-L5GTX0SeLdnp_NQd+C_QWspHW8w@mail.gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Injection-Info: usenet.network;
	logging-data="1312172"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:HmE9lt3NpSw/vNNmwW1Y4R7vnM4= sha256:lJO/Mx4TPXe76P7JPbJ0RSoQURkiTPjfYU9GzUdRfh8=
	sha1:QFXAFOqSbOO8pgb98m1Udtv1t3c= sha256:vuY85vKfAKLcyHoclp222suVfIQRmC7JHR+JqyrKjlY=
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 0AF32125BA8; Mon, 26 Oct 2026 16:16:41 +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 Oo0cJQ_iFIxO;
	Mon, 26 Oct 2026 16:16:37 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=104.64.211.4; helo=sin.lore.kernel.org; envelope-from=netdev+bounces-351911-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 80ECE125BA6; Mon, 26 Oct 2026 16:16:26 +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 DE31625E8C; Mon, 26 Oct 2026 13:10:35 +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=1793020234;
	b=wZRN+NedHihx2GjlNqTPOSRJpbSpLKMepI74CiiKztZWgBRHMpybBM+ufztwpt45Y4EC
	 CeArAqIkUbChz8jrKQkj4EYCdhcWj7DwVH/5Lx5MwX7uBsanSGDxTqq/nbMQRpVgL6rMD
	 6STJNmWlYsC7VbPHVmCk/U87EuB4WaXL4HU1dUuK1MMRVcwYP05hz/IkphztgW8tHlvyH
	 sXhGP2nFHaVdZGK0LHABL1GvQYEDTOi/2b9KY5/SmmNbUpuMJFSk39P/LXMnC1We53jac
	 50o2h7+TlaFdMsFTottnfL9aOibuCtPFKF/CLLSowxKqjv3Uz32tL3tkImcv1JNr00w==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793020234;
	h=X-Original-To:Received:Received:DKIM-Signature:Received:
	 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=ceXZqyDZbjSJNKIpKzybX3IbNeKvCvLhqg+uOKbhDaA=;
	b=e1shnhyArtPzY78TQxGADNPk7WZAUY7bqOKSNJOwkqtWZHy9ActPMiP3VKkCCbCzJNzZ
	 xnUKLQGntBT4Nf190gx29UDKE+eJd69txRrr//KoO9SrQfIb4VZ5VyJ+kH085XsFWFWtc
	 5LovoOWJ0z+zUYWftJoqG+9HdCz7qDii6FSbD4P1Z5Hv13HiqI7jIktKl/LHrWSKjd0SZ
	 /bd03CCWPuMFg0i+XgVnXZGRSbyxBNr6hXaNgcanN3sdgprkbM3jgY3ohQW4mEt81bZVP
	 0+icDqY6ZoTp9vYeT84uwZ6CgEUFR2g3PxJlPIloAU+udE02W5ScJigfxtIa3eqT3nA==
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=IbtJouF2;
	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 A040C606A325;
	Mon, 26 Oct 2026 13:10: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=IbtJouF2
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=1793020233;
	b=bpioOeUhyKAl8+12Y2ztLTfTqhhRDVtatwJXm4sOj7Ss7sAjxRf5WMFzKiN84zMOCs38
	 RI/8vWCIIzBb7WcJz8ToZmrP1lInrnImJHvQGwI7Wz3rFoEuo0LaRH02kXT76ZS0uCeYp
	 fVyQ421Sq4lAViDiMqt/EAUyt4a6P/d3/0h1oeh7tRH/l7vMohrfr2/CaFIj/QiMn2GZf
	 8lhyOM85E1Zk/jLyIPuZ9I4y8SSyQeABGCnFuA0Ynq8LhbhG+oKqhl6pMNSDxYM+ySK+Y
	 t5jRbsO1kS49V0J/t5s7TuewACeaf8B2mA6xIBxsxzk961yF+p5BzYCyaMWNy6gKuWw==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793020233;
	h=Received:DKIM-Signature:Received: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=ceXZqyDZbjSJNKIpKzybX3IbNeKvCvLhqg+uOKbhDaA=;
	b=x820d8lwE14R1biCR5/lOcA897dH3eLllwZltevzJ2s4YXbZch6zTxd6D1DmRizPvoJj
	 bwi4+Y0j6RTVlGIDxuHFlv4t+LCpT1n9z2SgupdGea1Q2fwBDyxGJqqMO0JfGOLIrkmI7
	 kp2AATq1gxOZQg3tlhNilMal61v7zPSgMDss62Jx3Vz7c4Q1vYcSZ5Cvlcll64mZZzZhe
	 cigtygNV6T6tFR5n7IGHEt5eHV5zctkAFPXbNag/f+KHebjlfKFzzxHAre9bORDz7wGpq
	 Qmocii6HpnpPRsweQPt5hz9Rr/RxmBfBkZ8+qUT3RnEgzrHVQiiw3rEWHodsgtMvInQ==
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=IbtJouF2;
	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 74AF1606A31A
	for <netdev@vger.kernel.org>; Mon, 26 Oct 2026 13:10:33 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 134471F031E3
	for <netdev@vger.kernel.org>; Mon, 26 Oct 2026 13:10:33 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1793020233;
	bh=ceXZqyDZbjSJNKIpKzybX3IbNeKvCvLhqg+uOKbhDaA=;
	h=References:In-Reply-To:From:Date:Subject:To:Cc;
	b=IbtJouF23KmF/ujU9ayRLX0fmwvOp9zhCA7pPTY6lkxh4PF1lw+oWj3R2CCQrv4Lm
	 6VMH+n4OBeqdONyO5UGF2ax6CYmIJqG+C37PGqXWKY9qvlCjS5gCzSd2MYlww/Ln1P
	 4DXa039eRpUqH0B5RghAP4S/2dJXbU0VsOJBW46dGXxC2kgdSucBQu3x1DcqMCEV/F
	 qMTU8sJckTJosE7y0M7hPKUhbzkgCWEi6NnDGJKGtZXQRjdrBwYVtOJDrgatWCWMg5
	 eJ2hq6Q20Xtk6rjD0/qtIj/dQCJyE13TtKpkrGWoG67cInfSq5E/g6Sk9rq5OEtO1D
	 DH6TXBWfHOa2g==
X-Received: by mail-oa1-f41.google.com with SMTP id 586e51a60fabf-486f013db83so1101889fac.0
        for <netdev@vger.kernel.org>; Mon, 26 Oct 2026 06:10:33 -0700 (PDT)
X-Gm-Message-State: AFq9FYIXFwHWIkRzK5u/u3p+J1wSkmeF+HVufzN+h9eZ2S4U7PE10qSo
	CFeW4Joyybjqoo8be2maOZaD2VxHv5zui00X/MS2phiPHvHl8NtZKvYnCWLz7SDv0UUUbFo66qu
	XuXGyc7AErtbJ4yzVqdG/FZ643zBL74Q=
X-Received: by 2002:a05:6871:c8e7:b0:455:d4ba:1dc6 with SMTP id
 586e51a60fabf-4a83f1d4ef2mr4799602fac.5.1793020232147; Mon, 26 Oct 2026
 06:10:32 -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: <CAM0EoMkct9bMMZHPRKh3xZ-L5GTX0SeLdnp_NQd+C_QWspHW8w@mail.gmail.com>
X-Gmail-Original-Message-ID: <CAL4WiirtOb9t7DHTk_bawuhAUeKYTQL_p0DvOZDL-HhuKr+h2w@mail.gmail.com>
X-Gm-Features: AclHuK8qH1aV31d0h4LssF8wxy74YlebQMH4xMO3XjkohC_WOp_VXKRU4T1umRQ
X-Cc: netdev@vger.kernel.org, Jiri Pirko <jiri@resnulli.us>, 
	Victor Nogueira <victor@mojatatu.com>, "David S . Miller" <davem@davemloft.net>, 
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>, Simon Horman <horms@kernel.org>, 
	Martin Varghese <martin.varghese@nokia.com>, Pravin B Shelar <pshelar@ovn.org>, Vega <vega@nebusec.ai>, 
	Willem de Bruijn <willemb@google.com>, Willem de Bruijn <willemdebruijn.kernel@gmail.com>, 
	stable@vger.kernel.org