aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNicholas Bellinger <nab@linux-iscsi.org>2017-10-27 15:32:59 -0400
committerNicholas Bellinger <nab@linux-iscsi.org>2017-11-07 22:51:23 -0500
commitae072726f6109bb1c94841d6fb3a82dde298ea85 (patch)
tree2de91dfef6e38343b09d0b8d568e8d51f43faa62
parent1c21a48055a67ceb693e9c2587824a8de60a217c (diff)
iscsi-target: Make TASK_REASSIGN use proper se_cmd->cmd_kref
Since commit 59b6986dbf fixed a potential NULL pointer dereference by allocating a se_tmr_req for ISCSI_TM_FUNC_TASK_REASSIGN, the se_tmr_req is currently leaked by iscsit_free_cmd() because no iscsi_cmd->se_cmd.se_tfo was associated. To address this, treat ISCSI_TM_FUNC_TASK_REASSIGN like any other TMR and call transport_init_se_cmd() + target_get_sess_cmd() to setup iscsi_cmd->se_cmd.se_tfo with se_cmd->cmd_kref of 2. This will ensure normal release operation once se_cmd->cmd_kref reaches zero and target_release_cmd_kref() is invoked, se_tmr_req will be released via existing target_free_cmd_mem() and core_tmr_release_req() code. Reported-by: Donald White <dew@datera.io> Cc: Donald White <dew@datera.io> Cc: Mike Christie <mchristi@redhat.com> Cc: Hannes Reinecke <hare@suse.com> Cc: stable@vger.kernel.org # 3.10+ Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
-rw-r--r--drivers/target/iscsi/iscsi_target.c22
1 files changed, 9 insertions, 13 deletions
diff --git a/drivers/target/iscsi/iscsi_target.c b/drivers/target/iscsi/iscsi_target.c
index 541f66a875fc..048d4227327c 100644
--- a/drivers/target/iscsi/iscsi_target.c
+++ b/drivers/target/iscsi/iscsi_target.c
@@ -1955,7 +1955,6 @@ iscsit_handle_task_mgt_cmd(struct iscsi_conn *conn, struct iscsi_cmd *cmd,
1955 struct iscsi_tmr_req *tmr_req; 1955 struct iscsi_tmr_req *tmr_req;
1956 struct iscsi_tm *hdr; 1956 struct iscsi_tm *hdr;
1957 int out_of_order_cmdsn = 0, ret; 1957 int out_of_order_cmdsn = 0, ret;
1958 bool sess_ref = false;
1959 u8 function, tcm_function = TMR_UNKNOWN; 1958 u8 function, tcm_function = TMR_UNKNOWN;
1960 1959
1961 hdr = (struct iscsi_tm *) buf; 1960 hdr = (struct iscsi_tm *) buf;
@@ -1988,22 +1987,23 @@ iscsit_handle_task_mgt_cmd(struct iscsi_conn *conn, struct iscsi_cmd *cmd,
1988 1987
1989 cmd->data_direction = DMA_NONE; 1988 cmd->data_direction = DMA_NONE;
1990 cmd->tmr_req = kzalloc(sizeof(*cmd->tmr_req), GFP_KERNEL); 1989 cmd->tmr_req = kzalloc(sizeof(*cmd->tmr_req), GFP_KERNEL);
1991 if (!cmd->tmr_req) 1990 if (!cmd->tmr_req) {
1992 return iscsit_add_reject_cmd(cmd, 1991 return iscsit_add_reject_cmd(cmd,
1993 ISCSI_REASON_BOOKMARK_NO_RESOURCES, 1992 ISCSI_REASON_BOOKMARK_NO_RESOURCES,
1994 buf); 1993 buf);
1994 }
1995
1996 transport_init_se_cmd(&cmd->se_cmd, &iscsi_ops,
1997 conn->sess->se_sess, 0, DMA_NONE,
1998 TCM_SIMPLE_TAG, cmd->sense_buffer + 2);
1999
2000 target_get_sess_cmd(&cmd->se_cmd, true);
1995 2001
1996 /* 2002 /*
1997 * TASK_REASSIGN for ERL=2 / connection stays inside of 2003 * TASK_REASSIGN for ERL=2 / connection stays inside of
1998 * LIO-Target $FABRIC_MOD 2004 * LIO-Target $FABRIC_MOD
1999 */ 2005 */
2000 if (function != ISCSI_TM_FUNC_TASK_REASSIGN) { 2006 if (function != ISCSI_TM_FUNC_TASK_REASSIGN) {
2001 transport_init_se_cmd(&cmd->se_cmd, &iscsi_ops,
2002 conn->sess->se_sess, 0, DMA_NONE,
2003 TCM_SIMPLE_TAG, cmd->sense_buffer + 2);
2004
2005 target_get_sess_cmd(&cmd->se_cmd, true);
2006 sess_ref = true;
2007 tcm_function = iscsit_convert_tmf(function); 2007 tcm_function = iscsit_convert_tmf(function);
2008 if (tcm_function == TMR_UNKNOWN) { 2008 if (tcm_function == TMR_UNKNOWN) {
2009 pr_err("Unknown iSCSI TMR Function:" 2009 pr_err("Unknown iSCSI TMR Function:"
@@ -2119,12 +2119,8 @@ attach:
2119 * For connection recovery, this is also the default action for 2119 * For connection recovery, this is also the default action for
2120 * TMR TASK_REASSIGN. 2120 * TMR TASK_REASSIGN.
2121 */ 2121 */
2122 if (sess_ref) {
2123 pr_debug("Handle TMR, using sess_ref=true check\n");
2124 target_put_sess_cmd(&cmd->se_cmd);
2125 }
2126
2127 iscsit_add_cmd_to_response_queue(cmd, conn, cmd->i_state); 2122 iscsit_add_cmd_to_response_queue(cmd, conn, cmd->i_state);
2123 target_put_sess_cmd(&cmd->se_cmd);
2128 return 0; 2124 return 0;
2129} 2125}
2130EXPORT_SYMBOL(iscsit_handle_task_mgt_cmd); 2126EXPORT_SYMBOL(iscsit_handle_task_mgt_cmd);