Skip to content

Commit 1901b91

Browse files
Jack Morgensteinjgunthorpe
Jack Morgenstein
authored andcommitted
IB/core: Fix potential NULL pointer dereference in pkey cache
The IB core pkey cache is populated by procedure ib_cache_update(). Initially, the pkey cache pointer is NULL. ib_cache_update allocates a buffer and populates it with the device's pkeys, via repeated calls to procedure ib_query_pkey(). If there is a failure in populating the pkey buffer via ib_query_pkey(), ib_cache_update does not replace the old pkey buffer cache with the updated one -- it leaves the old cache as is. Since initially the pkey buffer cache is NULL, when calling ib_cache_update the first time, a failure in ib_query_pkey() will cause the pkey buffer cache pointer to remain NULL. In this situation, any calls subsequent to ib_get_cached_pkey(), ib_find_cached_pkey(), or ib_find_cached_pkey_exact() will try to dereference the NULL pkey cache pointer, causing a kernel panic. Fix this by checking the ib_cache_update() return value. Fixes: 8faea9f ("RDMA/cache: Move the cache per-port data into the main ib_port_data") Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jack Morgenstein <[email protected]> Signed-off-by: Leon Romanovsky <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]>
1 parent fa8dac3 commit 1901b91

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

drivers/infiniband/core/cache.c

+5-2
Original file line numberDiff line numberDiff line change
@@ -1553,8 +1553,11 @@ int ib_cache_setup_one(struct ib_device *device)
15531553
if (err)
15541554
return err;
15551555

1556-
rdma_for_each_port (device, p)
1557-
ib_cache_update(device, p, true);
1556+
rdma_for_each_port (device, p) {
1557+
err = ib_cache_update(device, p, true);
1558+
if (err)
1559+
return err;
1560+
}
15581561

15591562
return 0;
15601563
}

0 commit comments

Comments
 (0)