Skip to content

Commit 186a964

Browse files
author
Nicholas Bellinger
committed
iscsi-target: Fix ISCSI_OP_SCSI_TMFUNC handling for iser
This patch adds target_get_sess_cmd reference counting for iscsit_handle_task_mgt_cmd(), and adds a target_put_sess_cmd() for the failure case. It also fixes a bug where ISCSI_OP_SCSI_TMFUNC type commands where leaking iscsi_cmd->i_conn_node and eventually triggering an OOPs during struct isert_conn shutdown. Cc: stable@vger.kernel.org # 3.10+ Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
1 parent 561bf15 commit 186a964

2 files changed

Lines changed: 18 additions & 10 deletions

File tree

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1200,14 +1200,12 @@ isert_put_cmd(struct isert_cmd *isert_cmd)
12001200
{
12011201
struct iscsi_cmd *cmd = &isert_cmd->iscsi_cmd;
12021202
struct isert_conn *isert_conn = isert_cmd->conn;
1203-
struct iscsi_conn *conn;
1203+
struct iscsi_conn *conn = isert_conn->conn;
12041204

12051205
pr_debug("Entering isert_put_cmd: %p\n", isert_cmd);
12061206

12071207
switch (cmd->iscsi_opcode) {
12081208
case ISCSI_OP_SCSI_CMD:
1209-
conn = isert_conn->conn;
1210-
12111209
spin_lock_bh(&conn->cmd_lock);
12121210
if (!list_empty(&cmd->i_conn_node))
12131211
list_del(&cmd->i_conn_node);
@@ -1217,16 +1215,18 @@ isert_put_cmd(struct isert_cmd *isert_cmd)
12171215
iscsit_stop_dataout_timer(cmd);
12181216

12191217
isert_unmap_cmd(isert_cmd, isert_conn);
1220-
/*
1221-
* Fall-through
1222-
*/
1218+
transport_generic_free_cmd(&cmd->se_cmd, 0);
1219+
break;
12231220
case ISCSI_OP_SCSI_TMFUNC:
1221+
spin_lock_bh(&conn->cmd_lock);
1222+
if (!list_empty(&cmd->i_conn_node))
1223+
list_del(&cmd->i_conn_node);
1224+
spin_unlock_bh(&conn->cmd_lock);
1225+
12241226
transport_generic_free_cmd(&cmd->se_cmd, 0);
12251227
break;
12261228
case ISCSI_OP_REJECT:
12271229
case ISCSI_OP_NOOP_OUT:
1228-
conn = isert_conn->conn;
1229-
12301230
spin_lock_bh(&conn->cmd_lock);
12311231
if (!list_empty(&cmd->i_conn_node))
12321232
list_del(&cmd->i_conn_node);

‎drivers/target/iscsi/iscsi_target.c‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1737,8 +1737,8 @@ iscsit_handle_task_mgt_cmd(struct iscsi_conn *conn, struct iscsi_cmd *cmd,
17371737
struct se_tmr_req *se_tmr;
17381738
struct iscsi_tmr_req *tmr_req;
17391739
struct iscsi_tm *hdr;
1740-
int out_of_order_cmdsn = 0;
1741-
int ret;
1740+
int out_of_order_cmdsn = 0, ret;
1741+
bool sess_ref = false;
17421742
u8 function;
17431743

17441744
hdr = (struct iscsi_tm *) buf;
@@ -1794,6 +1794,9 @@ iscsit_handle_task_mgt_cmd(struct iscsi_conn *conn, struct iscsi_cmd *cmd,
17941794
conn->sess->se_sess, 0, DMA_NONE,
17951795
MSG_SIMPLE_TAG, cmd->sense_buffer + 2);
17961796

1797+
target_get_sess_cmd(conn->sess->se_sess, &cmd->se_cmd, true);
1798+
sess_ref = true;
1799+
17971800
switch (function) {
17981801
case ISCSI_TM_FUNC_ABORT_TASK:
17991802
tcm_function = TMR_ABORT_TASK;
@@ -1931,6 +1934,11 @@ iscsit_handle_task_mgt_cmd(struct iscsi_conn *conn, struct iscsi_cmd *cmd,
19311934
* For connection recovery, this is also the default action for
19321935
* TMR TASK_REASSIGN.
19331936
*/
1937+
if (sess_ref) {
1938+
pr_debug("Handle TMR, using sess_ref=true check\n");
1939+
target_put_sess_cmd(conn->sess->se_sess, &cmd->se_cmd);
1940+
}
1941+
19341942
iscsit_add_cmd_to_response_queue(cmd, conn, cmd->i_state);
19351943
return 0;
19361944
}

0 commit comments

Comments
 (0)