[PATCH 6.19 486/844] RDMA/ionic: Fix potential NULL pointer dereference in ionic_query_port
From: Sasha Levin
Date: Sat Feb 28 2026 - 15:21:50 EST
From: Kamal Heib <kheib@xxxxxxxxxx>
[ Upstream commit fd80bd7105f88189f47d465ca8cb7d115570de30 ]
The function ionic_query_port() calls ib_device_get_netdev() without
checking the return value which could lead to NULL pointer dereference,
Fix it by checking the return value and return -ENODEV if the 'ndev' is
NULL.
Fixes: 2075bbe8ef03 ("RDMA/ionic: Register device ops for miscellaneous functionality")
Signed-off-by: Kamal Heib <kheib@xxxxxxxxxx>
Link: https://patch.msgid.link/20260220222125.16973-2-kheib@xxxxxxxxxx
Signed-off-by: Leon Romanovsky <leon@xxxxxxxxxx>
Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>
---
drivers/infiniband/hw/ionic/ionic_ibdev.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/infiniband/hw/ionic/ionic_ibdev.c b/drivers/infiniband/hw/ionic/ionic_ibdev.c
index 164046d00e5d4..bd4c73e530d08 100644
--- a/drivers/infiniband/hw/ionic/ionic_ibdev.c
+++ b/drivers/infiniband/hw/ionic/ionic_ibdev.c
@@ -81,6 +81,8 @@ static int ionic_query_port(struct ib_device *ibdev, u32 port,
return -EINVAL;
ndev = ib_device_get_netdev(ibdev, port);
+ if (!ndev)
+ return -ENODEV;
if (netif_running(ndev) && netif_carrier_ok(ndev)) {
attr->state = IB_PORT_ACTIVE;
--
2.51.0