[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250702140735.GE41770@horms.kernel.org>
Date: Wed, 2 Jul 2025 15:07:35 +0100
From: Simon Horman <horms@...nel.org>
To: Leon Romanovsky <leon@...nel.org>
Cc: Jason Gunthorpe <jgg@...dia.com>, Stav Aviram <saviram@...dia.com>,
Andrew Lunn <andrew+netdev@...n.ch>,
Eric Dumazet <edumazet@...gle.com>,
Jakub Kicinski <kuba@...nel.org>, linux-rdma@...r.kernel.org,
Mark Bloch <markb@...lanox.com>, netdev@...r.kernel.org,
Paolo Abeni <pabeni@...hat.com>, Saeed Mahameed <saeedm@...dia.com>,
Tariq Toukan <tariqt@...dia.com>,
Michal Swiatkowski <michal.swiatkowski@...ux.intel.com>
Subject: Re: [PATCH mlx5-next v1] net/mlx5: Check device memory pointer
before usage
On Wed, Jul 02, 2025 at 11:28:47AM +0300, Leon Romanovsky wrote:
> On Tue, Jul 01, 2025 at 08:38:58PM +0100, Simon Horman wrote:
> > On Tue, Jul 01, 2025 at 03:08:12PM +0300, Leon Romanovsky wrote:
> > > From: Stav Aviram <saviram@...dia.com>
> > >
> > > Add a NULL check before accessing device memory to prevent a crash if
> > > dev->dm allocation in mlx5_init_once() fails.
> > >
> > > Fixes: c9b9dcb430b3 ("net/mlx5: Move device memory management to mlx5_core")
> > > Signed-off-by: Stav Aviram <saviram@...dia.com>
> > > Signed-off-by: Leon Romanovsky <leonro@...dia.com>
> > > ---
> > > Changelog:
> > > v1:
> > > * Removed extra IS_ERR(dm) check.
> > > v0:
> > > https://lore.kernel.org/all/e389fa6ef075af1049cd7026b912d736ebe3ad23.1751279408.git.leonro@nvidia.com
> > > ---
> > > drivers/infiniband/hw/mlx5/dm.c | 2 +-
> > > drivers/net/ethernet/mellanox/mlx5/core/lib/dm.c | 4 ++--
> > > drivers/net/ethernet/mellanox/mlx5/core/main.c | 2 +-
> > > 3 files changed, 4 insertions(+), 4 deletions(-)
> > >
> > > diff --git a/drivers/infiniband/hw/mlx5/dm.c b/drivers/infiniband/hw/mlx5/dm.c
> > > index b4c97fb62abf..9ded2b7c1e31 100644
> > > --- a/drivers/infiniband/hw/mlx5/dm.c
> > > +++ b/drivers/infiniband/hw/mlx5/dm.c
> > > @@ -282,7 +282,7 @@ static struct ib_dm *handle_alloc_dm_memic(struct ib_ucontext *ctx,
> > > int err;
> > > u64 address;
> > >
> > > - if (!MLX5_CAP_DEV_MEM(dm_db->dev, memic))
> > > + if (!dm_db || !MLX5_CAP_DEV_MEM(dm_db->dev, memic))
> > > return ERR_PTR(-EOPNOTSUPP);
> >
> > nit: -EOPNOTSUPP doesn't feel like the right error code
> > in the !dm_db case.
>
> Why? This error is returned to the user through mlx5_ib_alloc_dm().
Because, as I understand things, such a case would be due to a memory
allocation failure, not by the device not supporting a feature.
handle_alloc_dm_memic() already returns ERR_PTR(-ENOMEM) if kzalloc() fails.
I'd suggest doing so for the !dm_db case too.
But I don't feel particularly strongly about this.
Powered by blists - more mailing lists