Skip to content

Commit ce9a9fc

Browse files
author
Nicholas Bellinger
committed
iser-target: Fix REJECT CM event use-after-free OOPs
This patch fixes a bug in iser-target code where the REJECT CM event handler code currently performs a isert_put_conn() for the final isert_conn->kref put, while iscsi_np process context is still blocked in isert_get_login_rx(). Once isert_get_login_rx() is awoking due to login timeout, iscsi_np process context will attempt to invoke iscsi_target_login_sess_out() to cleanup iscsi_conn as expected, and calls isert_wait_conn() + isert_free_conn() which triggers the use-after-free OOPs. To address this bug, move the kref_get_unless_zero() call from isert_connected_handler() into isert_connect_request() immediately preceeding isert_rdma_accept() to ensure the CM handler cleanup paths and isert_free_conn() are always operating with two refs. Cc: Sagi Grimberg <[email protected]> Cc: <[email protected]> # v3.10+ Signed-off-by: Nicholas Bellinger <[email protected]>
1 parent 007d038 commit ce9a9fc

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

drivers/infiniband/ulp/isert/ib_isert.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -775,6 +775,17 @@ isert_connect_request(struct rdma_cm_id *cma_id, struct rdma_cm_event *event)
775775
ret = isert_rdma_post_recvl(isert_conn);
776776
if (ret)
777777
goto out_conn_dev;
778+
/*
779+
* Obtain the second reference now before isert_rdma_accept() to
780+
* ensure that any initiator generated REJECT CM event that occurs
781+
* asynchronously won't drop the last reference until the error path
782+
* in iscsi_target_login_sess_out() does it's ->iscsit_free_conn() ->
783+
* isert_free_conn() -> isert_put_conn() -> kref_put().
784+
*/
785+
if (!kref_get_unless_zero(&isert_conn->kref)) {
786+
isert_warn("conn %p connect_release is running\n", isert_conn);
787+
goto out_conn_dev;
788+
}
778789

779790
ret = isert_rdma_accept(isert_conn);
780791
if (ret)
@@ -836,11 +847,6 @@ isert_connected_handler(struct rdma_cm_id *cma_id)
836847

837848
isert_info("conn %p\n", isert_conn);
838849

839-
if (!kref_get_unless_zero(&isert_conn->kref)) {
840-
isert_warn("conn %p connect_release is running\n", isert_conn);
841-
return;
842-
}
843-
844850
mutex_lock(&isert_conn->mutex);
845851
if (isert_conn->state != ISER_CONN_FULL_FEATURE)
846852
isert_conn->state = ISER_CONN_UP;

0 commit comments

Comments
 (0)