๐Ÿš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #8208

Re: [PATCH net] bpf: Fix skb_pull() BUG in __bpf_redirect_neigh()

#8208
From: Eric Dumazet
Date: Wed, 28 Oct 2026 11:40
137 lines
14340 bytes
Le mer. 28 oct. 2026 ร  11:19, <bot+bpf-ci@kernel.org> a รฉcrit :
>
> > bpf: Fix skb_pull() BUG in __bpf_redirect_neigh()
>
> TL;DR: The new skb->mac_len < ETH_HLEN check in __bpf_redirect_neigh() may
> wrongly drop valid packets on tc egress and netkit, where mac_len is often 0;
> a regression that would reach stable.
>
> > diff --git a/net/core/filter.c b/net/core/filter.c
> > index b7ac145b68b1..95a8a728a71d 100644
> > --- a/net/core/filter.c
> > +++ b/net/core/filter.c
>
> [ ... ]
>
> > @@ -2451,10 +2451,14 @@ static int __bpf_redirect_neigh_v4(struct sk_buff *skb, struct net_device *dev,
> >  static int __bpf_redirect_neigh(struct sk_buff *skb, struct net_device *dev,
> >                               struct bpf_nh_params *nh)
> >  {
> > -     struct ethhdr *ethh = eth_hdr(skb);
> > +     struct ethhdr *ethh;
> >
> >       if (unlikely(skb->mac_header >= skb->network_header))
> >               goto out;
> > +     if (unlikely(skb->mac_len < ETH_HLEN ||
> > +                  !pskb_may_pull(skb, ETH_HLEN)))
> > +             goto out;
>
> Does the new skb->mac_len < ETH_HLEN test drop valid packets on tc egress
> and netkit?
>


The bot is right, sorry Jamal, I missed this when looking at your
first version.

skb->mac_len is only set on the receive path. On tc egress (and netkit),
it is usually 0 for locally generated packets, so this would drop all
bpf_redirect_neigh() traffic from egress programs.

In both cases skb->data is at the MAC header when __bpf_redirect_neigh()
runs (sch_handle_ingress() pushes skb->mac_len before skb_do_redirect()),
so you can use skb_network_offset() instead:

if (unlikely(skb_network_offset(skb) < ETH_HLEN ||
     !pskb_may_pull(skb, ETH_HLEN)))
        goto out;

This still rejects the 1-byte header from bpf_skb_change_head(skb, 1, 0),
and also covers the existing mac_header >= network_header test.


> skb->mac_len is only set on the receive path, where
> __netif_receive_skb_core() calls skb_reset_mac_len().  The transmit path
> only calls skb_reset_mac_header() in __dev_queue_xmit(), and nothing in
> ip_finish_output2(), neigh_output(), eth_header(), sch_handle_egress(),
> tcx_run(), cls_bpf_classify() (egress branch), netkit_xmit() or
> netkit_prep_forward() writes mac_len.
>
> A packet built by a local socket starts with mac_len == 0, because
> skbuff_clear() zeroes everything before 'tail', and skb_clone() (used by TCP
> transmit) copies that 0.
>
> For example, with tc egress and a locally generated IPv4/IPv6 packet:
>
> ip_finish_output2()
>   neigh_output()
>     dev_queue_xmit()
>       __dev_queue_xmit()          <- skb_reset_mac_header() only
>         sch_handle_egress()
>           tc_run() / tcx_run()
>             prog returns bpf_redirect_neigh() = TC_ACT_REDIRECT
>               skb_do_redirect()
>                 __bpf_redirect_neigh()
>
> Here mac_header < network_header passes, because an Ethernet header was
> pushed, but mac_len == 0 < ETH_HLEN, so the skb goes to 'out', gets
> kfree_skb() and -ENOTSUPP is returned.
>
> The same happens with netkit:
>
> netkit_xmit()
>   netkit_run()
>     NETKIT_REDIRECT
>       skb_do_redirect()
>         __bpf_redirect_neigh()
>
> with mac_len still 0.  Netkit programs are BPF_PROG_TYPE_SCHED_CLS, and
> tc_cls_act_func_proto() allows BPF_FUNC_redirect_neigh.  Forwarded traffic
> that arrived on a layer 3 device (mac_len 0 on receive) and leaves through
> an Ethernet device's tc egress would be dropped as well.
>
> Before this patch these paths worked, since the Ethernet header is linear
> (dev_hard_header() pushes it into the head) and skb_pull(skb, ETH_HLEN) was
> fine.  bpf_out_neigh_v4/v6() calling sock_confirm_neigh(skb, neigh) also
> suggests the helper is meant to handle locally generated skbs.
>
> Elsewhere the kernel already treats mac_len as unreliable at egress.
> act_mirred uses:
>
>     mac_len = at_ingress ? skb->mac_len : skb_network_offset(skb);
>
> and act_mpls uses skb_network_offset(skb) when not at ingress.
>
> The bpf_redirect_neigh selftests (test_tc_neigh, test_tc_neigh_fib,
> test_tc_dtime) all attach at tc ingress, where mac_len is valid, so they
> would not catch this.
>
> Would testing the real MAC header length work instead, for example
> skb_mac_header_len(skb) < ETH_HLEN (network_header - mac_header), or
> skb_network_offset(skb) < ETH_HLEN with skb->data at the MAC header here?
>
> That would still reject the 1-byte header from the commit message (pop_eth
> followed by bpf_skb_change_head(skb, 1, 0)) without dropping egress and
> netkit traffic.  Since the patch carries Cc: stable, this regression would
> also reach stable kernels.
>
>
> ---
> AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
> See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md
>
> CI run summary: https://github.com/kernel-patches/bpf/actions/runs/40666397744
Technical Details
Message-ID: <CAL4WiioEQsckFKbLz8mnZdK9vG93qEj40Ft8fEfqaNDHyB7DTg@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-352827-linux-kernel-netdev=dewy.ru
References: <bpf_redirect_neigh_short_linear.v1.r0.20261028033717-1@mojatatu.com> <2a0f5ff1d8db81b07fc4b344b8e68e3505fcbf36f72a471d1678b2f1cecd881b@mail.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-352827-linux-kernel-netdev=dewy.ru
From: edumazet@kernel.org (Eric Dumazet)
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net] bpf: Fix skb_pull() BUG in __bpf_redirect_neigh()
Date: Wed, 28 Oct 2026 12:40:23 +0100
Organization: Usenet Network
Message-ID: <CAL4WiioEQsckFKbLz8mnZdK9vG93qEj40Ft8fEfqaNDHyB7DTg@mail.gmail.com>
References: <bpf_redirect_neigh_short_linear.v1.r0.20261028033717-1@mojatatu.com>
 <2a0f5ff1d8db81b07fc4b344b8e68e3505fcbf36f72a471d1678b2f1cecd881b@mail.kernel.org>
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Injection-Info: usenet.network;
	logging-data="1761543"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:nDfCjEhZ6AMFr4OGlC7tV7CaF3M= sha256:K9WCiNkRdgbrcEEOZeRJBT0QXbWLOwCMa8xPl9z5r9A=
	sha1:k3m/1Nn1DqG4PbIVmF8DGYED0IE= sha256:wbD20BNh6MiUCnXdj4KhSwju0/RIb2knj8m1VITNUmY=
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 0C1EB125C35; Wed, 28 Oct 2026 14:45:54 +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 Bu4rHoRmBoVf;
	Wed, 28 Oct 2026 14:45:50 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=104.64.211.4; helo=sin.lore.kernel.org; envelope-from=netdev+bounces-352827-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 5247A125C32; Wed, 28 Oct 2026 14:45:41 +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 65F5C26A8E; Wed, 28 Oct 2026 11:40:38 +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=1793187637;
	b=Oh5GHb5mw8zZ7XjHX0LKgmOyVpsUwHbzWus+S//Oout2SsNG4vwTUw0vlZAGAwlJYy/7
	 GSsWe+HCDnTdz40QXitdZjl2XXEgT19hQVRcJKK4BPxZREYgcIMYgtF00Jy7OoBfJh8tH
	 NdCa93LNHqD4eH9Ith0FKEoZN/cj/dY7eOFZB3nNgpQA9lSxw3PnUg1ECGjzr5xsO0Trw
	 2Ot4QDGi+/LW7eRJHiO0oCs8sjeE9URSddbxbrsX+ZPdAv+Z+sZg2WrO6bS7SkbX4zPRc
	 VKYZ9zi+6rCeO2FUWxEIfRlOEtOxMI9LXAk95S2zc75t1ADGzvxkMVBvtl6vhW0ufUA==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793187637;
	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=obR2UEdD7Tns0Z10i+23V+1SlPg/ENB2qI48XfeG2/k=;
	b=mShnh2a/5Bk7YjCNz+7bPDOL3/xswS8mkmznouqg4bNXj0cCE9IyBhQaqHd2iaEwBJ0L
	 BLNItz9feq5UL4o+wIa72MPkKVuyrcC7duF6geKixAT8ZXWpO9AlkR46oSljGhC1ie/9N
	 7Mq/7W6um2YeGdHIyKRTanDJ1cXGoFr4/GFUxzb4G0qmpgkNHaMp/B3c6HtbptTXaYVUq
	 1R8dL/GlAR5pLJ12CRhZh6//tDeEKykDzEKzHSscFnDIsjF3Om+cprgy/ZclYZsXdd7hJ
	 3bWjhfgIVNcFWoXqmoeh4LY7bQcoM4ZyHeEx70dDPoneNzBQOgpPx+WNuC3CWFJv6vw==
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=ezr0klfN;
	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 3FF38606A327;
	Wed, 28 Oct 2026 11:40:37 +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=ezr0klfN
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=1793187636;
	b=ssxcbPbe7qqXv4BG0GEaQoDAU7E2+PfBzSSogdriNLHba0vA++yeNRcNUPnayCA1ZVgX
	 HbUknUsFCRVb4omGxwMBkjSHClqgP0SD9U7eSdRq7oBkmQi3gUtPFuFo5C+I4cCurq4xo
	 TCz0cVM3py5Avax8tY7iJP51E2rP/PCQkDvaORU0ya7glL18DAPb/G7jq49cMPANJpG4n
	 GFmYf8UVNd3s57mh6jNV383i5Y/Ne0dbV5zdqpqIROPtOtJsl4RVmvPdrJV/K5+I1kM5R
	 ELssuwNYrESMvq38SCAw5m9180TUCwl/JI6zgXIm1kd4KJlh3ZjhVlNCDroG7NzrOsA==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793187636;
	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=obR2UEdD7Tns0Z10i+23V+1SlPg/ENB2qI48XfeG2/k=;
	b=HzaPoFw9MyNDiGnjkml68IsWddYDhADefCd3dHaQO3arWhPq8Yzy30aH/qZqifotkbpS
	 Gg+kxB/S3XRYxcNdmWnzkG/rQQEnTrmhqVH0PPUxnQJGf1zmpgRWwT9mRmG7kKH8pVNYn
	 xraiyqaMhyaQb+nF0UtQQuD6nJWSgJi7P9a/M3WS4Th2mMfVkxzl6uPPLfMZAK9Dt6YGw
	 Q9JuJqyleeDOLiePdg0F/z5bnDw+djbUbSizKkE+UyMaF+fuqG1gW+9b/pCmKyr38EzMb
	 wvWIRHf0HnVQBJFntPlCuHHVJNE7zZbBOUpBJZK1IekSfb1pAEtmNQbzSQxakeFhs5w==
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=ezr0klfN;
	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 1E586606A31D
	for <netdev@vger.kernel.org>; Wed, 28 Oct 2026 11:40:36 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id EF55D1F031E2
	for <netdev@vger.kernel.org>; Wed, 28 Oct 2026 11:40:35 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1793187636;
	bh=obR2UEdD7Tns0Z10i+23V+1SlPg/ENB2qI48XfeG2/k=;
	h=References:In-Reply-To:From:Date:Subject:To:Cc;
	b=ezr0klfNxF7Ey0XZOvc/mzvkQZTo8mbVM9GBw1OHHOFyL2e70AIJTb1T6vgvOtVTa
	 GxQT+GsALQQnX5/tfT1DVyUZErOP0YGFdvnLDVCXPpkvo8VFAwkDwACxtHgMF6PCQ2
	 0j3ws7DbySoBOQjnHXodMtEJ0svIkuvaxO5KBUjmArZO5+W4qaWEO9W42EnA5utcQL
	 YJugRcZ+2ed1hBls5s+ieT9dQu6Wqsd6WiRAnlWcmPaZ4SxtOwvx5Ftyzx57Jf1r3O
	 RbXQ4hCYL2HuWud5IcdSYaFUaXAhtqpbND0lgMHH9JGMGsheW/OyiiNVOSf8gPrAMd
	 nPslxBQGs9FoQ==
X-Received: by mail-oo1-f42.google.com with SMTP id 006d021491bc7-703be215729so474145eaf.1
        for <netdev@vger.kernel.org>; Wed, 28 Oct 2026 04:40:35 -0700 (PDT)
X-Forwarded-Encrypted: i=1; AKwUvBxORasYwr5c/N1H2fKG0tslwyQ4kT8PihCNsLze628ZZLRFYJZ3hshkg5wf1/zdukRRWkPxoPg=@vger.kernel.org
X-Gm-Message-State: AFq9FYIsOYV9JdMSHiYbgB+HplOCclhaeSGboMWqaIkiG4cUUP8Jm7Sj
	DirmJEG0elz/NddUeBLmlkZCo9rLdRjBTHVNKnjYDKPnky6Rb628ysF3Ly6eEQfZ5gGc3G+ExV4
	oviEuk/KERpYA0pZ1+Fhj4Ex/CIW+4kc=
X-Received: by 2002:a05:6820:151a:b0:70b:9806:c916 with SMTP id
 006d021491bc7-713eeb541c3mr1075160eaf.51.1793187635194; Wed, 28 Oct 2026
 04:40:35 -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: <2a0f5ff1d8db81b07fc4b344b8e68e3505fcbf36f72a471d1678b2f1cecd881b@mail.kernel.org>
X-Gmail-Original-Message-ID: <CAL4WiioEQsckFKbLz8mnZdK9vG93qEj40Ft8fEfqaNDHyB7DTg@mail.gmail.com>
X-Gm-Features: AclHuK_CEP5bgRzGigT6P04fyHtIPSbz6OTbsbeDJkrmOaj61eVvdu3lBePlTmM
X-Cc: jhs@mojatatu.com, netdev@vger.kernel.org, bpf@vger.kernel.org, 
	stable@vger.kernel.org, daniel@iogearbox.net, ast@kernel.org, 
	dsahern@gmail.com, kafai@fb.com, martin.lau@linux.dev, 
	john.fastabend@gmail.com, sdf@fomichev.me, andrii@kernel.org, 
	eddyz87@gmail.com, memxor@gmail.com, song@kernel.org, yonghong.song@linux.dev, 
	jolsa@kernel.org, emil@etsalapatis.com, ihor.solodrai@linux.dev, 
	davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, horms@kernel.org, 
	jiri@resnulli.us, victor@mojatatu.com, martin.lau@kernel.org, 
	mason@kernel.org