🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #23759

Re: [PATCH net 08/10] net/mlx5e: Validate neighbour events before updating IPsec SAs

#23759
From: netdev-bot+sashiko
Date: Fri, 27 Nov 2026 22:32
171 lines
14973 bytes
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.

Critical: 0 · High: 0 · Medium: 1 (1) · Low: 0 (1)

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).

- [Medium] With nh.ifindex == 0, a foreign neighbour on any device in the
  same netns can still overwrite the hardware MAC.

Pre-existing issues:
- [Medium] In the route-resolved branch of mlx5e_ipsec_init_macs(),
  dst_neigh_lookup() can return an unresolved neighbour with an all-zero…
- [Low] In this commit, the per-SA MAC buffer work->data->addr has no
  synchronization.

--

net/mlx5e: Validate neighbour events before updating IPsec SAs

The patch stops matching neighbour events against the SA source and
destination addresses. Instead it saves a snapshot of the resolved nexthop
(neigh table, ifindex, key) in mlx5e_ipsec_init_macs() and matches events
against that. The ifindex is saved only when the nexthop device is the SA's
offload device (xso.dev); otherwise 0 is saved and any device in the netns
matches.

> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec.c b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec.c
> index 4084f8a88695b..cc75fcb0aa152 100644
> --- a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec.c
> +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec.c
> @@ -256,6 +256,17 @@ static void mlx5e_ipsec_init_limits(struct mlx5e_ipsec_sa_entry *sa_entry,
>  	attrs->lft.numb_rounds_soft = (u64)n;
>  }
>  
> +static void mlx5e_ipsec_set_tnl_nh(struct mlx5e_ipsec_sa_entry *sa_entry,
> +				   struct mlx5_accel_esp_xfrm_attrs *attrs,
> +				   const struct neigh_table *tbl,
> +				   const struct net_device *dev,
> +				   const void *pkey)
> +{
> +	attrs->nh.tbl = tbl;
> +	attrs->nh.ifindex = dev == sa_entry->x->xso.dev ? dev->ifindex : 0;

[Severity: Medium]
If the nexthop device is not xso.dev, nh.ifindex is saved as 0.
mlx5e_ipsec_neigh_matches() then treats 0 as "any device":

    (!attrs->nh.ifindex || attrs->nh.ifindex == n->dev->ifindex) &&

In that case, can a foreign neighbour on another device in the same netns
still overwrite the programmed MAC?

This looks like it always happens in the bonding fallback path.
bond_ipsec_add_sa() calls:

    real_dev->xfrmdev_ops->xdo_dev_state_add(real_dev, xs, extack);

so mlx5e_xfrm_add_state() sets sa_entry->dev to the slave, while xso.dev is
the bond. The neigh: and IS_ERR branches of mlx5e_ipsec_init_macs() pass
that slave netdev, so ifindex 0 is saved. The route branch ends up the same
way whenever the route's output device is not xso.dev.

For example, a container behind a host-side veth could send an ARP request
with sip set to the nexthop IP and tip set to a host address.
arp_process()->neigh_event_ns() then creates a NUD_STALE neighbour on the
host veth and raises NETEVENT_NEIGH_UPDATE.

The table, the wildcard ifindex and the key all match. neigh_ha_snapshot()
copies the attacker's MAC, and the worker reprograms the TX dmac or RX smac.

The commit message documents the ifindex 0 trade-off. However, this looks
like the case it describes as fixed:

  "a foreign neighbour (veth, other netdev or netns) sharing the SA
   address overwrites the programmed MAC"

The only difference is that the nexthop IP is the target instead of the SA
IP.

Would a tighter match close this? For example, n->dev could be accepted
only when it is xso.dev or the nexthop device, instead of using a wildcard.

> +	memcpy(attrs->nh.key, pkey, tbl->key_len);
> +}

[ ... ]

> @@ -360,6 +372,7 @@ static void mlx5e_ipsec_init_macs(struct mlx5e_ipsec_sa_entry *sa_entry,
>  	if (attrs->dir == XFRM_DEV_OFFLOAD_OUT &&
>  	    is_zero_ether_addr(addr))
>  		neigh_event_send(n, NULL);
> +	mlx5e_ipsec_set_tnl_nh(sa_entry, attrs, n->tbl, n->dev, n->primary_key);

[Severity: Medium]
This is a pre-existing issue and was not introduced by this patch. Should
the route branch of mlx5e_ipsec_init_macs() set attrs->drop while the
nexthop MAC is still zero?

dst_neigh_lookup() can return an unresolved neighbour whose ha is all
zeros. For IPv4, the route's neigh_lookup creates one if it is missing.
This branch already checks for that with is_zero_ether_addr(addr).

The zero address is still copied into attrs->dmac (OUT) or attrs->smac
(IN), and attrs->drop stays false.

The TX rule adds MLX5_FLOW_CONTEXT_ACTION_DROP only when attrs->drop is
set. setup_pkt_tunnel_reformat() copies attrs->dmac into the encap header
as is:

    ether_addr_copy(eth_hdr->h_dest, attrs->dmac);

Until the neighbour resolves and the netevent worker reprograms the rule,
could encrypted tunnel frames go out with destination MAC
00:00:00:00:00:00?

The fallback branch sets attrs->drop = true for the same unresolved state.
So does the IS_ERR case added by "net/mlx5e: Drop IPsec tunnel traffic if
the neigh cannot be created".

The problem is still there at the end of the series. This patch does make
the window shorter: gateway events now match, so the rule gets reprogrammed
once the gateway resolves.

>  	dst_release(rt_dst_entry);
>  	neigh_release(n);
>  	return;

[ ... ]

> @@ -988,21 +1018,9 @@ static int mlx5e_ipsec_netevent_event(struct notifier_block *nb,
>  
>  	ipsec = container_of(nb, struct mlx5e_ipsec, netevent_nb);
>  	xa_for_each_marked(&ipsec->sadb, idx, sa_entry, MLX5E_IPSEC_TUNNEL_SA) {
> -		attrs = &sa_entry->attrs;
> -
> -		if (attrs->addrs.family != n->tbl->family)
> +		if (!mlx5e_ipsec_neigh_matches(sa_entry, n))
>  			continue;

[ ... ]

>  		data = sa_entry->work->data;
>  
>  		neigh_ha_snapshot(data->addr, n, sa_entry->dev);

[Severity: Low]
This isn't a bug introduced by this patch, but nothing synchronizes access
to data->addr here. mlx5e_ipsec_netevent_event() writes it from the atomic
netevent chain. mlx5e_ipsec_handle_netdev_event() reads it from the
workqueue and programs the result into hardware:

    ether_addr_copy(attrs->dmac, data->addr);

Can a worker that is already running read a torn MAC while the notifier
rewrites the buffer? With the ifindex 0 wildcard, two notifier calls on
different CPUs could also write the buffer at the same time.

The next patch in the series, "net/mlx5e: Serialize IPsec netevent MAC
snapshots", appears to fix this. It adds a spinlock_t to struct
mlx5e_ipsec_netevent_data and takes spin_lock_bh() around
neigh_ha_snapshot(). The worker then copies data->addr into a local buffer
under the same lock.

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261126215614.792598-1-tariqt%40nvidia.com
Technical Details
Message-ID: <179581873585.3135.8443874889177753516@kernel.org>
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-372970-linux-kernel-netdev=dewy.ru
References: <20261126215614.792598-9-tariqt@nvidia.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-372970-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net 08/10] net/mlx5e: Validate neighbour events before
 updating IPsec SAs
Date: Fri, 27 Nov 2026 22:32:15 +0000
Organization: Usenet Network
Message-ID: <179581873585.3135.8443874889177753516@kernel.org>
References: <20261126215614.792598-9-tariqt@nvidia.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="834417"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:ujv0KXnlcwRabXaxZoNcZaeVB8s= sha256:LFtmxQvytXMF2ZjZRRvHje4VwxrNvVlsKzhCCavuvrE=
	sha1:sJvm4hpZaXa42oT2ccWtdC1meS0= sha256:C1p2aR/Hi+/aggO71U9q4iO0bp2w/Wut7v9LKnPjI20=
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 C5FEE125F68; Sat, 28 Nov 2026 01:32: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 N3wQf6Dm1reE;
	Sat, 28 Nov 2026 01:32:47 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-372970-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 0EC17125F65; Sat, 28 Nov 2026 01:32:38 +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 0099D2F49D; Fri, 27 Nov 2026 22:32:23 +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=1795818743;
	b=eOo+iQrnen9+SWD6Rqsd51ueo3VuaV8dMY3jYldrCbkHDpVZuGDCh/DayFylqf2BCDOG
	 0qscKnVc/rl1uSgUIUv8CxpqQtg0zd8yP/O8/0l3qQuUqhcstKWTM13JOhW/fboFiN2MS
	 v7MmfxptQmBNbEkex74hfSHc2N5u65sYH9wDjbBW3pbn91ccG+FQtIWj3Sv7bAKEDWmBM
	 96/vSMtOtuXR9iVRdpQL5X/1HLe6P/GBFWK6x8kdXhqg+BVAPO16rVZ9q1sQWc49PaGKU
	 fG/dtV0fVPXL+f1ssoTOkpX2aDP81LdLVf6dmbmK6bTMLtyZ5g9hi1Ob/2RL791pM5w==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795818743;
	h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc:
	 Date:Message-ID:In-Reply-To:References:X-sashiko-severity:
	 Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id:
	 List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner:
	 Precedence:MIME-Version;
	bh=Uy3i8hRJJm8f7lYjXs5CtnhHjt88mvlRID2CRQj4Jgs=;
	b=HnmfMniNtVmEL7Gic0Bz2IMI1t9XJvgNqHgUytMZg0EJ0u8n5J9WW6tS1ZWiGQdq4D9o
	 yADffFDfxFmoYWMfQqjRNuNgawtbQImfOF2+ktv6Z9KLN4W6oepTTJFoBlMHqIm9KalmH
	 2nIQJ1foYPpiAPS28OiPJt3LKVQVlmoYhwstLy+9t470JT4e+ng5N2igrIZuhDjlyqlsl
	 NPNAa3AChpwK9CwQRQo+SMrwnkBbwB/OZGlDJbRdyml76InQoQRYDFcDr6bOqq/7lE5Lr
	 oi1fMcy84e5TS+wdEsGfjYqVlttHDDqd97ukXb/1Dv8fL7WRw+XSrrgJj37Vpl48uhw==
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=hm7FCe3H;
	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 C8367606A323;
	Fri, 27 Nov 2026 22:32:23 +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=hm7FCe3H
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=1795818738;
	b=mAu+JviCZ5H5jKdoWgobbhtxt6WmbYe+hwdunvkjUta0Np3/dwrCO4gpTJjRXqlBMOq1
	 ayjkQUmQip09XL6s4cdIZlccM/EpNStz2xeZbqkROwZOfYAfRdeyyokljjSvmcP9cL6f7
	 cFGeGB3yQgiN2hpk4exZBfUVD0JllQE6fJA4R0Y9SouMSvmfQmrlUe+9Fsfy1xzYCuAYE
	 7+HxxNUGBzXYymlxMig0hOl0at46P40aBdSDhR1VyOxr2lho32HbbmbDniACbthPDDiKd
	 zwnsfbcEFqEda7UKUg9scHDZ7eM9nyqiaUa7npVStb47inVrGVXly0PiTYXhrXJHqPg==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795818738;
	h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID:
	 In-Reply-To:References:X-sashiko-severity:Content-Type:
	 Content-Transfer-Encoding:MIME-Version;
	bh=Uy3i8hRJJm8f7lYjXs5CtnhHjt88mvlRID2CRQj4Jgs=;
	b=t1xItxZhBlH+SaPom2nKCHhElpykBAxf6i/pjSP3DXLKycpBt/YBOHd0N8VG98G1DEoy
	 19lyV4S3tEL8KJjIAjn47ryyECVfVWu8ZYritbk7Wtseb/cetZlG4+Zjb8UBRPS8LWSOP
	 3GEj2PkZ5Jqz0sQ+HIItZIhuWXGgX1OsvNMO+O6PzgGln52SwrplBuKHwoTYKAKpSl646
	 BFkxUNwAlANDcfWbwLbwSLfRXzvmtpMHu/CseGwCWUJyZTATeG7lBRY0Rl1yiaM6Xz35K
	 QxRAdJ6wv24KHTF3MXBhXS7DpswIKlQYZnIUPEcOOTLBsxkfWSYZL64yKlnnVPRjCpg==
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=hm7FCe3H;
	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 E4FB9606A31E;
	Fri, 27 Nov 2026 22:32:17 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4CD0A1F00924;
	Fri, 27 Nov 2026 22:32:16 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1795818737;
	bh=Uy3i8hRJJm8f7lYjXs5CtnhHjt88mvlRID2CRQj4Jgs=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=hm7FCe3HTOWDXcyZNYiW66bk/NQGIp82cY6sGUIjnwzSIPwvc8+SsWMk8yUrBAJy9
	 3psQfYtCglb6p9u7Ur6ex0+TW9+tLeFfQff24prUlRKGVGXmEcHyqBeGpTj65lIdhi
	 MCL33DwVvkInRjIWwBm71vs9WuH9g0ui8R9XlG+bXu5tGhJc/4ItGt+Frvr0MhQ3Q5
	 NqtyV9uYSSX/JQIHrFI7TAR1NusU8b/UfUtxHCINTMLy5WZBStGab1y0OjLHHmzgjA
	 0Avz9vidcz0bvNzoPnU5Mj5VQ/u7DvUnw3iq4u/fTi4GG6OJ4E+Ph3hiNjqQEXFwlw
	 F7AA9B3WkxSDg==
X-Cc: andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@kernel.org,
 kuba@kernel.org, netdev@vger.kernel.org, pabeni@redhat.com,
 willemb@google.com, parri.andrea@gmail.com, borisp@nvidia.com,
 cratiu@nvidia.com, eedmunds@nvidia.com, gal@nvidia.com, jmassar@nvidia.com,
 jianbol@nvidia.com, kuniyu@google.com, leon@kernel.org,
 linux-rdma@vger.kernel.org, mbloch@nvidia.com, phaddad@nvidia.com,
 raeds@nvidia.com, saeedm@nvidia.com, horms@kernel.org,
 sridhar.samudrala@intel.com, steffen.klassert@secunet.com
X-In-Reply-To: <20261126215614.792598-9-tariqt@nvidia.com>
X-sashiko-severity: Medium
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