netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mlx5: Add check for get_macsec_device()
@ 2025-02-18 10:02 Haoxiang Li
  2025-02-19 12:30 ` Leon Romanovsky
  0 siblings, 1 reply; 2+ messages in thread
From: Haoxiang Li @ 2025-02-18 10:02 UTC (permalink / raw)
  To: leon, jgg, sd, phaddad
  Cc: linux-rdma, linux-kernel, netdev, Haoxiang Li, stable

Add check for the return value of get_macsec_device() in
mlx5r_del_gid_macsec_operations() to prevent null pointer
dereference.

Fixes: 58dbd6428a68 ("RDMA/mlx5: Handles RoCE MACsec steering rules addition and deletion")
Cc: stable@vger.kernel.org
Signed-off-by: Haoxiang Li <haoxiang_li2024@163.com>
---
 drivers/infiniband/hw/mlx5/macsec.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/infiniband/hw/mlx5/macsec.c b/drivers/infiniband/hw/mlx5/macsec.c
index 3c56eb5eddf3..623b0a58f721 100644
--- a/drivers/infiniband/hw/mlx5/macsec.c
+++ b/drivers/infiniband/hw/mlx5/macsec.c
@@ -354,6 +354,11 @@ void mlx5r_del_gid_macsec_operations(const struct ib_gid_attr *attr)
 		}
 	}
 	macsec_device = get_macsec_device(ndev, &dev->macsec.macsec_devices_list);
+	if (!macsec_device) {
+		dev_put(ndev);
+		mutex_unlock(&dev->macsec.lock);
+		return;
+	}
 	mlx5_macsec_del_roce_rule(attr->index, dev->mdev->macsec_fs,
 				  &macsec_device->tx_rules_list, &macsec_device->rx_rules_list);
 	mlx5_macsec_del_roce_gid(macsec_device, attr->index);
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-02-19 12:31 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-18 10:02 [PATCH] mlx5: Add check for get_macsec_device() Haoxiang Li
2025-02-19 12: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).