From patchwork Tue Jul 25 19:19:12 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 9862881 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 169E6600F5 for ; Tue, 25 Jul 2017 19:23:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 01F6326E76 for ; Tue, 25 Jul 2017 19:23:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EADDB285DB; Tue, 25 Jul 2017 19:23:48 +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 5316926E76 for ; Tue, 25 Jul 2017 19:23:47 +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 1da5OP-0004Y8-K3; Tue, 25 Jul 2017 19:21:17 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1da5OP-0004Y2-1J for xen-devel@lists.xenproject.org; Tue, 25 Jul 2017 19:21:17 +0000 Received: from [85.158.139.211] by server-4.bemta-5.messagelabs.com id D1/96-02184-C2A97795; Tue, 25 Jul 2017 19:21:16 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprCIsWRWlGSWpSXmKPExsXSc3klj672rPJ Igx2f1S2+b5nM5MDocfjDFZYAxijWzLyk/IoE1oz7x64yFbRLV1w65NvAuE68i5GLQ0hgK6PE 7OcP2boYOTjYBEwlZvxX6WLk5BARUJDY3PuMFaSGWeA8k8SaE0/ZQRLCAt4SDReng9ksAqoSz csXMYPYvAJWEg92XmMFsSUE5CUm9k5jBLE5Bawlrh5exwRiCwHVfP8yE8wWFRCTOPjuPhNEr6 DEyZlPWEBuYBZQl1g/T2gCI+8sJJlZCJkFjEyrGNWLU4vKUot0LfWSijLTM0pyEzNzdA0NTPV yU4uLE9NTcxKTivWS83M3MQLDhgEIdjCubXU+xCjJwaQkyvtNtzxSiC8pP6UyI7E4I76oNCe1 +BCjDAeHkgSvykygnGBRanpqRVpmDjCAYdISHDxKIrzFM4DSvMUFibnFmekQqVOMxhwbVq//w sTxasL/b0xCLHn5ealS4ryyIJMEQEozSvPgBsEi6xKjrJQwLyPQaUI8BalFuZklqPKvGMU5GJ WEeXeALOTJzCuB2/cK6BQmoFPmzCgFOaUkESEl1cCocDKG44T7igVbEpu9FPYsXhWsHrPl6ro ZcVuv1PqnvY8tWX9/4VbLHqklf4PXn0vST7zSIzzrplZ66Z+bq16pOogYHu0O+a1zlaVD2vT0 G6eQKoO3RnYh/QcYJWIUNdatbY9I/iNnuHjKp+DK9qmpD5ebcL4TnB6V9MZr2nEJ/idXP97os vyhxFKckWioxVxUnAgABoNWsKcCAAA= X-Env-Sender: gregkh@linuxfoundation.org X-Msg-Ref: server-14.tower-206.messagelabs.com!1501010474!65656411!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 60760 invoked from network); 25 Jul 2017 19:21:15 -0000 Received: from mail.linuxfoundation.org (HELO mail.linuxfoundation.org) (140.211.169.12) by server-14.tower-206.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 25 Jul 2017 19:21:15 -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 2C4D7A86; Tue, 25 Jul 2017 19:21:13 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Date: Tue, 25 Jul 2017 12:19:12 -0700 Message-Id: <20170725192016.331366693@linuxfoundation.org> X-Mailer: git-send-email 2.13.3 In-Reply-To: <20170725192014.314851996@linuxfoundation.org> References: <20170725192014.314851996@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.9 037/125] 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.9-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)