From: Cosmin Ratiu <cratiu@nvidia.com>
To: Tariq Toukan <tariqt@nvidia.com>, "kuba@kernel.org" <kuba@kernel.org>
Cc: "parri.andrea@gmail.com" <parri.andrea@gmail.com>,
Boris Pismenny <borisp@nvidia.com>,
"andrew+netdev@lunn.ch" <andrew+netdev@lunn.ch>,
"davem@davemloft.net" <davem@davemloft.net>,
"leon@kernel.org" <leon@kernel.org>,
"edumazet@kernel.org" <edumazet@kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"pabeni@redhat.com" <pabeni@redhat.com>,
"linux-rdma@vger.kernel.org" <linux-rdma@vger.kernel.org>,
Roi Dayan <roid@nvidia.com>, Raed Salem <raeds@nvidia.com>,
Jianbo Liu <jianbol@nvidia.com>,
Carolina Jubran <cjubran@nvidia.com>,
"kees@kernel.org" <kees@kernel.org>,
"fmancera@suse.de" <fmancera@suse.de>,
Dragos Tatulea <dtatulea@nvidia.com>,
Mark Bloch <mbloch@nvidia.com>, Parav Pandit <parav@nvidia.com>,
"netdev@vger.kernel.org" <netdev@vger.kernel.org>,
"steffen.klassert@secunet.com" <steffen.klassert@secunet.com>,
Gal Pressman <gal@nvidia.com>, Saeed Mahameed <saeedm@nvidia.com>,
Patrisious Haddad <phaddad@nvidia.com>
Subject: Re: [PATCH net V2 2/4] net/mlx5e: ipsec: Block eswitch mode changes before accessing priv->ipsec
Date: Tue, 13 Oct 2026 16:02:43 +0000 [thread overview]
Message-ID: <02f705ebc1632c0bdf27348050e923757681a73e.camel@nvidia.com> (raw)
In-Reply-To: <20261007005118.2944625-1-kuba@kernel.org>
On Tue, 2026-10-06 at 17:51 -0700, Jakub Kicinski wrote:
> This is an AI-generated review of your patch. The human sending this
> email has considered the AI review valid, or at least plausible.
> ---
> net/mlx5e: ipsec: Block eswitch mode changes before accessing priv-
> >ipsec
>
> This patch moves the eswitch mode block in mlx5e_xfrm_add_state() so
> it is
> taken before priv->ipsec is read and before the state is validated. A
> concurrent profile change can then no longer free the IPsec context
> while
> it is in use. The acquire placeholder path is still not blocked, and
> mlx5e_xfrm_add_policy() gains a local mdev with a NULL check.
>
> > mlx5e_xfrm_add_state() reads priv->ipsec and validates mode-
> > dependent
> > capabilities before blocking eswitch mode changes. A concurrent
> > profile
> > change can free the saved IPsec context and cause use-after-free.
>
> [ ... ]
>
> > Fixes: 22239eb258bc ("net/mlx5e: Prevent tunnel reformat when
> > tunnel mode not allowed")
>
> [Severity: Medium]
> Is this the right Fixes: tag for the race being closed?
>
> Before 22239eb258bc, mlx5e_xfrm_add_state() had no eswitch mode block
> at
> all. It already read priv->ipsec, stored it in sa_entry, and used it
> for
> validation, SA hardware context creation and
> mlx5e_accel_ipsec_fs_add_rule(). 22239eb258bc added a block after
> that
> read. It did not move an existing block later.
>
> Before 22239eb258bc, the only mode block on this path was the late
> one in
> rx_get()/tx_get() in ipsec_fs.c:
>
> err = mlx5_eswitch_block_mode(mdev, true);
>
> The previous patch in this series ("net/mlx5e: ipsec: Block eswitch
> mode
> changes during policy creation") says that late block comes too late,
> because the table lookup already touches the IPsec context. That
> patch
> tags a5b8ca9471d3 and says "mlx5e_xfrm_add_state() has the same
> race".
>
> With the current tag, could a stable tree that has the packet offload
> state path but not 22239eb258bc take the add_policy half of the fix
> and
> never get this add_state half? Should this patch carry the same tag
> as
> the policy patch?
22239eb258bc is the patch which introduces the incomplete fix which
doesn't close the race. Any series which has it should get this patch
as well. It doesn't make sense to put an older patch as Fixes (e.g. the
one which introduced profile clearing) because this patch couldn't be
taken without the others.
So "Fixes: 22239eb258bc" should be interpreted as "Fixing the
incomplete fix, take this one as well wherever that was taken".
>
> > 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 841ecdc2c4d9e..cf721ef83d597 100644
> > --- a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec.c
> > +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec.c
> > @@ -771,28 +771,44 @@ static int mlx5e_xfrm_add_state(struct
> > net_device *dev,
> > struct xfrm_state *x,
> > struct netlink_ext_ack *extack)
> > {
>
> [ ... ]
>
> > priv = netdev_priv(dev);
> > - if (!priv->ipsec)
> > + mdev = priv->mdev;
> > + if (!mdev || !priv->ipsec)
> > return -EOPNOTSUPP;
> >
> > + if (!is_acq) {
> > + err = mlx5_eswitch_block_mode(mdev, false);
> > + if (err)
> > + return err;
> > + }
>
> [Severity: Low]
> Should these loads of priv->mdev and priv->ipsec use READ_ONCE()?
>
> They happen without a lock, before the mode block is held, so they
> can
> race with a concurrent profile change:
>
> mlx5e_netdev_change_profile()
> mlx5e_priv_cleanup()
> memset(priv, 0, sizeof(*priv));
>
> The !mdev check only covers that window if priv->mdev is loaded
> exactly
> once. With a plain load, the compiler may reload priv->mdev for the
> mlx5_eswitch_block_mode() argument. The reloaded value could be NULL,
> and
> mlx5_eswitch_block_mode() would then dereference dev->priv.eswitch.
> KCSAN
> would also report these as data races.
>
> The same question applies to the new mdev = priv->mdev read in
> mlx5e_xfrm_add_policy().
Will fix.
>
> [ ... ]
>
> > @@ -1262,12 +1275,17 @@ static int mlx5e_xfrm_add_policy(struct
> > xfrm_policy *x,
> > {
> > struct net_device *netdev = x->xdo.dev;
> > struct mlx5e_ipsec_pol_entry *pol_entry;
> > + struct mlx5_core_dev *mdev;
> > struct mlx5e_priv *priv;
> > int err;
> >
> > priv = netdev_priv(netdev);
> > + mdev = priv->mdev;
> > + if (!mdev)
> > + return -EOPNOTSUPP;
> > +
> > /* Block esw mode changes until the policy holds its own
> > block. */
> > - err = mlx5_eswitch_block_mode(priv->mdev, false);
> > + err = mlx5_eswitch_block_mode(mdev, false);
>
> [Severity: Medium]
> The commit message only covers add_state and does not mention this
> new
> NULL check in mlx5e_xfrm_add_policy(). Should the check go into the
> previous patch instead?
>
> The previous patch ("net/mlx5e: ipsec: Block eswitch mode changes
> during
> policy creation") moved mlx5_eswitch_block_mode(priv->mdev, false)
> ahead
> of the !priv->ipsec check. mlx5_eswitch_block_mode() dereferences
> dev->priv.eswitch without checking dev for NULL.
>
> priv->mdev can be NULL while the netdev is still registered. If a
> profile
> change fails and its rollback also fails, mlx5e_priv_cleanup() zeroes
> priv:
>
> mlx5e_priv_cleanup() {
> ...
> /* bail if change profile failed and also rollback failed */
> if (!priv->mdev)
> return;
> ...
> memset(priv, 0, sizeof(*priv));
> }
>
> netdev->xfrmdev_ops is not cleared, so a CAP_NET_ADMIN user who adds
> an
> offloaded policy still reaches:
>
> xfrm_dev_policy_add()
> mlx5e_xfrm_add_policy()
> mlx5_eswitch_block_mode(NULL, false)
>
> At baseline, the !priv->ipsec check returned -EOPNOTSUPP in that
> state.
> With only the previous patch applied, this path oopses.
>
> The previous patch carries Fixes: a5b8ca9471d3 and this one carries
> Fixes: 22239eb258bc. Could the previous patch be backported without
> this
> guard? As posted, the series is also not bisect-safe at the previous
> patch.
Will fix.
Cosmin.
next prev parent reply other threads:[~2026-10-13 16:03 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-30 12:11 [PATCH net V2 0/4] net/mlx5e: Fix offload lifetime and exclusion bugs Tariq Toukan
2026-09-30 12:11 ` [PATCH net V2 1/4] net/mlx5e: ipsec: Block eswitch mode changes during policy creation Tariq Toukan
2026-10-07 0:51 ` Jakub Kicinski
2026-10-13 15:58 ` Cosmin Ratiu
2026-09-30 12:11 ` [PATCH net V2 2/4] net/mlx5e: ipsec: Block eswitch mode changes before accessing priv->ipsec Tariq Toukan
2026-10-07 0:51 ` Jakub Kicinski
2026-10-13 16:02 ` Cosmin Ratiu [this message]
2026-09-30 12:11 ` [PATCH net V2 3/4] net/mlx5e: Serialize TC and IPsec offload exclusion counters Tariq Toukan
2026-09-30 12:11 ` [PATCH net V2 4/4] net/mlx5e: tc: Tie esw & accel blocking refs to the flow's lifetime Tariq Toukan
2026-09-30 12:18 ` [PATCH net V2 0/4] net/mlx5e: Fix offload lifetime and exclusion bugs netdev-bot+sinfo
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=02f705ebc1632c0bdf27348050e923757681a73e.camel@nvidia.com \
--to=cratiu@nvidia.com \
--cc=andrew+netdev@lunn.ch \
--cc=borisp@nvidia.com \
--cc=cjubran@nvidia.com \
--cc=davem@davemloft.net \
--cc=dtatulea@nvidia.com \
--cc=edumazet@kernel.org \
--cc=fmancera@suse.de \
--cc=gal@nvidia.com \
--cc=jianbol@nvidia.com \
--cc=kees@kernel.org \
--cc=kuba@kernel.org \
--cc=leon@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rdma@vger.kernel.org \
--cc=mbloch@nvidia.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=parav@nvidia.com \
--cc=parri.andrea@gmail.com \
--cc=phaddad@nvidia.com \
--cc=raeds@nvidia.com \
--cc=roid@nvidia.com \
--cc=saeedm@nvidia.com \
--cc=steffen.klassert@secunet.com \
--cc=tariqt@nvidia.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
all inboxes | Powered by JetHome®