From patchwork Wed Feb 8 22:24:34 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 9563685 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 02EF06020F for ; Wed, 8 Feb 2017 22:29:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C99EC284F2 for ; Wed, 8 Feb 2017 22:29:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BEB9C2852D; Wed, 8 Feb 2017 22:29:47 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3C319284F2 for ; Wed, 8 Feb 2017 22:29:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751149AbdBHW3q (ORCPT ); Wed, 8 Feb 2017 17:29:46 -0500 Received: from esa2.hgst.iphmx.com ([68.232.143.124]:11128 "EHLO esa2.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751092AbdBHW3q (ORCPT ); Wed, 8 Feb 2017 17:29:46 -0500 X-IronPort-AV: E=Sophos;i="5.35,348,1483977600"; d="scan'208";a="76618116" Received: from unknown (HELO milsmgep15.sandisk.com) ([63.163.107.21]) by ob1.hgst.iphmx.com with ESMTP; 09 Feb 2017 06:28:17 +0800 Received: from MILHUBIP03.sdcorp.global.sandisk.com (Unknown_Domain [10.201.67.162]) (using TLS with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by (Symantec Messaging Gateway) with SMTP id A2.54.57638.8CA9B985; Wed, 8 Feb 2017 14:25:12 -0800 (PST) Received: from milsmgip12.sandisk.com (10.177.8.100) by MILHUBIP03.sdcorp.global.sandisk.com (10.177.9.96) with Microsoft SMTP Server id 14.3.319.2; Wed, 8 Feb 2017 14:25:11 -0800 X-AuditID: 0ac94369-26dee9800001e126-ee-589b9ac8ccce Received: from exp-402881.sdcorp.global.sandisk.com ( [10.177.9.6]) by (Symantec Messaging Gateway) with SMTP id EE.32.18148.7CA9B985; Wed, 8 Feb 2017 14:25:11 -0800 (PST) From: Bart Van Assche To: Bart Van Assche CC: , Moshe David Subject: [PATCH v4 04/37] target/iscsi: Fix iSCSI task reassignment handling Date: Wed, 8 Feb 2017 14:24:34 -0800 Message-ID: <20170208222507.25715-5-bart.vanassche@sandisk.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170208222507.25715-1-bart.vanassche@sandisk.com> References: <20170208222507.25715-1-bart.vanassche@sandisk.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrELMWRmVeSWpSXmKPExsXCddJ5ke6JWbMjDL7sULG4e3UVu0Xr0rdM DkweL59tY/L4vEkugCmKyyYlNSezLLVI3y6BK6Nv9y7WgguCFddnHWBuYLzJ18XIySEhYCLx aOoqti5GLg4hgaVMEotevmeFcLYzSiyftI25i5EDrKp1jzBEfCOjxIIPPWwg3WwCRhLf3s9k AbFFBAwkfvdeYASxmQXcJHo/XGUGsYUFfCQ+H98OFmcRUJG4f3orWD2vgL3E6fZ3rBBXyEvs arsIZnMKOEhMePkMrF4IqObVgS+MIIslBJ6zSGw+dYQNollQ4uTMJywQyyQkDr54wQzRoC5x csl8pgmMQrOQlM1CUraAkWkVo1huZk5xbnpqgaGpXnFiXkpmcbZecn7uJkZIyGbuYLz7xPsQ owAHoxIPb4Xl7Agh1sSy4srcQ4wSHMxKIrwp04BCvCmJlVWpRfnxRaU5qcWHGKU5WJTEec/J TI0QEkhPLEnNTk0tSC2CyTJxcEo1MGo+uKxg/yN/tr8q9y2DC3e3+Ovs5FoXX/XzlIG05Oly f6Pw/8u2Saj5igVv6hbLkegMiugTvyHAd/JAn9zqDEVh/6uFLXt7c5/cW5/S/dpquews7gtJ v8VmV1++e33Lv0lzVzrP/Vu4cMa6XjWDv8U9lX8rH17OZdf/GVFwL6AwoFT/YJbuESWW4oxE Qy3mouJEAIAzK3dVAgAA X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprIJMWRmVeSWpSXmKPExsXCtZGTTff4rNkRBi0zhSwO/mxjtLh7dRW7 RevSt0wOzB4vn21j8pi25jyTx+dNcgHMUVw2Kak5mWWpRfp2CVwZfbt3sRZcEKy4PusAcwPj Tb4uRg4OCQETidY9wl2MXBxCAusZJaZ2LWTtYuTkYBMwkvj2fiYLiC0iYCDxu/cCI4jNLOAm 8fPLZTBbWMBH4vPx7WA2i4CqROP+c+wgNq+AvcTOGSvA5kgIyEvsarsIZnMKOEhMePkMrF4I qObVgS+MExi5FzAyrGIUy83MKc5NzywwNNIrTsxLySzO1kvOz93ECPF01A7G6xPNDzEycXBK NTAeOpTPFxZafTTL833+E1GJjumz32zQ0oi7zmGTmOXovyuAc2Hk3glFXv75U/07/0ySvrV3 ybHDf7U5j2xR2jK9avK7RTVbH+RHvI1vXRhjM/PBc/GLhdcX6Bz/7RN8/5xyS+mW88fnbQtm MNq867zJtDulwYe59qgfWftv7ucD5zlnTzxx5ERFkBJLcUaioRZzUXEiAIQFE32kAQAA MIME-Version: 1.0 Sender: target-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: target-devel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Allocate a task management request structure for all task management requests, including task reassignment. This change avoids that the se_tmr->response assignment dereferences an uninitialized se_tmr pointer. Reported-by: Moshe David Signed-off-by: Bart Van Assche Reviewed-by: Hannes Reinecke Reviewed-by: Christoph Hellwig Cc: Moshe David --- drivers/target/iscsi/iscsi_target.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/drivers/target/iscsi/iscsi_target.c b/drivers/target/iscsi/iscsi_target.c index d16729fa1f67..b4f1d1cbe521 100644 --- a/drivers/target/iscsi/iscsi_target.c +++ b/drivers/target/iscsi/iscsi_target.c @@ -1951,7 +1951,7 @@ iscsit_handle_task_mgt_cmd(struct iscsi_conn *conn, struct iscsi_cmd *cmd, struct iscsi_tm *hdr; int out_of_order_cmdsn = 0, ret; bool sess_ref = false; - u8 function; + u8 function, tcm_function = TMR_UNKNOWN; hdr = (struct iscsi_tm *) buf; hdr->flags &= ~ISCSI_FLAG_CMD_FINAL; @@ -1997,10 +1997,6 @@ iscsit_handle_task_mgt_cmd(struct iscsi_conn *conn, struct iscsi_cmd *cmd, * LIO-Target $FABRIC_MOD */ if (function != ISCSI_TM_FUNC_TASK_REASSIGN) { - - u8 tcm_function; - int ret; - transport_init_se_cmd(&cmd->se_cmd, &iscsi_ops, conn->sess->se_sess, 0, DMA_NONE, TCM_SIMPLE_TAG, cmd->sense_buffer + 2); @@ -2014,15 +2010,14 @@ iscsit_handle_task_mgt_cmd(struct iscsi_conn *conn, struct iscsi_cmd *cmd, return iscsit_add_reject_cmd(cmd, ISCSI_REASON_BOOKMARK_NO_RESOURCES, buf); } - - ret = core_tmr_alloc_req(&cmd->se_cmd, cmd->tmr_req, - tcm_function, GFP_KERNEL); - if (ret < 0) - return iscsit_add_reject_cmd(cmd, + } + ret = core_tmr_alloc_req(&cmd->se_cmd, cmd->tmr_req, tcm_function, + GFP_KERNEL); + if (ret < 0) + return iscsit_add_reject_cmd(cmd, ISCSI_REASON_BOOKMARK_NO_RESOURCES, buf); - cmd->tmr_req->se_tmr_req = cmd->se_cmd.se_tmr_req; - } + cmd->tmr_req->se_tmr_req = cmd->se_cmd.se_tmr_req; cmd->iscsi_opcode = ISCSI_OP_SCSI_TMFUNC; cmd->i_state = ISTATE_SEND_TASKMGTRSP;