🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #27463

[PATCH net-next v2] net: neighbour: skip the stale dst lookup for a redirected skb

#27463
From: Jamal Hadi Salim
Date: Sat, 05 Dec 2026 17:51
114 lines
15556 bytes
Alexei Starovoitov suggested guarding the re-lookup in
neigh_update_process_arp_queue() with the skb's device instead of changing
every producer that steers a packet to another device. This is that guard.

The issue:
neigh_update_process_arp_queue() re-looks the neighbour up from the skb's
dst, because shapers, eql and sch_teql can output a packet through a
different neigh object and it has to be reinjected at the top of the path.
A packet steered to another device by bpf_redirect_neigh(), or by an nft
"fwd ... device" rule, is parked on that device's neighbour while its dst
is still the route that named the device it arrived on. The lookup returns
the neighbour of that route, so the drained frame leaves the parking
device with the arrived-on device's source address and that route's
neighbour as the destination.

The Fix:
Skip the lookup when skb->dev is already neigh->dev; the parking neighbour
is the top-level one in that case and can reinject the packet itself. The
condition never consults dst->dev: teql still takes the lookup because
there skb->dev is the master, not the slave's neigh->dev.

Some context:
A route for one device is a normal thing to find on a frame that leaves
another one; bpf_redirect() and mirred have always produced it, and the
packet has to keep it for the xfrm, tunnel and lwtstate consumers further
down. lwtstate, NBMA tunnels, the route realm and ICMP errors are
unaffected, and the fast path does not change.

Conditions to recreate the bug:
Two network namespaces joined by two veth pairs, va/vb in the first and
va_peer/vb_peer in the second. vb_peer carries no address, so the
neighbour for its side stays unresolved.

    ip netns add ns1
    ip netns add ns2
    ip link add va type veth peer name va_peer
    ip link add vb type veth peer name vb_peer
    ip link set va netns ns1
    ip link set va_peer netns ns2
    ip link set vb netns ns1
    ip link set vb_peer netns ns2
    ip -n ns1 link set va address 02:aa:00:00:00:01
    ip -n ns1 link set vb address 02:bb:00:00:00:01
    ip -n ns1 addr add 10.10.0.1/24 dev va
    ip -n ns1 addr add 10.1.0.1/24 dev vb
    ip -n ns2 addr add 10.10.0.2/24 dev va_peer
    ip -n ns1 link set va up
    ip -n ns1 link set vb up
    ip -n ns2 link set va_peer up
    ip -n ns2 link set vb_peer up
    ip -n ns1 neigh replace 10.10.0.2 lladdr 02:aa:00:00:00:ab dev va nud permanent
    ip netns exec ns1 nft add table netdev t
    ip netns exec ns1 nft "add chain netdev t c { type filter hook egress device va priority 0; policy accept; }"
    ip netns exec ns1 nft add rule netdev t c fwd ip to 10.1.0.2 device vb

One packet to 10.10.0.2 egresses va and the rule steers it through vb to
10.1.0.2, whose neighbour is incomplete, so it is parked there with va's
route. A cls_bpf program returning

    struct bpf_redir_neigh nh = { .nh_family = AF_INET,
                                  .ipv4_nh = htonl(0x0a010002) };

    return bpf_redirect_neigh(vb, &nh, sizeof(nh), 0);

in the same hook produces the same park. Making that neighbour valid
drains the queue:

    ip -n ns1 neigh replace 10.1.0.2 lladdr 02:bb:00:00:00:cd dev vb nud permanent

The single frame that leaves vb_peer carries 02:aa:00:00:00:01 as its
source and 02:aa:00:00:00:ab as its destination instead of vb's own
addresses.

Setup needs CAP_NET_ADMIN in a user namespace of its own (unshare -Urn);
the payload itself does not.  The bpf_redirect_neigh() arm is a
higher-privileged alternative; the nft route above is the minimum.

Fixes: 13a43d94ab02 ("neigh: Convert over to dst_neigh_lookup_skb().")
Link: https://lore.kernel.org/netdev/DMX7RM93TMGR.AXFN4YJ55REF@gmail.com/
Suggested-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Jamal Hadi Salim <jhs@mojatatu.com>

---
v1 -> v2:
- say what the guard actually tests: it is skipped when skb->dev is
already neigh->dev and never consults dst->dev, so teql still takes the
lookup because there skb->dev is the master, not the slave's neigh->dev.
- add the Fixes: tag for the drain's dst-based re-lookup, and carry
Alexei's Acked-by.
---
 net/core/neighbour.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/net/core/neighbour.c b/net/core/neighbour.c
index 887d2e35cd04..219dc89716f8 100644
--- a/net/core/neighbour.c
+++ b/net/core/neighbour.c
@@ -1334,9 +1334,11 @@ static void neigh_update_process_arp_queue(struct neighbour *neigh)
 		 * the packet in the output path.  So what we need to do
 		 * here is re-lookup the top-level neigh in the path so
 		 * we can reinject the packet there.
+		 * When skb->dev is neigh->dev 'neigh' is the top-level one.
+		 * dst can be a route via another device after a redirect.
 		 */
 		n2 = NULL;
-		if (dst &&
+		if (dst && skb->dev != neigh->dev &&
 		    READ_ONCE(dst->obsolete) != DST_OBSOLETE_DEAD) {
 			n2 = dst_neigh_lookup_skb(dst, skb);
 			if (n2)
-- 
2.43.0
Technical Details
Message-ID: <CORE-J9UK.v2.r0.20261205124820-1@mojatatu.com>
Path: mbox-mo1.pugleaf.net!news-wdc.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-378087-linux-kernel-netdev=dewy.ru

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-wdc.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-378087-linux-kernel-netdev=dewy.ru
From: jhs@mojatatu.com (Jamal Hadi Salim)
Newsgroups: linux.kernel.netdev
Subject: [PATCH net-next v2] net: neighbour: skip the stale dst lookup for a redirected skb
Date: Sat,  5 Dec 2026 12:51:14 -0500
Organization: Usenet Network
Message-ID: <CORE-J9UK.v2.r0.20261205124820-1@mojatatu.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="3084100"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:Q4tew6LYDnJzHn9J42WhrVV3mF4= sha256:bXZ9yljd8jqXS2SmUCxJInrCotpIpG+oXGOiNKuD9DI=
	sha1:lHZZpCJsBM9i9/oG4vBpWk1LY+g= sha256:XYIyt+jXto8dSO+odd0QZMmjjQWRJJdha5uN/MsGrMQ=
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 E9FD1117E87; Sat,  5 Dec 2026 20:51:54 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.298
X-Spam-Status: No, score=-3.298 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
	DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.001,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (1024-bit key)
	header.d=mojatatu.com
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 fOSL2l5RiW5j;
	Sat,  5 Dec 2026 20:51:51 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-378087-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=none (p=none dis=none) header.from=mojatatu.com
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id 356D2117E02; Sat,  5 Dec 2026 20:51:43 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sea.lore.kernel.org (Postfix) with ESMTP id 68CC02E9BC; Sat,  5 Dec 2026 17:51:41 +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=1796493100;
	b=LIFd/HpW5l7vCQax/z57GyKguehAEHKWMWJLpzwMkUpG8/i79Q4QLJhJnK3u2RGgoLLk
	 JJtLFA6v7ZlBBQpipnYfs5ZcfqG31wc2gEPZNS9MFQf8QPZgRFEbSv6nIkwdRsw/xl7zK
	 mFYWEkXvVeW8aRdsdjghMwz5fpGaV/CDnFFZ4AUUNbX0NRxqy0Id+gt1bOzSqdedy3Ha7
	 HCtFkchLJyF14PEnWZe+zUFxyHSBZImPmz18sa2dlcl63C0wjAI8tARPSzTdqPb3YDf15
	 kzsUsvBhpUAualsOHz6VucrTWU4W5s4d5OufbUqUt/4VSqY3bt4/LGwcBmf+1u8dn5g==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796493100;
	h=X-Original-To:Received:DMARC-Filter:Received:DKIM-Signature:
	 X-Google-DKIM-Signature:X-Gm-Message-State:X-Gm-Gg:X-Received:
	 Received:From:To:Cc:Subject:Date:Message-ID:X-Mailer:X-Mailing-List:
	 List-Id:List-Post:List-Help:List-Subscribe:List-Unsubscribe:
	 List-Owner:Precedence:MIME-Version:Content-Transfer-Encoding;
	bh=8eiaxcgLiEUSxDjSFjBTtnkB9Y4TnMe+SOhOip1oEBs=;
	b=4LgKME2MA4wb5dzuRLIoArTQWYEPF5PM3bh3wmtF+d51QMC0KnX2E7C8myI4OSVY84gA
	 YFJFSvPbInr5KPoUJZXzE+zSGv/QRksIVqefJvir0afBfwuAXyIDm2mtxRYqyErtHycQM
	 NfVPBwyr93iJPslfi5aLNVqvMFsgXErqfFQwOV5eDJyEZtlt8EedOlCI2Yw6IVCHeE0rO
	 DuBsST8p6J52On6JapryuDDq+6+7h6YKA3DU1L8PalQ+8GEHU80L9N1tEka6vPRdKLZPq
	 AX+7R9nyruZjcEZUNDYMEn3ZnJYzYtxSv9eDF12w+OfF5IfLvPc8gbmVqYoxz/6NetA==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=mojatatu.com header.i=@mojatatu.com header.a=rsa-sha256 header.s=google header.b=ZqAG9fbH;
	dmarc=none header.from=mojatatu.com;
	spf=none smtp.mailfrom=mojatatu.com;
	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 D54DC606A337;
	Sat,  5 Dec 2026 17:51:40 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (1024-bit key) header.d=mojatatu.com header.i=@mojatatu.com header.a=rsa-sha256 header.s=google header.b=ZqAG9fbH
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.222.52
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1796493100;
	b=C7URNVA7qCax5Q+ADom4Coz9OQ05WNpT/+ulBmlfh2a33+jVlTyHA6JSAFIi2m5NSeeE
	 QdGM5sZdNZZR9Ug4VyVBYPAn9HgSQU7dSCTGNZQtB88f13+Ycy5S8Nk1XJcMf1RAPJpYB
	 TIHQJD9tMtO+GhJCX/sE8xo4TuEKK9E9jacCe4oZUr1gY08zEMBQvTqTCrM/KfvPiiRBC
	 8ttpfS9JkJQC6A3+oeyDHEVvPjB4D/JZ5VYer0veng4uHPdlnvjV3JhTrq3XAiz97Edgk
	 PcXER6yruKWZBotN9HIc1mfQ0624ZebHFMgixoMR7/ZN2SKhpeP/4VGJ43oH7qXoKhw==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796493100;
	h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature:
	 X-Gm-Message-State:X-Gm-Gg:X-Received:Received:From:To:Cc:Subject:
	 Date:Message-ID:X-Mailer:MIME-Version:Content-Transfer-Encoding;
	bh=8eiaxcgLiEUSxDjSFjBTtnkB9Y4TnMe+SOhOip1oEBs=;
	b=ImXAbbkUr1qBR6yocpYFPRBolSIL30c54JTgsOLVQcWC2ZKHoHon1nVyx+qyjTsFbK3G
	 IUgcqIRIDzHH+j8ytlfJ2LjF3V/ZI4jfr+zoXnd8ISEElMG4knX+OgU02hNE04oW89oAE
	 ZvCOdYtEpDxyt0MZ7DHPbWC3rXmeeyymH2uNmTYEZJATtLGOXNTikh4HzqmYKgdJUkBFG
	 hvD5HS9DByP7txyD3B9XXO5ZDOt5L1ostZT9wajproi4uOdACEwt52O+78AhOzKEtuB12
	 2VYuvp9G9FPr5iWvBZNVnwdK7jRDjKn+V2tqE8nQytJtL5uTiNCvYnqsocEU18EfOdg==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dmarc=none header.from=mojatatu.com;
	spf=none smtp.mailfrom=mojatatu.com;
	dkim=pass header.d=mojatatu.com header.i=@mojatatu.com header.a=rsa-sha256 header.s=google header.b=ZqAG9fbH;
	arc=none smtp.remote-ip=209.85.222.52
X-Received: from mail-ua1-f52.google.com (mail-ua1-f52.google.com [209.85.222.52])
	(using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7F70F606A322
	for <netdev@vger.kernel.org>; Sat,  5 Dec 2026 17:51:39 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 7F70F606A322
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=mojatatu.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=mojatatu.com
X-Received: by mail-ua1-f52.google.com with SMTP id a1e0cc1a2514c-99e81f5ec91so1037754241.2
        for <netdev@vger.kernel.org>; Sat, 05 Dec 2026 09:51:39 -0800 (PST)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=mojatatu.com; s=google; t=1796493098; x=1797097898; darn=vger.kernel.org;
        h=content-transfer-encoding:mime-version:message-id:date:subject:cc
         :to:from:from:to:cc:subject:date:message-id:reply-to:content-type;
        bh=8eiaxcgLiEUSxDjSFjBTtnkB9Y4TnMe+SOhOip1oEBs=;
        b=ZqAG9fbHCPym1wVRB3ncBCQb1wQ3+n94EbFT4q8iIwDUZUGefGn6y069Ib8VhdrhtQ
         UKqWy2swWRZdUToZnCHrVHPwzaWmy/uJ7gXYyemamTAGnlhHBfhBsXNLwhMJWZcIBjSI
         QL3CGGY5V0y3T9LVYVeWCrDWcwRPX2MRFsZlw=
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20260707; t=1796493098; x=1797097898;
        h=content-transfer-encoding:mime-version:message-id:date:subject:cc
         :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date
         :message-id:reply-to:content-type;
        bh=8eiaxcgLiEUSxDjSFjBTtnkB9Y4TnMe+SOhOip1oEBs=;
        b=xNr0zJ1pJZbyf7QfLttrC2bqtJO8n1mro7vfj4UiuCPNAUe6mRGn6L5zuScUlWJt/Z
         lJvB03kiy/Z0mDw6eFNMzELyjUUVcJ8werSlKt7XtiRqPPDAP4oHqx/o+xknH9vZ30Qw
         vELtLBG0fOAy5S/uOa0s+qVsHeYU91bgWzp6oREgKHCv8WNSFKXa+gwyTeuZRpYEqNrt
         yZAPjTm+AXyP2x0XIiNLWuX6ZsbNxSAFWSojQFc7FoDECbIv3DlQTK4FGSOeyUDOk4Rc
         KgwIDrizgDBW9KSqWIqESo6QwjoR7J+RGHyZsEzzrgzK8EwwawggK/e+mwd4holI9N6H
         u2OQ==
X-Gm-Message-State: AB4q+uHGpOtXBMkifCPN7fJMwIb5D8ryw6NDC+HOH7cMx01KlVV7gMt7
	/T64hTOmvYwu3uM9poyw+YnTZ5UC51eVUUGX/mD+O0wLx7tdYDCYSkfP9j31hry7Q3HByjfL/b9
	5X0u5Ef4t
X-Gm-Gg: AZFdTZf0VXnphmRnhdkFwNmm8wFEH3RBD9a1l9cUdniQw1TYVJmGfWV2U6j5HTSFp1y
	wsEPoSeUhyxl36cjQgRop8VEkEAdbdsJAUadnbZx6IWY43smUD5x3a+fNbSViWlq75CBad1q4W/
	qVO1cFZmjxnJyLvBc3WHT91u5e41TGwpiGiz1O3NTtvLYLOqI8+3lqxUcLNChq7VeyOCy1sy75n
	hh/Nug/IZwNFhEX2Hj9wVyE+MyMjhSI4U5gxkujOpotCmh65Fkve2o2qgh7H3lDP8e19hFTgMKa
	2fLgwdWBtbbxaczWBOlvWP4W3opfH/9ljR4qwH5eZzTk6zlNWABPZq/In/avlZKS0/Lrd1jvLqs
	o4TMf/0SCUBqHqL3PCTxbVRDbnYQxIOuSIfUwArJSttIVFV88SY6MCdYQGhf0q0sC0EWQH5EozT
	bJRI9fj/nTRBXAxK0FhzNubLQURh+7sgsysEE/yGSzK5N7AApW7HphtJl1p1pqvMfk5ht8ag4jR
	lLsbCbMrJdcwvYzj/byqS1zkNuc5J4v+/Dvx6TS/TiLQDsw9gLKEjMji7ChZX4uc8QB4H5jRGpS
	C5wZyqOA6a/XsYIq2rbrfbJN9v/mX0Br+YCCXxy17sV6qwc2v7yXOUyoCoUiM/KdpR1Mr0cOOa1
	zOPDjR4PBebWMZJmXzGY+UOPCbyudPplFCodDwzMaATBqeS4LosiQn8+DwreRiNmpIqOgTf6X
X-Received: by 2002:a05:6122:390f:b0:5e6:82ca:c551 with SMTP id 71dfb90a1353d-5f01d110f31mr5315538e0c.22.1796493098259;
        Sat, 05 Dec 2026 09:51:38 -0800 (PST)
X-Received: from tg.tail33bf8.ts.net ([174.94.23.9])
        by smtp.gmail.com with ESMTPSA id 71dfb90a1353d-5f01d3bf4d6sm3140992e0c.10.2026.12.05.09.51.36
        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
        Sat, 05 Dec 2026 09:51:37 -0800 (PST)
X-Cc: Jamal Hadi Salim <jhs@mojatatu.com>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@kernel.org>,
	Jakub Kicinski <kuba@kernel.org>,
	Paolo Abeni <pabeni@redhat.com>,
	Simon Horman <horms@kernel.org>,
	Willem de Bruijn <willemb@google.com>,
	bpf@vger.kernel.org,
	Alexei Starovoitov <ast@kernel.org>,
	Jiri Pirko <jiri@resnulli.us>,
	Victor Nogueira <victor@mojatatu.com>
X-Mailer: git-send-email 2.43.0
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