net/mlx5: Check device memory pointer before usage
Subsystems (5)
PATCH 1/1 net/mlx5: Check device memory pointer before usage
From: Stav Aviram <[email protected]>
Add a NULL check before accessing device memory to prevent a crash if dev->dm allocation in mlx5_init_once() fails.
---
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(-)
drivers/infiniband/hw/mlx5/dm.c +1 -1
@@ -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 );
drivers/net/ethernet/mellanox/mlx5/core/lib/dm.c +2 -2
@@ -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)
drivers/net/ethernet/mellanox/mlx5/core/main.c +1 -1
@@ -1102,7 +1102,7 @@ static int mlx5_init_once(struct mlx5_core_dev *dev) } dev->dm =mlx5_dm_create (dev); -if (IS_ERR (dev->dm)) +if (!dev->dm)mlx5_core_warn (dev,"Failed to init device memory %ld\n" ,PTR_ERR (dev->dm)); dev->tracer =mlx5_fw_tracer_create (dev);
Signature · 1 line
2.50.0
Simon Horman
reviewerQuoted 25 lines · Leon Romanovsky
From: Stav Aviram <[email protected]>
Add a NULL check before accessing device memory to prevent a crash if
dev->dmallocation inmlx5_init_once()fails.Fixes c9b9dcb430b3 ("net/mlx5: Move device memory management to mlx5_core")Signed-off-by Stav Aviram <[email protected]>Signed-off-by Leon Romanovsky <[email protected]>---
Changelog:
v1:
* Removed extraIS_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(-)drivers/infiniband/hw/mlx5/dm.c +0
-0
drivers/infiniband/hw/mlx5/dm.c static struct ib_dm *handle_alloc_dm_memic(struct ib_ucontext *ctx, · line 286
Quoted 6 lines
drivers/infiniband/hw/mlx5/dm.c +1
-1@@ -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.
Quoted 2 lines
drivers/infiniband/hw/mlx5/dm.c +0
-0dm =kzalloc (sizeof (*dm),GFP_KERNEL );
...
Quoted 29 lines · Simon Horman
Quoted 28 lines · Leon Romanovsky
From: Stav Aviram <[email protected]>
Add a NULL check before accessing device memory to prevent a crash if
dev->dmallocation inmlx5_init_once()fails.Fixes c9b9dcb430b3 ("net/mlx5: Move device memory management to mlx5_core")Signed-off-by Stav Aviram <[email protected]>Signed-off-by Leon Romanovsky <[email protected]>---
Changelog:
v1:
* Removed extraIS_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(-)drivers/infiniband/hw/mlx5/dm.c +0
-0@@ -282,7 +282,7 @@ static struct ib_dm *handle_alloc_dm_memic(struct ib_ucontext *ctx,int err;u64 address;
Quoted 6 lines
drivers/infiniband/hw/mlx5/dm.c static struct ib_dm *handle_alloc_dm_memic(struct ib_ucontext *ctx, · line 286
Quoted 3 lines
drivers/infiniband/hw/mlx5/dm.c +1
-1-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:
-EOPNOTSUPPdoesn'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().
Thanks
Quoted 5 lines
Quoted 3 lines
drivers/infiniband/hw/mlx5/dm.c +0
-0dm =kzalloc (sizeof (*dm),GFP_KERNEL );...
Simon Horman
reviewerQuoted 30 lines · Leon Romanovsky
Quoted 29 lines · Simon Horman
Quoted 28 lines · Leon Romanovsky
From: Stav Aviram <[email protected]>
Add a NULL check before accessing device memory to prevent a crash if
dev->dmallocation inmlx5_init_once()fails.Fixes c9b9dcb430b3 ("net/mlx5: Move device memory management to mlx5_core")Signed-off-by Stav Aviram <[email protected]>Signed-off-by Leon Romanovsky <[email protected]>---
Changelog:
v1:
* Removed extraIS_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(-)drivers/infiniband/hw/mlx5/dm.c +0
-0@@ -282,7 +282,7 @@ static struct ib_dm *handle_alloc_dm_memic(struct ib_ucontext *ctx,int err;u64 address;
Quoted 8 lines
Quoted 6 lines
drivers/infiniband/hw/mlx5/dm.c static struct ib_dm *handle_alloc_dm_memic(struct ib_ucontext *ctx, · line 286
Quoted 3 lines
drivers/infiniband/hw/mlx5/dm.c +1
-1-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:
-EOPNOTSUPPdoesn'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.
Quoted 38 lines · Simon Horman
Quoted 37 lines · Leon Romanovsky
Quoted 35 lines · Simon Horman
Quoted 25 lines · Leon Romanovsky
From: Stav Aviram <[email protected]>
Add a NULL check before accessing device memory to prevent a crash if
dev->dmallocation inmlx5_init_once()fails.Fixes c9b9dcb430b3 ("net/mlx5: Move device memory management to mlx5_core")Signed-off-by Stav Aviram <[email protected]>Signed-off-by Leon Romanovsky <[email protected]>---
Changelog:
v1:
* Removed extraIS_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(-)drivers/infiniband/hw/mlx5/dm.c +0
-0drivers/infiniband/hw/mlx5/dm.c static struct ib_dm *handle_alloc_dm_memic(struct ib_ucontext *ctx, · line 286
Quoted 6 lines
drivers/infiniband/hw/mlx5/dm.c +1
-1@@ -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:
-EOPNOTSUPPdoesn't feel like the right error code
in the !dm_db case.
Quoted 7 lines
Quoted 1 line
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 returnsERR_PTR(-ENOMEM)ifkzalloc()fails. I'd suggest doing so for the !dm_db case too.
!dm_db case can be because of missing capabilities and EOPNOTSUPP is a way to inform users about it.
Quoted 2 lines
But I don't feel particularly strongly about this.
Simon Horman
reviewerQuoted 41 lines · Leon Romanovsky
Quoted 40 lines · Simon Horman
Quoted 38 lines · Leon Romanovsky
Quoted 29 lines · Simon Horman
Quoted 28 lines · Leon Romanovsky
From: Stav Aviram <[email protected]>
Add a NULL check before accessing device memory to prevent a crash if
dev->dmallocation inmlx5_init_once()fails.Fixes c9b9dcb430b3 ("net/mlx5: Move device memory management to mlx5_core")Signed-off-by Stav Aviram <[email protected]>Signed-off-by Leon Romanovsky <[email protected]>---
Changelog:
v1:
* Removed extraIS_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(-)drivers/infiniband/hw/mlx5/dm.c +0
-0@@ -282,7 +282,7 @@ static struct ib_dm *handle_alloc_dm_memic(struct ib_ucontext *ctx,int err;u64 address;Quoted 6 lines
drivers/infiniband/hw/mlx5/dm.c static struct ib_dm *handle_alloc_dm_memic(struct ib_ucontext *ctx, · line 286
Quoted 3 lines
drivers/infiniband/hw/mlx5/dm.c +1
-1-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:
-EOPNOTSUPPdoesn'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().
Quoted 8 lines
Quoted 5 lines
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 returnsERR_PTR(-ENOMEM)ifkzalloc()fails. I'd suggest doing so for the !dm_db case too.!dm_db case can be because of missing capabilities and EOPNOTSUPP is a way to inform users about it.
Understood. No further objections from my side.
...
Leon Romanovsky
AppliedQuoted 4 lines · Leon Romanovsky
Add a NULL check before accessing device memory to prevent a crash if
dev->dmallocation inmlx5_init_once()fails.
Applied, thanks!
[1/1] net/mlx5: Check device memory pointer before usage
https://git.kernel.org/rdma/rdma/c/70f238c902b8c0
Best regards,
Signature · 1 line
Leon Romanovsky <[email protected]>