From: Jianbo Liu <jianbol@nvidia.com>
To: netdev-bot+sashiko@kernel.org, tariqt@nvidia.com
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, 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
Subject: Re: [PATCH net 08/10] net/mlx5e: Validate neighbour events before updating IPsec SAs
Date: Mon, 30 Nov 2026 18:01:38 +0800 [thread overview]
Message-ID: <2646b595-be84-4c0a-8cfb-87e0b64630e5@nvidia.com> (raw)
In-Reply-To: <179581873585.3135.8443874889177753516@kernel.org>
On 11/28/2026 6:32 AM, netdev-bot+sashiko@kernel.org wrote:
> 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.
>
This idea is possible. But it closes the bond case only. For a
device that only carries the route it leaves one corner: nothing
removes the SA with that device, and its ifindex can later go to a
new device. That is why the patch saves no ifindex for such a
device. Closing that corner as well needs a netdevice notifier, or
a new route lookup on each event. It can be done as a separate
patch on top of this fix.
>> + 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.
>
next prev parent reply other threads:[~2026-11-30 10:01 UTC|newest]
Thread overview: 22+ 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-27 22:32 ` netdev-bot+sashiko
2026-11-26 21:56 ` [PATCH net 02/10] net/mlx5e: Stop counting packets dropped by IPsec RX SA rules Tariq Toukan
2026-11-27 22:32 ` netdev-bot+sashiko
2026-11-30 6:57 ` Jianbo Liu
2026-11-26 21:56 ` [PATCH net 03/10] net/mlx5e: Fix IPsec SA modify/stats update race Tariq Toukan
2026-11-27 22:32 ` netdev-bot+sashiko
2026-11-30 7:14 ` Jianbo Liu
2026-11-26 21:56 ` [PATCH net 04/10] net/mlx5e: Drain pending hardware event work before freeing IPsec SA Tariq Toukan
2026-11-27 22:32 ` netdev-bot+sashiko
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-27 22:32 ` netdev-bot+sashiko
2026-11-30 7:40 ` Jianbo Liu
2026-11-26 21:56 ` [PATCH net 06/10] net/mlx5e: Fix IPv6 neighbour fallback for IPsec tunnels 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 ` [PATCH net 08/10] net/mlx5e: Validate neighbour events before updating IPsec SAs Tariq Toukan
2026-11-27 22:32 ` netdev-bot+sashiko
2026-11-30 10:01 ` Jianbo Liu [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
2026-11-27 22:32 ` netdev-bot+sashiko
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=2646b595-be84-4c0a-8cfb-87e0b64630e5@nvidia.com \
--to=jianbol@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=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-bot+sashiko@kernel.org \
--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=tariqt@nvidia.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