Skip to content

Commit d2228e4

Browse files
committed
Merge git://git.kernel.org/pub/scm/linux/kernel/git/nab/target-pending
Pull scsi target fixes from Nicholas Bellinger: "Apologies for the late pull request. Here are the outstanding target-pending fixes for v4.1 code. The series contains three patches from Sagi + Co that address a few iser-target issues that have been uncovered during recent testing at Mellanox. Patch #1 has a v3.16+ stable tag, and #2-3 have v3.10+ stable tags" * git://git.kernel.org/pub/scm/linux/kernel/git/nab/target-pending: iser-target: Fix possible use-after-free iser-target: release stale iser connections iser-target: Fix variable-length response error completion
2 parents 8f4ce07 + 524630d commit d2228e4

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

drivers/infiniband/ulp/isert/ib_isert.c

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ static int
6565
isert_rdma_accept(struct isert_conn *isert_conn);
6666
struct rdma_cm_id *isert_setup_id(struct isert_np *isert_np);
6767

68+
static void isert_release_work(struct work_struct *work);
69+
6870
static inline bool
6971
isert_prot_cmd(struct isert_conn *conn, struct se_cmd *cmd)
7072
{
@@ -648,6 +650,7 @@ isert_init_conn(struct isert_conn *isert_conn)
648650
mutex_init(&isert_conn->mutex);
649651
spin_lock_init(&isert_conn->pool_lock);
650652
INIT_LIST_HEAD(&isert_conn->fr_pool);
653+
INIT_WORK(&isert_conn->release_work, isert_release_work);
651654
}
652655

653656
static void
@@ -925,19 +928,33 @@ isert_disconnected_handler(struct rdma_cm_id *cma_id,
925928
{
926929
struct isert_np *isert_np = cma_id->context;
927930
struct isert_conn *isert_conn;
931+
bool terminating = false;
928932

929933
if (isert_np->np_cm_id == cma_id)
930934
return isert_np_cma_handler(cma_id->context, event);
931935

932936
isert_conn = cma_id->qp->qp_context;
933937

934938
mutex_lock(&isert_conn->mutex);
939+
terminating = (isert_conn->state == ISER_CONN_TERMINATING);
935940
isert_conn_terminate(isert_conn);
936941
mutex_unlock(&isert_conn->mutex);
937942

938943
isert_info("conn %p completing wait\n", isert_conn);
939944
complete(&isert_conn->wait);
940945

946+
if (terminating)
947+
goto out;
948+
949+
mutex_lock(&isert_np->np_accept_mutex);
950+
if (!list_empty(&isert_conn->accept_node)) {
951+
list_del_init(&isert_conn->accept_node);
952+
isert_put_conn(isert_conn);
953+
queue_work(isert_release_wq, &isert_conn->release_work);
954+
}
955+
mutex_unlock(&isert_np->np_accept_mutex);
956+
957+
out:
941958
return 0;
942959
}
943960

@@ -2380,7 +2397,6 @@ isert_build_rdma_wr(struct isert_conn *isert_conn, struct isert_cmd *isert_cmd,
23802397
page_off = offset % PAGE_SIZE;
23812398

23822399
send_wr->sg_list = ib_sge;
2383-
send_wr->num_sge = sg_nents;
23842400
send_wr->wr_id = (uintptr_t)&isert_cmd->tx_desc;
23852401
/*
23862402
* Perform mapping of TCM scatterlist memory ib_sge dma_addr.
@@ -2400,14 +2416,17 @@ isert_build_rdma_wr(struct isert_conn *isert_conn, struct isert_cmd *isert_cmd,
24002416
ib_sge->addr, ib_sge->length, ib_sge->lkey);
24012417
page_off = 0;
24022418
data_left -= ib_sge->length;
2419+
if (!data_left)
2420+
break;
24032421
ib_sge++;
24042422
isert_dbg("Incrementing ib_sge pointer to %p\n", ib_sge);
24052423
}
24062424

2425+
send_wr->num_sge = ++i;
24072426
isert_dbg("Set outgoing sg_list: %p num_sg: %u from TCM SGLs\n",
24082427
send_wr->sg_list, send_wr->num_sge);
24092428

2410-
return sg_nents;
2429+
return send_wr->num_sge;
24112430
}
24122431

24132432
static int
@@ -3366,14 +3385,14 @@ static void isert_wait_conn(struct iscsi_conn *conn)
33663385
isert_wait4flush(isert_conn);
33673386
isert_wait4logout(isert_conn);
33683387

3369-
INIT_WORK(&isert_conn->release_work, isert_release_work);
33703388
queue_work(isert_release_wq, &isert_conn->release_work);
33713389
}
33723390

33733391
static void isert_free_conn(struct iscsi_conn *conn)
33743392
{
33753393
struct isert_conn *isert_conn = conn->context;
33763394

3395+
isert_wait4flush(isert_conn);
33773396
isert_put_conn(isert_conn);
33783397
}
33793398

0 commit comments

Comments
 (0)