* [PATCH v2] infiniband: Fix a use after free in isert_connect_request
@ 2021-03-22 16:13 Lv Yunlong
2021-03-23 0:47 ` Sagi Grimberg
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Lv Yunlong @ 2021-03-22 16:13 UTC (permalink / raw)
To: sagi, dledford, jgg; +Cc: linux-rdma, target-devel, linux-kernel, Lv Yunlong
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. This patch
free the device in the correct order.
Signed-off-by: Lv Yunlong <lyl2019@mail.ustc.edu.cn>
---
drivers/infiniband/ulp/isert/ib_isert.c | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/drivers/infiniband/ulp/isert/ib_isert.c b/drivers/infiniband/ulp/isert/ib_isert.c
index 7305ed8976c2..18266f07c58d 100644
--- a/drivers/infiniband/ulp/isert/ib_isert.c
+++ b/drivers/infiniband/ulp/isert/ib_isert.c
@@ -438,23 +438,23 @@ isert_connect_request(struct rdma_cm_id *cma_id, struct rdma_cm_event *event)
isert_init_conn(isert_conn);
isert_conn->cm_id = cma_id;
- ret = isert_alloc_login_buf(isert_conn, cma_id->device);
- if (ret)
- goto out;
-
device = isert_device_get(cma_id);
if (IS_ERR(device)) {
ret = PTR_ERR(device);
- goto out_rsp_dma_map;
+ goto out;
}
isert_conn->device = device;
+ ret = isert_alloc_login_buf(isert_conn, cma_id->device);
+ if (ret)
+ goto out_conn_dev;
+
isert_set_nego_params(isert_conn, &event->param.conn);
isert_conn->qp = isert_create_qp(isert_conn, cma_id);
if (IS_ERR(isert_conn->qp)) {
ret = PTR_ERR(isert_conn->qp);
- goto out_conn_dev;
+ goto out_rsp_dma_map;
}
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)
out_destroy_qp:
isert_destroy_qp(isert_conn);
-out_conn_dev:
- isert_device_put(device);
out_rsp_dma_map:
isert_free_login_buf(isert_conn);
+out_conn_dev:
+ isert_device_put(device);
out:
kfree(isert_conn);
rdma_reject(cma_id, NULL, 0, IB_CM_REJ_CONSUMER_DEFINED);
--
2.25.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v2] infiniband: Fix a use after free in isert_connect_request
2021-03-22 16:13 [PATCH v2] infiniband: Fix a use after free in isert_connect_request Lv Yunlong
@ 2021-03-23 0:47 ` Sagi Grimberg
2021-03-24 9:21 ` Leon Romanovsky
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Sagi Grimberg @ 2021-03-23 0:47 UTC (permalink / raw)
To: Lv Yunlong, dledford, jgg; +Cc: linux-rdma, target-devel, linux-kernel
Acked-by: Sagi Grimberg <sagi@grimberg.me>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] infiniband: Fix a use after free in isert_connect_request
2021-03-22 16:13 [PATCH v2] infiniband: Fix a use after free in isert_connect_request Lv Yunlong
2021-03-23 0:47 ` Sagi Grimberg
@ 2021-03-24 9:21 ` Leon Romanovsky
2021-03-25 10:56 ` Max Gurtovoy
2021-03-26 17:26 ` Jason Gunthorpe
3 siblings, 0 replies; 5+ messages in thread
From: Leon Romanovsky @ 2021-03-24 9:21 UTC (permalink / raw)
To: Lv Yunlong; +Cc: sagi, dledford, jgg, linux-rdma, target-devel, linux-kernel
On Mon, Mar 22, 2021 at 09:13:25AM -0700, Lv Yunlong wrote:
> 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. This patch
> free the device in the correct order.
>
> Signed-off-by: Lv Yunlong <lyl2019@mail.ustc.edu.cn>
> ---
> drivers/infiniband/ulp/isert/ib_isert.c | 16 ++++++++--------
> 1 file changed, 8 insertions(+), 8 deletions(-)
>
Thanks,
Reviewed-by: Leon Romanovsky <leonro@nvidia.com>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] infiniband: Fix a use after free in isert_connect_request
2021-03-22 16:13 [PATCH v2] infiniband: Fix a use after free in isert_connect_request Lv Yunlong
2021-03-23 0:47 ` Sagi Grimberg
2021-03-24 9:21 ` Leon Romanovsky
@ 2021-03-25 10:56 ` Max Gurtovoy
2021-03-26 17:26 ` Jason Gunthorpe
3 siblings, 0 replies; 5+ messages in thread
From: Max Gurtovoy @ 2021-03-25 10:56 UTC (permalink / raw)
To: Lv Yunlong, sagi, dledford, jgg; +Cc: linux-rdma, target-devel, linux-kernel
On 3/22/2021 6:13 PM, Lv Yunlong wrote:
> 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. This patch
> free the device in the correct order.
>
> Signed-off-by: Lv Yunlong <lyl2019@mail.ustc.edu.cn>
> ---
> drivers/infiniband/ulp/isert/ib_isert.c | 16 ++++++++--------
> 1 file changed, 8 insertions(+), 8 deletions(-)
looks good,
Reviewed-by: Max Gurtovoy <mgurtovoy@nvidia.com>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] infiniband: Fix a use after free in isert_connect_request
2021-03-22 16:13 [PATCH v2] infiniband: Fix a use after free in isert_connect_request Lv Yunlong
` (2 preceding siblings ...)
2021-03-25 10:56 ` Max Gurtovoy
@ 2021-03-26 17:26 ` Jason Gunthorpe
3 siblings, 0 replies; 5+ messages in thread
From: Jason Gunthorpe @ 2021-03-26 17:26 UTC (permalink / raw)
To: Lv Yunlong; +Cc: sagi, dledford, linux-rdma, target-devel, linux-kernel
On Mon, Mar 22, 2021 at 09:13:25AM -0700, Lv Yunlong wrote:
> 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. This patch
> free the device in the correct order.
>
> 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>
> drivers/infiniband/ulp/isert/ib_isert.c | 16 ++++++++--------
> 1 file changed, 8 insertions(+), 8 deletions(-)
Applied to for-next, I added
Fixes: ae9ea9ed38c9 ("iser-target: Split some logic in isert_connect_request to routines")
Please ensure you add fixes lines when you send bug fixes.
Thanks,
Jason
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2021-03-26 17:27 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-03-22 16:13 [PATCH v2] infiniband: Fix a use after free in isert_connect_request Lv Yunlong
2021-03-23 0:47 ` Sagi Grimberg
2021-03-24 9:21 ` Leon Romanovsky
2021-03-25 10:56 ` Max Gurtovoy
2021-03-26 17:26 ` Jason Gunthorpe
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).