From patchwork Tue Jul 25 19:20:46 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 9862931 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 35C24600F5 for ; Tue, 25 Jul 2017 19:26:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1E7B9285FC for ; Tue, 25 Jul 2017 19:26:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 131742869C; Tue, 25 Jul 2017 19:26:16 +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=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 9AEFD285FC for ; Tue, 25 Jul 2017 19:26:15 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1da5R2-0004hm-1D; Tue, 25 Jul 2017 19:24:00 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1da5R1-0004hf-DM for xen-devel@lists.xenproject.org; Tue, 25 Jul 2017 19:23:59 +0000 Received: from [193.109.254.147] by server-11.bemta-6.messagelabs.com id A0/A8-03612-ECA97795; Tue, 25 Jul 2017 19:23:58 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprKIsWRWlGSWpSXmKPExsXSc3klj+7ZWeW RBusnWVl83zKZyYHR4/CHKywBjFGsmXlJ+RUJrBnnN29hL+iQrjgx4x1jA+N68S5GLg4hga2M Emd7NzB3MXJwsAmYSsz4r9LFyMkhIqAgsbn3GStIDbPAeSaJNSeesoMkhAV8JP5/WcEKYrMIq Ers7VrFCGLzClhJnJn+GsyWEJCXmNg7DczmFLCW+Lx5ChPIfCGgmr5LuiBhUQExiYPv7jNBtA pKnJz5hAWkhFlAXWL9PKEJjLyzkGRmIWQWMDKtYtQoTi0qSy3SNbLUSyrKTM8oyU3MzNE1NDD Ty00tLk5MT81JTCrWS87P3cQIDBwGINjBeGBR4CFGSQ4mJVHeb7rlkUJ8SfkplRmJxRnxRaU5 qcWHGGU4OJQkeFVmAuUEi1LTUyvSMnOAIQyTluDgURLhXQiS5i0uSMwtzkyHSJ1iNObYsHr9F yaOVxP+f2MSYsnLz0uVEueVBSkVACnNKM2DGwSLrUuMslLCvIxApwnxFKQW5WaWoMq/YhTnYF QS5s0DmcKTmVcCt+8V0ClMQKfMmVEKckpJIkJKqoFxo9ASExnhl1f0Iu7/nJLorHvwHmPlnK/ N+3+qFPDN/TbVa51Y4/lAt8Q/7m90WB3NWG22/N30eEKt7oTwXdmTHgdYzdipvyF7d0z5bo2D nZdNJGqM1hytaD1wc/M2t8qPjat62t9aXor+ZNkq/+rf/oj/2x9e0uz/nHfps5wfx+mv3Amdb Ea/lFiKMxINtZiLihMBfglQsqgCAAA= X-Env-Sender: gregkh@linuxfoundation.org X-Msg-Ref: server-7.tower-27.messagelabs.com!1501010636!104239820!1 X-Originating-IP: [140.211.169.12] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.4.25; banners=-,-,- X-VirusChecked: Checked Received: (qmail 63483 invoked from network); 25 Jul 2017 19:23:57 -0000 Received: from mail.linuxfoundation.org (HELO mail.linuxfoundation.org) (140.211.169.12) by server-7.tower-27.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 25 Jul 2017 19:23:57 -0000 Received: from localhost (rrcs-64-183-28-114.west.biz.rr.com [64.183.28.114]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id A6630982; Tue, 25 Jul 2017 19:23:55 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Date: Tue, 25 Jul 2017 12:20:46 -0700 Message-Id: <20170725192048.947682613@linuxfoundation.org> X-Mailer: git-send-email 2.13.3 In-Reply-To: <20170725192046.422343510@linuxfoundation.org> References: <20170725192046.422343510@linuxfoundation.org> User-Agent: quilt/0.65 MIME-Version: 1.0 Cc: Juergen Gross , Hannes Reinecke , xen-devel@lists.xenproject.org, Greg Kroah-Hartman , stable@vger.kernel.org, Nicholas Bellinger , David Disseldorp , Bart Van Assche , Christoph Hellwig Subject: [Xen-devel] [PATCH 4.12 047/196] xen/scsiback: Fix a TMR related use-after-free X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP 4.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Bart Van Assche commit 9f4ab18ac51dc87345a9cbd2527e6acf7a0a9335 upstream. scsiback_release_cmd() must not dereference se_cmd->se_tmr_req because that memory is freed by target_free_cmd_mem() before scsiback_release_cmd() is called. Fix this use-after-free by inlining struct scsiback_tmr into struct vscsibk_pend. Signed-off-by: Bart Van Assche Reviewed-by: Juergen Gross Cc: Christoph Hellwig Cc: Hannes Reinecke Cc: David Disseldorp Cc: xen-devel@lists.xenproject.org Signed-off-by: Nicholas Bellinger Signed-off-by: Greg Kroah-Hartman --- drivers/xen/xen-scsiback.c | 33 +++++++++------------------------ 1 file changed, 9 insertions(+), 24 deletions(-) --- a/drivers/xen/xen-scsiback.c +++ b/drivers/xen/xen-scsiback.c @@ -134,9 +134,7 @@ struct vscsibk_pend { struct page *pages[VSCSI_MAX_GRANTS]; struct se_cmd se_cmd; -}; -struct scsiback_tmr { atomic_t tmr_complete; wait_queue_head_t tmr_wait; }; @@ -599,26 +597,20 @@ static void scsiback_device_action(struc struct scsiback_tpg *tpg = pending_req->v2p->tpg; struct scsiback_nexus *nexus = tpg->tpg_nexus; struct se_cmd *se_cmd = &pending_req->se_cmd; - struct scsiback_tmr *tmr; u64 unpacked_lun = pending_req->v2p->lun; int rc, err = FAILED; - tmr = kzalloc(sizeof(struct scsiback_tmr), GFP_KERNEL); - if (!tmr) { - target_put_sess_cmd(se_cmd); - goto err; - } - - init_waitqueue_head(&tmr->tmr_wait); + init_waitqueue_head(&pending_req->tmr_wait); rc = target_submit_tmr(&pending_req->se_cmd, nexus->tvn_se_sess, &pending_req->sense_buffer[0], - unpacked_lun, tmr, act, GFP_KERNEL, + unpacked_lun, NULL, act, GFP_KERNEL, tag, TARGET_SCF_ACK_KREF); if (rc) goto err; - wait_event(tmr->tmr_wait, atomic_read(&tmr->tmr_complete)); + wait_event(pending_req->tmr_wait, + atomic_read(&pending_req->tmr_complete)); err = (se_cmd->se_tmr_req->response == TMR_FUNCTION_COMPLETE) ? SUCCESS : FAILED; @@ -626,9 +618,8 @@ static void scsiback_device_action(struc scsiback_do_resp_with_sense(NULL, err, 0, pending_req); transport_generic_free_cmd(&pending_req->se_cmd, 1); return; + err: - if (tmr) - kfree(tmr); scsiback_do_resp_with_sense(NULL, err, 0, pending_req); } @@ -1389,12 +1380,6 @@ static int scsiback_check_stop_free(stru static void scsiback_release_cmd(struct se_cmd *se_cmd) { struct se_session *se_sess = se_cmd->se_sess; - struct se_tmr_req *se_tmr = se_cmd->se_tmr_req; - - if (se_tmr && se_cmd->se_cmd_flags & SCF_SCSI_TMR_CDB) { - struct scsiback_tmr *tmr = se_tmr->fabric_tmr_ptr; - kfree(tmr); - } percpu_ida_free(&se_sess->sess_tag_pool, se_cmd->map_tag); } @@ -1455,11 +1440,11 @@ static int scsiback_queue_status(struct static void scsiback_queue_tm_rsp(struct se_cmd *se_cmd) { - struct se_tmr_req *se_tmr = se_cmd->se_tmr_req; - struct scsiback_tmr *tmr = se_tmr->fabric_tmr_ptr; + struct vscsibk_pend *pending_req = container_of(se_cmd, + struct vscsibk_pend, se_cmd); - atomic_set(&tmr->tmr_complete, 1); - wake_up(&tmr->tmr_wait); + atomic_set(&pending_req->tmr_complete, 1); + wake_up(&pending_req->tmr_wait); } static void scsiback_aborted_task(struct se_cmd *se_cmd)