From patchwork Tue Oct 31 18:03:17 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: 10035077 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 A702D60327 for ; Tue, 31 Oct 2017 18:03:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9E7962884E for ; Tue, 31 Oct 2017 18:03:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 912572851D; Tue, 31 Oct 2017 18:03:32 +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.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID 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 315822851D for ; Tue, 31 Oct 2017 18:03:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932644AbdJaSDb (ORCPT ); Tue, 31 Oct 2017 14:03:31 -0400 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:38505 "EHLO esa4.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932531AbdJaSD0 (ORCPT ); Tue, 31 Oct 2017 14:03:26 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1509473007; x=1541009007; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=rbRmRUnJ1qNm4D9OvHDSXFLvT2rN8DGE+OChFu04OgQ=; b=haSqEdWqbsORJ+q5MF4aC3hAMfi3dONJto5lP/tabs8aHLpiXTNNRpuR qQiScm9ThH0xUh7nWEQql9RlI6IYTONxnrbUZgZzzM6zTCBZBuyt+1zOa GNhhWUXVu5YYiPr3oyz5R5OG23SQsHA/Xx8HFEH3AkeGp7EbOZHoU5+Gm JohkE2DHhVm80fwKDEXO+gYL6rFI8wNi4F/oDO6wfZG5g3ukRAdxCX5tW Qwjosd0rpJYcZYZXG0N7WV4K/4LEeVKKfILO4LuKrQonb0sdvlY86BLCI friv55hAQykwol5+mUd3B74rEGjwAD7tWJqbg4ay69cfbxxQ3AqVF1Qvz A==; X-IronPort-AV: E=Sophos;i="5.44,325,1505750400"; d="scan'208";a="60328640" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 01 Nov 2017 02:03:24 +0800 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP; 31 Oct 2017 11:01:08 -0700 Received: from unknown (HELO MILHUBIP03.sdcorp.global.sandisk.com) ([10.177.9.96]) by uls-op-cesaip02.wdc.com with ESMTP; 31 Oct 2017 11:03:24 -0700 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; Tue, 31 Oct 2017 11:03:23 -0700 X-AuditID: 0ab1095a-d99e3980000146e4-54-59f8baeada41 Received: from thinkpad-bart.int.fusionio.com ( [10.177.8.100]) by (Symantec Messaging Gateway) with SMTP id 8C.A9.18148.AEAB8F95; Tue, 31 Oct 2017 11:03:22 -0700 (PDT) From: Bart Van Assche To: "Martin K . Petersen" , "James E . J . Bottomley" CC: Nicholas Bellinger , Christoph Hellwig , , Bart Van Assche , Hannes Reinecke , Mike Christie Subject: [PATCH 09/11] target/iscsi: Fix a race condition in iscsit_add_reject_from_cmd() Date: Tue, 31 Oct 2017 11:03:17 -0700 Message-ID: <20171031180319.19258-10-bart.vanassche@wdc.com> X-Mailer: git-send-email 2.14.2 In-Reply-To: <20171031180319.19258-1-bart.vanassche@wdc.com> References: <20171031180319.19258-1-bart.vanassche@wdc.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrAJMWRmVeSWpSXmKPExsXCtZEjRffVrh+RBsueWlpc+vOF0WLBm71s FitXH2WyWDUxz2L58X9MFuuPbGC0aFt9htGidelbJgcOj/vbjzB5PDi0mcVj980GNo+PT2+x eLzfd5XNY/2WqywenzfJebQf6GYK4IjisklJzcksSy3St0vgyth+YA9jwQbOitYbLewNjC/Z uxg5OCQETCQOrffoYuTiEBJYzSjx6OIsxi5GTg42AT2JU/P2MYHYIgK5Eqce3mACKWIWeMIo 0fJzH1izsECkxORfeSAmi4CqRPM1GRCTV8BG4uBSY5BOCQF5ifcL7oNN5AQKv+3ZzQJiCwlY S1zbu4R5AiP3AkaGVYxiuZk5xbnpmQWGRnrFiXkpmcXZesn5uZsYwWHEGbWD8fpE80OMTByc Ug2MpVc+WO6Z7jZ1T/m/Bdzc1yVf5Z0LiNj+y/ZWZeSbZ1lP3Go4T6+4o5+w563lgb8bDrHv 4fh99YKt+YM3V0Stly77U21/8OSCtaGtW37lP1d+sVG/anGA0sPU/fl3m+8t3l91xHxy/9/J 9vXa2yNts3/7Hy5bu1hFc47WDm25rPQ7uVtXXVd/0KbEUpyRaKjFXFScCAAcdhgs0wEAAA== 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 Avoid that cmd->se_cmd.se_tfo is read after a command has already been freed. Signed-off-by: Bart Van Assche Cc: Nicholas Bellinger Cc: Christoph Hellwig Cc: Hannes Reinecke Cc: Mike Christie Reviewed-by: Hannes Reinecke --- drivers/target/iscsi/iscsi_target.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/target/iscsi/iscsi_target.c b/drivers/target/iscsi/iscsi_target.c index 91fbada7cdc2..541f66a875fc 100644 --- a/drivers/target/iscsi/iscsi_target.c +++ b/drivers/target/iscsi/iscsi_target.c @@ -833,6 +833,7 @@ static int iscsit_add_reject_from_cmd( unsigned char *buf) { struct iscsi_conn *conn; + const bool do_put = cmd->se_cmd.se_tfo != NULL; if (!cmd->conn) { pr_err("cmd->conn is NULL for ITT: 0x%08x\n", @@ -863,7 +864,7 @@ static int iscsit_add_reject_from_cmd( * Perform the kref_put now if se_cmd has already been setup by * scsit_setup_scsi_cmd() */ - if (cmd->se_cmd.se_tfo != NULL) { + if (do_put) { pr_debug("iscsi reject: calling target_put_sess_cmd >>>>>>\n"); target_put_sess_cmd(&cmd->se_cmd); }