1 From c8d3bcbfc5eab3f01cf373d039af725f3b488813 Mon Sep 17 00:00:00 2001
2 From: Leon Romanovsky <leonro@mellanox.com>
3 Date: Sun, 25 Mar 2018 11:39:05 +0300
4 Subject: RDMA/ucma: Check that device exists prior to accessing it
6 From: Leon Romanovsky <leonro@mellanox.com>
8 commit c8d3bcbfc5eab3f01cf373d039af725f3b488813 upstream.
10 Ensure that device exists prior to accessing its properties.
12 Reported-by: <syzbot+71655d44855ac3e76366@syzkaller.appspotmail.com>
13 Fixes: 75216638572f ("RDMA/cma: Export rdma cm interface to userspace")
14 Signed-off-by: Leon Romanovsky <leonro@mellanox.com>
15 Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
16 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
19 drivers/infiniband/core/ucma.c | 6 ++++--
20 1 file changed, 4 insertions(+), 2 deletions(-)
22 --- a/drivers/infiniband/core/ucma.c
23 +++ b/drivers/infiniband/core/ucma.c
24 @@ -1335,7 +1335,7 @@ static ssize_t ucma_notify(struct ucma_f
26 struct rdma_ucm_notify cmd;
27 struct ucma_context *ctx;
31 if (copy_from_user(&cmd, inbuf, sizeof(cmd)))
33 @@ -1344,7 +1344,9 @@ static ssize_t ucma_notify(struct ucma_f
37 - ret = rdma_notify(ctx->cm_id, (enum ib_event_type) cmd.event);
38 + if (ctx->cm_id->device)
39 + ret = rdma_notify(ctx->cm_id, (enum ib_event_type)cmd.event);