diff mbox series

[next] RDMA: check for null return from call to ib_get_client_data

Message ID 20190620135052.27367-1-colin.king@canonical.com (mailing list archive)
State Rejected
Headers show
Series [next] RDMA: check for null return from call to ib_get_client_data | expand

Commit Message

Colin King June 20, 2019, 1:50 p.m. UTC
From: Colin Ian King <colin.king@canonical.com>

The return from ib_get_client_data can potentially be null, so add a null
check on umad_dev and return -ENODEV in this unlikely case to avoid any
null pointer deferences.

Addresses-Coverity: ("Dereference null return")
Fixes: 8f71bb0030b8 ("RDMA: Report available cdevs through RDMA_NLDEV_CMD_GET_CHARDEV")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 drivers/infiniband/core/user_mad.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

Jason Gunthorpe June 20, 2019, 3:02 p.m. UTC | #1
On Thu, Jun 20, 2019 at 02:50:52PM +0100, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> The return from ib_get_client_data can potentially be null, so add a null
> check on umad_dev and return -ENODEV in this unlikely case to avoid any
> null pointer deferences.

It would be a kernel bug if NULL is seen here.

Jason
diff mbox series

Patch

diff --git a/drivers/infiniband/core/user_mad.c b/drivers/infiniband/core/user_mad.c
index 547090b41cfb..d78a35913824 100644
--- a/drivers/infiniband/core/user_mad.c
+++ b/drivers/infiniband/core/user_mad.c
@@ -1153,6 +1153,9 @@  static int ib_issm_get_nl_info(struct ib_device *ibdev, void *client_data,
 	struct ib_umad_device *umad_dev =
 		ib_get_client_data(ibdev, &umad_client);
 
+	if (!umad_dev)
+		return -ENODEV;
+
 	if (!rdma_is_port_valid(ibdev, res->port))
 		return -EINVAL;