From: Tariq Toukan <tariqt@nvidia.com>
To: Andrew Lunn <andrew+netdev@lunn.ch>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@kernel.org>,
Jakub Kicinski <kuba@kernel.org>, <netdev@vger.kernel.org>,
Paolo Abeni <pabeni@redhat.com>,
Willem de Bruijn <willemb@google.com>
Cc: Andrea Parri <parri.andrea@gmail.com>,
Boris Pismenny <borisp@nvidia.com>,
Cosmin Ratiu <cratiu@nvidia.com>,
Elliot Edmunds <eedmunds@nvidia.com>,
"Gal Pressman" <gal@nvidia.com>,
Jeroen Massar <jmassar@nvidia.com>,
Jianbo Liu <jianbol@nvidia.com>,
Kuniyuki Iwashima <kuniyu@google.com>,
Leon Romanovsky <leon@kernel.org>, <linux-rdma@vger.kernel.org>,
Mark Bloch <mbloch@nvidia.com>,
Patrisious Haddad <phaddad@nvidia.com>,
Raed Salem <raeds@nvidia.com>, Saeed Mahameed <saeedm@nvidia.com>,
Simon Horman <horms@kernel.org>,
Sridhar Samudrala <sridhar.samudrala@intel.com>,
"Steffen Klassert" <steffen.klassert@secunet.com>,
Tariq Toukan <tariqt@nvidia.com>
Subject: [PATCH net 08/10] net/mlx5e: Validate neighbour events before updating IPsec SAs
Date: Thu, 26 Nov 2026 23:56:12 +0200 [thread overview]
Message-ID: <20261126215614.792598-9-tariqt@nvidia.com> (raw)
In-Reply-To: <20261126215614.792598-1-tariqt@nvidia.com>
From: Jianbo Liu <jianbol@nvidia.com>
mlx5e_ipsec_netevent_event() runs for every valid neighbour update on
the global netevent chain. It matched the event by the SA source or
destination address, which is wrong:
- a foreign neighbour (veth, other netdev or netns) sharing the SA
address overwrites the programmed MAC;
- for a routed peer the MAC is taken from the nexthop gateway, whose
address never equals the SA address, so gateway MAC changes are
missed.
Snapshot the resolved nexthop (table, ifindex, key) when its MAC is
read in mlx5e_ipsec_init_macs(), and match events against it. The
neighbour tables are per netns, so matching the table also keeps
neighbours of other namespaces out. The ifindex tells apart one gateway
IP on several netdevs in a netns. Save it only when the nexthop is on
the SA's offload device (xso.dev): xfrm flushes the SA when that device
goes down, so the saved ifindex can never be reused by another device.
For any other device, e.g. a bond slave when the fallback path is used,
save ifindex 0 and match the key on any device in the netns.
This depends on "net/mlx5e: Copy back only replay_esn after an IPsec
ESN update": without it an ESN update replaces nh with a fresh lookup
while the hardware keeps the old MACs, and writes it while
mlx5e_ipsec_netevent_event() reads it without a lock.
Observed on a ConnectX-8 Kubernetes cluster: a pod learns its node IP
with the host veth MAC, that MAC is programmed and the peer drops the
tunnel traffic. Reproduced on ConnectX-7 (fw 28.48.1000):
- neighbour for the peer address added on a dummy netdev: ping loss
100%, 0% with the fix;
- routed peer, wrong gateway MAC corrected after the SA was added:
ping loss 100%, 0% with the fix.
Fixes: 4c24272b4e2b ("net/mlx5e: Listen to ARP events to update IPsec L2 headers in tunnel mode")
Co-developed-by: Elliot Edmunds <eedmunds@nvidia.com>
Signed-off-by: Elliot Edmunds <eedmunds@nvidia.com>
Signed-off-by: Jianbo Liu <jianbol@nvidia.com>
Reviewed-by: Saeed Mahameed <saeedm@nvidia.com>
Reviewed-by: Cosmin Ratiu <cratiu@nvidia.com>
Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
---
.../mellanox/mlx5/core/en_accel/ipsec.c | 48 +++++++++++++------
.../mellanox/mlx5/core/en_accel/ipsec.h | 8 ++++
2 files changed, 41 insertions(+), 15 deletions(-)
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 4084f8a88695..cc75fcb0aa15 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;
+ memcpy(attrs->nh.key, pkey, tbl->key_len);
+}
+
static void mlx5e_ipsec_init_macs(struct mlx5e_ipsec_sa_entry *sa_entry,
struct mlx5_accel_esp_xfrm_attrs *attrs)
{
@@ -263,6 +274,7 @@ static void mlx5e_ipsec_init_macs(struct mlx5e_ipsec_sa_entry *sa_entry,
struct net_device *netdev = sa_entry->dev;
struct xfrm_state *x = sa_entry->x;
struct dst_entry *rt_dst_entry;
+ const struct neigh_table *tbl;
struct flowi4 fl4 = {};
struct flowi6 fl6 = {};
struct neighbour *n;
@@ -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);
dst_release(rt_dst_entry);
neigh_release(n);
return;
@@ -375,13 +388,20 @@ static void mlx5e_ipsec_init_macs(struct mlx5e_ipsec_sa_entry *sa_entry,
else
n = ipv6_neigh_create(netdev, pkey);
attrs->drop = true;
- if (IS_ERR(n))
+ if (IS_ERR(n)) {
+ tbl = addrs->family == AF_INET ?
+ arp_table(dev_net(netdev)) :
+ nd_table(dev_net(netdev));
+ mlx5e_ipsec_set_tnl_nh(sa_entry, attrs, tbl, netdev,
+ pkey);
return;
+ }
neigh_event_send(n, NULL);
} else {
neigh_ha_snapshot(addr, n, netdev);
ether_addr_copy(dst, addr);
}
+ mlx5e_ipsec_set_tnl_nh(sa_entry, attrs, n->tbl, n->dev, n->primary_key);
neigh_release(n);
}
@@ -973,10 +993,20 @@ static void mlx5e_xfrm_free_state(struct net_device *dev, struct xfrm_state *x)
kfree(sa_entry);
}
+static bool
+mlx5e_ipsec_neigh_matches(const struct mlx5e_ipsec_sa_entry *sa_entry,
+ const struct neighbour *n)
+{
+ const struct mlx5_accel_esp_xfrm_attrs *attrs = &sa_entry->attrs;
+
+ return attrs->nh.tbl == n->tbl &&
+ (!attrs->nh.ifindex || attrs->nh.ifindex == n->dev->ifindex) &&
+ !memcmp(attrs->nh.key, n->primary_key, n->tbl->key_len);
+}
+
static int mlx5e_ipsec_netevent_event(struct notifier_block *nb,
unsigned long event, void *ptr)
{
- struct mlx5_accel_esp_xfrm_attrs *attrs;
struct mlx5e_ipsec_netevent_data *data;
struct mlx5e_ipsec_sa_entry *sa_entry;
struct mlx5e_ipsec *ipsec;
@@ -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;
- if (attrs->addrs.family == AF_INET) {
- if (!neigh_key_eq32(n, &attrs->addrs.saddr.a4) &&
- !neigh_key_eq32(n, &attrs->addrs.daddr.a4))
- continue;
- } else {
- if (!neigh_key_eq128(n, &attrs->addrs.saddr.a4) &&
- !neigh_key_eq128(n, &attrs->addrs.daddr.a4))
- continue;
- }
-
data = sa_entry->work->data;
neigh_ha_snapshot(data->addr, n, sa_entry->dev);
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec.h b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec.h
index 6c17bd997a0c..d60c72df0bf1 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec.h
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec.h
@@ -119,6 +119,14 @@ struct mlx5_accel_esp_xfrm_attrs {
u8 dmac[ETH_ALEN];
__be16 dport;
};
+ struct {
+ /* Neighbour tables are per netns, so matching the table
+ * also keeps neighbours of other namespaces out.
+ */
+ const struct neigh_table *tbl;
+ int ifindex;
+ u8 key[sizeof(struct in6_addr)];
+ } nh;
};
enum mlx5_ipsec_cap {
--
2.44.0
next prev parent reply other threads:[~2026-11-26 21:57 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-26 21:56 [PATCH net 00/10] net/mlx5e: Fix IPsec SA races and neighbour handling Tariq Toukan
2026-11-26 21:56 ` [PATCH net 01/10] net/mlx5e: Initialize IPsec XArrays with XA_FLAGS_LOCK_BH Tariq Toukan
2026-11-26 21:56 ` [PATCH net 02/10] net/mlx5e: Stop counting packets dropped by IPsec RX SA rules Tariq Toukan
2026-11-26 21:56 ` [PATCH net 03/10] net/mlx5e: Fix IPsec SA modify/stats update race Tariq Toukan
2026-11-26 21:56 ` [PATCH net 04/10] net/mlx5e: Drain pending hardware event work before freeing IPsec SA Tariq Toukan
2026-11-26 21:56 ` [PATCH net 05/10] net/mlx5e: Drop IPsec tunnel traffic if the neigh cannot be created Tariq Toukan
2026-11-26 21:56 ` [PATCH net 07/10] net/mlx5e: Copy back only replay_esn after an IPsec ESN update Tariq Toukan
2026-11-26 21:56 ` Tariq Toukan [this message]
2026-11-26 21:56 ` [PATCH net 09/10] net/mlx5e: Serialize IPsec netevent MAC snapshots Tariq Toukan
2026-11-26 21:56 ` [PATCH net 10/10] net/mlx5e: Create IPsec flow counters once per SA Tariq Toukan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261126215614.792598-9-tariqt@nvidia.com \
--to=tariqt@nvidia.com \
--cc=andrew+netdev@lunn.ch \
--cc=borisp@nvidia.com \
--cc=cratiu@nvidia.com \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=eedmunds@nvidia.com \
--cc=gal@nvidia.com \
--cc=horms@kernel.org \
--cc=jianbol@nvidia.com \
--cc=jmassar@nvidia.com \
--cc=kuba@kernel.org \
--cc=kuniyu@google.com \
--cc=leon@kernel.org \
--cc=linux-rdma@vger.kernel.org \
--cc=mbloch@nvidia.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=parri.andrea@gmail.com \
--cc=phaddad@nvidia.com \
--cc=raeds@nvidia.com \
--cc=saeedm@nvidia.com \
--cc=sridhar.samudrala@intel.com \
--cc=steffen.klassert@secunet.com \
--cc=willemb@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox