From patchwork Tue Jun 23 19:56:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 223234 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.0 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C0C43C433DF for ; Tue, 23 Jun 2020 21:14:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9EC9820702 for ; Tue, 23 Jun 2020 21:14:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1592946885; bh=7SiCr40mxqN8cAYDHS6gADa/pXDurxsfBtLVqOY735w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=D0PqmQ2exJdUXHKdbXYFjiaSHZJP93xh97oBSdD9Dpdqqs53rmM3LYH8B2AOJJlzS dUC4LtjI0NLgRZ+MnbaviIeOS0oX0eHxeFrVCFc23q+MB367Ob6i34TBkCDIoP+d9X AeZgga1jFugSocBUSbsuMjWyUso0phjEUJ0XMz8U= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391164AbgFWVOh (ORCPT ); Tue, 23 Jun 2020 17:14:37 -0400 Received: from mail.kernel.org ([198.145.29.99]:48946 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390934AbgFWU3A (ORCPT ); Tue, 23 Jun 2020 16:29:00 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 372CB2064B; Tue, 23 Jun 2020 20:29:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1592944140; bh=7SiCr40mxqN8cAYDHS6gADa/pXDurxsfBtLVqOY735w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=M0klOyi4g++JrZr5qPg7TqogcxMbcEGGUWNYEhpGpcTmnQl6dMxWXsKgsqtcHx9gH x/0KycVXkArdpf0LxOx4+ejjEFScd0cUEY9IKSgJ/c/qtooll9r8dEiZKPT+T5RQE+ GwpZzapMwROYppjvrmDoyEoszqikNYsXNc0LZZGo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Mike Christie , David Disseldorp , Dan Carpenter , "Martin K. Petersen" , Sasha Levin Subject: [PATCH 5.4 188/314] scsi: target: tcmu: Fix a use after free in tcmu_check_expired_queue_cmd() Date: Tue, 23 Jun 2020 21:56:23 +0200 Message-Id: <20200623195347.880864073@linuxfoundation.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200623195338.770401005@linuxfoundation.org> References: <20200623195338.770401005@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Dan Carpenter [ Upstream commit 9d7464b18892332e35ff37f0b024429a1a9835e6 ] The pr_debug() dereferences "cmd" after we already freed it by calling tcmu_free_cmd(cmd). The debug printk needs to be done earlier. Link: https://lore.kernel.org/r/20200523101129.GB98132@mwanda Fixes: 61fb24822166 ("scsi: target: tcmu: Userspace must not complete queued commands") Reviewed-by: Mike Christie Reviewed-by: David Disseldorp Signed-off-by: Dan Carpenter Signed-off-by: Martin K. Petersen Signed-off-by: Sasha Levin --- drivers/target/target_core_user.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/target/target_core_user.c b/drivers/target/target_core_user.c index 70c64e69a1d29..a497e7c1f4fcc 100644 --- a/drivers/target/target_core_user.c +++ b/drivers/target/target_core_user.c @@ -1292,13 +1292,13 @@ static void tcmu_check_expired_queue_cmd(struct tcmu_cmd *cmd) if (!time_after(jiffies, cmd->deadline)) return; + pr_debug("Timing out queued cmd %p on dev %s.\n", + cmd, cmd->tcmu_dev->name); + list_del_init(&cmd->queue_entry); se_cmd = cmd->se_cmd; tcmu_free_cmd(cmd); - pr_debug("Timing out queued cmd %p on dev %s.\n", - cmd, cmd->tcmu_dev->name); - target_complete_cmd(se_cmd, SAM_STAT_TASK_SET_FULL); }