* [PATCH mlx5-next] net/mlx5: Check device memory pointer before usage
@ 2025-06-30 10:35 Leon Romanovsky
2025-06-30 10:56 ` Michal Swiatkowski
2025-06-30 11:18 ` Dawid Osuchowski
0 siblings, 2 replies; 5+ messages in thread
From: Leon Romanovsky @ 2025-06-30 10:35 UTC (permalink / raw)
To: Jason Gunthorpe
Cc: Stav Aviram, Andrew Lunn, Eric Dumazet, Jakub Kicinski,
linux-rdma, Mark Bloch, netdev, Paolo Abeni, Saeed Mahameed,
Tariq Toukan
From: Stav Aviram <saviram@nvidia.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@nvidia.com>
Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
---
drivers/infiniband/hw/mlx5/dm.c | 2 +-
drivers/net/ethernet/mellanox/mlx5/core/lib/dm.c | 4 ++--
2 files changed, 3 insertions(+), 3 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);
dm = kzalloc(sizeof(*dm), GFP_KERNEL);
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/lib/dm.c b/drivers/net/ethernet/mellanox/mlx5/core/lib/dm.c
index 7c5516b0a844..8115071c34a4 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/lib/dm.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/lib/dm.c
@@ -30,7 +30,7 @@ struct mlx5_dm *mlx5_dm_create(struct mlx5_core_dev *dev)
dm = kzalloc(sizeof(*dm), GFP_KERNEL);
if (!dm)
- return ERR_PTR(-ENOMEM);
+ return NULL;
spin_lock_init(&dm->lock);
@@ -96,7 +96,7 @@ struct mlx5_dm *mlx5_dm_create(struct mlx5_core_dev *dev)
err_steering:
kfree(dm);
- return ERR_PTR(-ENOMEM);
+ return NULL;
}
void mlx5_dm_cleanup(struct mlx5_core_dev *dev)
--
2.50.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH mlx5-next] net/mlx5: Check device memory pointer before usage
2025-06-30 10:35 [PATCH mlx5-next] net/mlx5: Check device memory pointer before usage Leon Romanovsky
@ 2025-06-30 10:56 ` Michal Swiatkowski
2025-07-01 11:33 ` Leon Romanovsky
2025-06-30 11:18 ` Dawid Osuchowski
1 sibling, 1 reply; 5+ messages in thread
From: Michal Swiatkowski @ 2025-06-30 10:56 UTC (permalink / raw)
To: Leon Romanovsky
Cc: Jason Gunthorpe, Stav Aviram, Andrew Lunn, Eric Dumazet,
Jakub Kicinski, linux-rdma, Mark Bloch, netdev, Paolo Abeni,
Saeed Mahameed, Tariq Toukan
On Mon, Jun 30, 2025 at 01:35:53PM +0300, Leon Romanovsky wrote:
> From: Stav Aviram <saviram@nvidia.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@nvidia.com>
> Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
> ---
> drivers/infiniband/hw/mlx5/dm.c | 2 +-
> drivers/net/ethernet/mellanox/mlx5/core/lib/dm.c | 4 ++--
> 2 files changed, 3 insertions(+), 3 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);
>
> dm = kzalloc(sizeof(*dm), GFP_KERNEL);
> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/lib/dm.c b/drivers/net/ethernet/mellanox/mlx5/core/lib/dm.c
> index 7c5516b0a844..8115071c34a4 100644
> --- a/drivers/net/ethernet/mellanox/mlx5/core/lib/dm.c
> +++ b/drivers/net/ethernet/mellanox/mlx5/core/lib/dm.c
> @@ -30,7 +30,7 @@ struct mlx5_dm *mlx5_dm_create(struct mlx5_core_dev *dev)
>
> dm = kzalloc(sizeof(*dm), GFP_KERNEL);
> if (!dm)
> - return ERR_PTR(-ENOMEM);
> + return NULL;
>
> spin_lock_init(&dm->lock);
>
> @@ -96,7 +96,7 @@ struct mlx5_dm *mlx5_dm_create(struct mlx5_core_dev *dev)
> err_steering:
> kfree(dm);
>
> - return ERR_PTR(-ENOMEM);
> + return NULL;
In mlx5_init_once() IS_ERR is used (still). It should be consistent.
Looks like you can use IS_ERR() instead of checking just dm_db, however,
mlx5_dm_create() returns also NULL. I am not sure if it is fine (will
not cause an error in mlx5_init_once()).
Maybe the best is to change a check in mlx5_init_once() from IS_ERROR()
to just !dm.
Thanks
> }
>
> void mlx5_dm_cleanup(struct mlx5_core_dev *dev)
> --
> 2.50.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH mlx5-next] net/mlx5: Check device memory pointer before usage
2025-06-30 10:35 [PATCH mlx5-next] net/mlx5: Check device memory pointer before usage Leon Romanovsky
2025-06-30 10:56 ` Michal Swiatkowski
@ 2025-06-30 11:18 ` Dawid Osuchowski
2025-07-01 11:30 ` Leon Romanovsky
1 sibling, 1 reply; 5+ messages in thread
From: Dawid Osuchowski @ 2025-06-30 11:18 UTC (permalink / raw)
To: Leon Romanovsky, Jason Gunthorpe
Cc: Stav Aviram, Andrew Lunn, Eric Dumazet, Jakub Kicinski,
linux-rdma, Mark Bloch, netdev, Paolo Abeni, Saeed Mahameed,
Tariq Toukan
On 2025-06-30 12:35 PM, Leon Romanovsky wrote:
> From: Stav Aviram <saviram@nvidia.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@nvidia.com>
> Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
Given this is a fix, the net tree should be targeted instead of next.
Best regards,
Dawid
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH mlx5-next] net/mlx5: Check device memory pointer before usage
2025-06-30 11:18 ` Dawid Osuchowski
@ 2025-07-01 11:30 ` Leon Romanovsky
0 siblings, 0 replies; 5+ messages in thread
From: Leon Romanovsky @ 2025-07-01 11:30 UTC (permalink / raw)
To: Dawid Osuchowski
Cc: Jason Gunthorpe, Stav Aviram, Andrew Lunn, Eric Dumazet,
Jakub Kicinski, linux-rdma, Mark Bloch, netdev, Paolo Abeni,
Saeed Mahameed, Tariq Toukan
On Mon, Jun 30, 2025 at 01:18:22PM +0200, Dawid Osuchowski wrote:
> On 2025-06-30 12:35 PM, Leon Romanovsky wrote:
> > From: Stav Aviram <saviram@nvidia.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@nvidia.com>
> > Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
>
> Given this is a fix, the net tree should be targeted instead of next.
This fix is mainly for RDMA and changes in net-next are by-product. The
current target is mlx5-next.
Thanks
>
> Best regards,
> Dawid
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH mlx5-next] net/mlx5: Check device memory pointer before usage
2025-06-30 10:56 ` Michal Swiatkowski
@ 2025-07-01 11:33 ` Leon Romanovsky
0 siblings, 0 replies; 5+ messages in thread
From: Leon Romanovsky @ 2025-07-01 11:33 UTC (permalink / raw)
To: Michal Swiatkowski
Cc: Jason Gunthorpe, Stav Aviram, Andrew Lunn, Eric Dumazet,
Jakub Kicinski, linux-rdma, Mark Bloch, netdev, Paolo Abeni,
Saeed Mahameed, Tariq Toukan
On Mon, Jun 30, 2025 at 12:56:46PM +0200, Michal Swiatkowski wrote:
> On Mon, Jun 30, 2025 at 01:35:53PM +0300, Leon Romanovsky wrote:
> > From: Stav Aviram <saviram@nvidia.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@nvidia.com>
> > Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
> > ---
> > drivers/infiniband/hw/mlx5/dm.c | 2 +-
> > drivers/net/ethernet/mellanox/mlx5/core/lib/dm.c | 4 ++--
> > 2 files changed, 3 insertions(+), 3 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);
> >
> > dm = kzalloc(sizeof(*dm), GFP_KERNEL);
> > diff --git a/drivers/net/ethernet/mellanox/mlx5/core/lib/dm.c b/drivers/net/ethernet/mellanox/mlx5/core/lib/dm.c
> > index 7c5516b0a844..8115071c34a4 100644
> > --- a/drivers/net/ethernet/mellanox/mlx5/core/lib/dm.c
> > +++ b/drivers/net/ethernet/mellanox/mlx5/core/lib/dm.c
> > @@ -30,7 +30,7 @@ struct mlx5_dm *mlx5_dm_create(struct mlx5_core_dev *dev)
> >
> > dm = kzalloc(sizeof(*dm), GFP_KERNEL);
> > if (!dm)
> > - return ERR_PTR(-ENOMEM);
> > + return NULL;
> >
> > spin_lock_init(&dm->lock);
> >
> > @@ -96,7 +96,7 @@ struct mlx5_dm *mlx5_dm_create(struct mlx5_core_dev *dev)
> > err_steering:
> > kfree(dm);
> >
> > - return ERR_PTR(-ENOMEM);
> > + return NULL;
>
> In mlx5_init_once() IS_ERR is used (still). It should be consistent.
> Looks like you can use IS_ERR() instead of checking just dm_db, however,
> mlx5_dm_create() returns also NULL. I am not sure if it is fine (will
> not cause an error in mlx5_init_once()).
>
> Maybe the best is to change a check in mlx5_init_once() from IS_ERROR()
> to just !dm.
We need to remove IS_ERR() check from all places.
>
> Thanks
>
> > }
> >
> > void mlx5_dm_cleanup(struct mlx5_core_dev *dev)
> > --
> > 2.50.0
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-07-01 11:33 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-30 10:35 [PATCH mlx5-next] net/mlx5: Check device memory pointer before usage Leon Romanovsky
2025-06-30 10:56 ` Michal Swiatkowski
2025-07-01 11:33 ` Leon Romanovsky
2025-06-30 11:18 ` Dawid Osuchowski
2025-07-01 11:30 ` Leon Romanovsky
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).