🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #13696

[PATCH net] vxlan: annotate lockless accesses to rdst->remote_ifindex

#13696
From: Eric Dumazet
Date: Tue, 10 Nov 2026 07:22
86 lines
10889 bytes
vxlan_fdb_replace() can update rd->remote_ifindex in place while
the destination entry is visible to concurrent lockless RCU readers:

- vxlan_fdb_info() reads rdst->remote_ifindex during RCU-protected
  FDB dumps and gets.
- vxlan_fdb_switchdev_notifier_info() reads rd->remote_ifindex from
  vxlan_fdb_find_uc().
- vxlan_snoop() reads rdst->remote_ifindex on the RX path.
- vxlan_xmit_one() reads rdst->remote_ifindex on the TX path.

Annotate these accesses with READ_ONCE() and WRITE_ONCE().

Fixes: 906dc186e020 ("vxlan fdb replace an existing entry")
Fixes: 87613de95041 ("vxlan: fix snooping for link-local IPv6 addresses")
Fixes: 49f810f00fa3 ("vxlan: allow multiple VXLANs with same VNI for IPv6 link-local addresses")
Signed-off-by: Eric Dumazet <edumazet@kernel.org>
---
Cc: Andrew Lunn <andrew+netdev@lunn.ch
---
 drivers/net/vxlan/vxlan_core.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/drivers/net/vxlan/vxlan_core.c b/drivers/net/vxlan/vxlan_core.c
index d11028b374721c9f4691254edb61a55c679fd2f2..13bfb1bb11b7be4d4e224d7f892c960512301b2e 100644
--- a/drivers/net/vxlan/vxlan_core.c
+++ b/drivers/net/vxlan/vxlan_core.c
@@ -215,6 +215,8 @@ static int vxlan_fdb_info(struct sk_buff *skb, struct vxlan_dev *vxlan,
 		if (nla_put_u32(skb, NDA_NH_ID, nh_id))
 			goto nla_put_failure;
 	} else if (rdst) {
+		u32 remote_ifindex;
+
 		if (send_ip && vxlan_nla_put_addr(skb, NDA_DST,
 						  &rdst->remote_ip))
 			goto nla_put_failure;
@@ -226,8 +228,9 @@ static int vxlan_fdb_info(struct sk_buff *skb, struct vxlan_dev *vxlan,
 		if (rdst->remote_vni != cfg->vni &&
 		    nla_put_u32(skb, NDA_VNI, be32_to_cpu(rdst->remote_vni)))
 			goto nla_put_failure;
-		if (rdst->remote_ifindex &&
-		    nla_put_u32(skb, NDA_IFINDEX, rdst->remote_ifindex))
+		remote_ifindex = READ_ONCE(rdst->remote_ifindex);
+		if (remote_ifindex &&
+		    nla_put_u32(skb, NDA_IFINDEX, remote_ifindex))
 			goto nla_put_failure;
 	}
 
@@ -300,7 +303,7 @@ static void vxlan_fdb_switchdev_notifier_info(const struct vxlan_dev *vxlan,
 	fdb_info->remote_ip = rd->remote_ip;
 	fdb_info->remote_port = rd->remote_port;
 	fdb_info->remote_vni = rd->remote_vni;
-	fdb_info->remote_ifindex = rd->remote_ifindex;
+	fdb_info->remote_ifindex = READ_ONCE(rd->remote_ifindex);
 	memcpy(fdb_info->eth_addr, fdb->key.eth_addr, ETH_ALEN);
 	fdb_info->vni = fdb->key.vni;
 	fdb_info->offloaded = rd->offloaded;
@@ -569,7 +572,7 @@ static int vxlan_fdb_replace(struct vxlan_fdb *f,
 	rd->remote_ip = *ip;
 	rd->remote_port = port;
 	rd->remote_vni = vni;
-	rd->remote_ifindex = ifindex;
+	WRITE_ONCE(rd->remote_ifindex, ifindex);
 	rd->offloaded = false;
 	return 1;
 }
@@ -1470,7 +1473,7 @@ static enum skb_drop_reason vxlan_snoop(struct net_device *dev,
 			return SKB_DROP_REASON_VXLAN_ENTRY_EXISTS;
 
 		if (likely(vxlan_addr_equal(&rdst->remote_ip, src_ip) &&
-			   rdst->remote_ifindex == ifindex))
+			   READ_ONCE(rdst->remote_ifindex) == ifindex))
 			return SKB_NOT_DROPPED_YET;
 
 		/* Don't migrate static entries, drop packets */
@@ -2442,7 +2445,7 @@ void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev,
 		addr_family = cfg->saddr.sa.sa_family;
 		dst_port = rdst->remote_port ? rdst->remote_port : cfg->dst_port;
 		vni = (rdst->remote_vni) ? : default_vni;
-		ifindex = rdst->remote_ifindex;
+		ifindex = READ_ONCE(rdst->remote_ifindex);
 
 		if (addr_family == AF_INET) {
 			key.u.ipv4.src = cfg->saddr.sin.sin_addr.s_addr;
-- 
2.53.0
Technical Details
Message-ID: <20261110072208.3273638-1-edumazet@kernel.org>
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-359935-linux-kernel-netdev=dewy.ru

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-359935-linux-kernel-netdev=dewy.ru
From: edumazet@kernel.org (Eric Dumazet)
Newsgroups: linux.kernel.netdev
Subject: [PATCH net] vxlan: annotate lockless accesses to rdst->remote_ifindex
Date: Tue, 10 Nov 2026 08:22:08 +0100
Organization: Usenet Network
Message-ID: <20261110072208.3273638-1-edumazet@kernel.org>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="550041"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:H+TrgogEXW9Ptgin6+AD11m8rXA= sha256:tu16mqkMaFzfkSUK1fxHRAGX1wzx0Ei/xTFAnQzkaL4=
	sha1:YYFdTV0EYZUb2nOJOkNDeZUjCXw= sha256:VSs97S8ZERZLvNSP3IJCpE0P6a0HmBLnZEgsu4bcxNE=
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 3FAB4113A6B; Tue, 10 Nov 2026 10:37:50 +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 MoCVNSYjUCnj;
	Tue, 10 Nov 2026 10:37:43 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-359935-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 sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id 92ED5113A69; Tue, 10 Nov 2026 10:37:33 +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 61521A794D; Tue, 10 Nov 2026 07:23:17 +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=1794295334;
	b=KmJiVRmTYEULmlP9/g68xl6YT/T1mkXvgplFkpLCtOxn0xudlYt88P8pdE3C+kj+MiP/
	 dGuDYdwcp0JTUoi/pnNUfsTauFU/JxxlE+TbsMAoVtZ7sL49P3EcXp6JhAXrFuLD1oKjF
	 mtbrVS2stRaQrNzRs4hXhD+wbnornJVIMcAkbe496EImpdlN7ohoPcXW589dwQkw+j6Tg
	 f93PaD+ui6wgge5Bpl5+xAdzKgFjr9hVmrYpDmoEujGSwfeAxozjU349eAS/yubFlWrBW
	 WZmsuuyOchBitiQtwf7r+Rhn2Cyex5LOg2VraRPLAkiJfNu2klntkq8cY8gX108wr+A==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794295334;
	h=X-Original-To:Received:Received:DKIM-Signature: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=zja2eMNGFiEkBZuH4kjMHFhhzIaxVJH4a94KyNvHTDk=;
	b=kIEL+VgTCA+KlMHzEoPz+eDTE9quaOjTbM+aaJz98rTBx9dHcET+1FjFHHHMdPbSsbKn
	 B0/30WL5slkSkLKHxTYZ75yFBTRGErTvC9OtVaoRehNYflu/togYWRIyjQJvNVx1SBh8b
	 X8riLvIiTwnPyxiVnA6auAcSeyUX7uSJLNohyhl6Swcm3P2Ao6lmJt1XNHpmYIb0xupzm
	 Qu+5ZlPEFq0PKTJ5AjSCp1ylX4ksucs09fLXGZIKb49FEbcFlMkLxPQ7mPtClOuHvS3jl
	 kC3XIkms+Q0QcX6SFKeewPieNJfEAP92cHMP5/hOI7Xg6thGZioQ5ycnAVGnDFfvSeA==
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=Zto+oPJQ;
	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 150F9606A84A;
	Tue, 10 Nov 2026 07:22:14 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Zto+oPJQ
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=1794295333;
	b=P31w3PjrSqPT4n/4eI6gjA4FxeHM4j9riktLXoARGsuCRqR88VlnKfDEwNzA3HEOf2LO
	 VjRwDbm2Jq+nDlPQ7vvFDj5vduPmbq243P9y7tN168h/09NyV6Mn07rQ9LdkOUwZbDXCw
	 QsSMah2uCJUA3BSQyeGlneqlLyYmj3DIdEans4fjMmnglUvggugN5Mi6on2WsTwLvqSdY
	 cwNNy5V8h7MKuy/7fhSkSmxtztYM+C3TVrZIvhjduYyKtM8F4hH8Sc26UYfI2hPSquNoZ
	 ANMDL2Uh0maC1nPneAa/cwUYsrH4UJUscXJDwUgv6Qgat5uxOduxmUBnq3QFYe/q2zQ==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794295333;
	h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer:
	 MIME-Version:Content-Transfer-Encoding;
	bh=zja2eMNGFiEkBZuH4kjMHFhhzIaxVJH4a94KyNvHTDk=;
	b=X5Z9o7MHTKZlCxJby+e15zdNNPklFb3DbXB9PgSCxUJFeNTMZG3fSSvGrlzlVOZSUUEI
	 34EphU0iDaniw3nskdfTJlm/+oj9v2R98zlYwb6U2dPUj1+oZBEhAENv8npVvafdz15JO
	 pvavwJCvAcIkPzkkqsi2UpkrQ+594hhF8oDhLsReoXMBNJ05IByWD/L8JGLx9MIC4stiT
	 AcT5J7JmGxgBk6+uSvu8upzVioZuTJdGKJ0zfXzlVQVCkeApXVECCk/8fyVQWInmFjtqX
	 mHCJxkbFkUEkOZ6C8BgIlV+oe/mqnBs7/psA7P7+icxK7DHJbWRk66GEtGa9E50rqNw==
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=Zto+oPJQ;
	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 EA2FB606A325
	for <netdev@vger.kernel.org>; Tue, 10 Nov 2026 07:22:12 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 11BB11F0089F;
	Tue, 10 Nov 2026 07:22:10 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1794295332;
	bh=zja2eMNGFiEkBZuH4kjMHFhhzIaxVJH4a94KyNvHTDk=;
	h=From:To:Cc:Subject:Date;
	b=Zto+oPJQ1+a6Qg95BBg0sfY4N6K1Bts7Uchj9COTnSq4Sc51Nid7AEPcXpS4wFjX1
	 gzmVzD6oDdEq4lIfB09KAo+8awCwAToWjl9AtMGOBc13WtBR2oG/Gs6ol8PMP+0+Cr
	 YHAj2wGrOtav9dNIAFVEjpidDrYeWLzi2uYHykiHxqEEoXzov0PiY082QTlp+SEIi0
	 DhmzHKhKhe0hxvrsFL9bIcH7/IKZLZf8ZRemfqXkpeAuVb/L1GhGiip2wvZTbEv+Zh
	 0c812A/cRLfxSDiGayDYh2z3xzVJmZUlvuFv6HfYQMxhK9+NJjIU3fUgnWLl78T0xv
	 6C/bFLFA+XSeg==
X-Cc: Simon Horman <horms@kernel.org>,
	netdev@vger.kernel.org,
	Eric Dumazet <edumazet@kernel.org>
X-Mailer: git-send-email 2.53.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