Skip to content

Commit 499b3ce

Browse files
Yunlongsgregkh
authored andcommitted
IB/isert: Fix a use after free in isert_connect_request
[ Upstream commit adb76a5 ] The device is got by isert_device_get() with refcount is 1, and is assigned to isert_conn by isert_conn->device = device. When isert_create_qp() failed, device will be freed with isert_device_put(). Later, the device is used in isert_free_login_buf(isert_conn) by the isert_conn->device->ib_device statement. Free the device in the correct order. Fixes: ae9ea9e ("iser-target: Split some logic in isert_connect_request to routines") Link: https://lore.kernel.org/r/20210322161325.7491-1-lyl2019@mail.ustc.edu.cn Signed-off-by: Lv Yunlong <lyl2019@mail.ustc.edu.cn> Acked-by: Sagi Grimberg <sagi@grimberg.me> Reviewed-by: Leon Romanovsky <leonro@nvidia.com> Reviewed-by: Max Gurtovoy <mgurtovoy@nvidia.com> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 78f537c commit 499b3ce

1 file changed

Lines changed: 8 additions & 8 deletions

File tree

‎drivers/infiniband/ulp/isert/ib_isert.c‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -438,23 +438,23 @@ isert_connect_request(struct rdma_cm_id *cma_id, struct rdma_cm_event *event)
438438
isert_init_conn(isert_conn);
439439
isert_conn->cm_id = cma_id;
440440

441-
ret = isert_alloc_login_buf(isert_conn, cma_id->device);
442-
if (ret)
443-
goto out;
444-
445441
device = isert_device_get(cma_id);
446442
if (IS_ERR(device)) {
447443
ret = PTR_ERR(device);
448-
goto out_rsp_dma_map;
444+
goto out;
449445
}
450446
isert_conn->device = device;
451447

448+
ret = isert_alloc_login_buf(isert_conn, cma_id->device);
449+
if (ret)
450+
goto out_conn_dev;
451+
452452
isert_set_nego_params(isert_conn, &event->param.conn);
453453

454454
isert_conn->qp = isert_create_qp(isert_conn, cma_id);
455455
if (IS_ERR(isert_conn->qp)) {
456456
ret = PTR_ERR(isert_conn->qp);
457-
goto out_conn_dev;
457+
goto out_rsp_dma_map;
458458
}
459459

460460
ret = isert_login_post_recv(isert_conn);
@@ -473,10 +473,10 @@ isert_connect_request(struct rdma_cm_id *cma_id, struct rdma_cm_event *event)
473473

474474
out_destroy_qp:
475475
isert_destroy_qp(isert_conn);
476-
out_conn_dev:
477-
isert_device_put(device);
478476
out_rsp_dma_map:
479477
isert_free_login_buf(isert_conn);
478+
out_conn_dev:
479+
isert_device_put(device);
480480
out:
481481
kfree(isert_conn);
482482
rdma_reject(cma_id, NULL, 0, IB_CM_REJ_CONSUMER_DEFINED);

0 commit comments

Comments
 (0)