Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp777978rwb; Mon, 26 Sep 2022 05:52:52 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4WCS5p7J5oN4TaoMxyIlMgyB13sdDbJIib1ci2QMim8joGhn4V+dovRwuD43bF1eMQFPe7 X-Received: by 2002:a17:907:a0c7:b0:77c:d4ac:e8f1 with SMTP id hw7-20020a170907a0c700b0077cd4ace8f1mr18368691ejc.354.1664196772591; Mon, 26 Sep 2022 05:52:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664196772; cv=none; d=google.com; s=arc-20160816; b=H/XU+bp7qihxkrw+IcFkw2U32NCiTl+Tm38axP9Kw7aDnwY5mTKfk0OPHk7TvD/pJr SNUi8aViJAJuSZFCDaE3qPXzRqVOkqLaA3OEgCtJiMTUWFOv7icIgw4ObGj7C48HOu3J E4NrheCXvS3GMcwQX48uWSW0yIV6M36Eao0N8H+Erpiwa4HWiVzA1v3R4YzGAK+l1p9M aV9Y9xngUwW2sNFNkxdbH/CxlDU6wB9QYW0NfoFDmIXo4et1cr8Uw2+HFLBJrVCL44Hs aN+gQtQQ6N0fP3s9yJeABzUeY+mGgjUchxCO0/aXyIi7McsW5nAaykJe9u1e/1tM0R1L Cvdw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=pdW7/rcTK0Lw4Oajob1+tGQ1g59xQLcA5oLlYX/H7b4=; b=TCO3F9y/ZpCtQx10N+UYCoDuTskqXXxNM+Z0sbsYYWvKrsMmzfWTXYVN7Toxcilx31 SZn9vCPJeQVFS2mdetxQ/4BNmSRPzEtVZiJ4RNAyl/Zp7g6JCOUGAv9Z3zHah0ErlYug gBO3lFJwFiKePt6pMT6SQcodYyE3XjHors+5emg9VTpffhmmFUCkWSuj82VitV3o2RV1 LZPJdurNHhLRjYeD1gXmVdWHfQ70KKMrk+X0f1CoegfUb8SCkRMrQdFkAQXsZItTY7dn DuDYY/bSXfwqo6R82Hbs1Dq0I3tDg3345M/xH8+9WGEuAzIxdSJ69+PAqcdF6TBnS9lk J7vw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=vpFBRUlS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j11-20020a508a8b000000b004539a0fc32dsi15270659edj.317.2022.09.26.05.52.27; Mon, 26 Sep 2022 05:52:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=vpFBRUlS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235325AbiIZK1k (ORCPT + 99 others); Mon, 26 Sep 2022 06:27:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34584 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235709AbiIZKYo (ORCPT ); Mon, 26 Sep 2022 06:24:44 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D25A914D21; Mon, 26 Sep 2022 03:18:03 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 97B5660BB7; Mon, 26 Sep 2022 10:17:53 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 90EBDC433C1; Mon, 26 Sep 2022 10:17:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1664187473; bh=txTZLVjtLQkcTi+soDlGB8fViSjcCVpczDKhYZmxGqk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vpFBRUlSW8PLLuVwXJSNyZrJ5+qTPF9wjyzjPZWr3jpGFBwANRdrb5TIwdP0KUk/z XTY3pxYKGLzCPggOclmN2iSfPk4kjLsmA+nS8NjFK79WW/ToOg4J6vZLNqJ18+qSdJ 8u0q663qvKIZWgGpAVPVSzOM6IwGXp9+f0H1DmNA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Bart Van Assche , Christoph Hellwig , Sasha Levin Subject: [PATCH 4.19 07/58] nvmet: fix a use-after-free Date: Mon, 26 Sep 2022 12:11:26 +0200 Message-Id: <20220926100741.687815267@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220926100741.430882406@linuxfoundation.org> References: <20220926100741.430882406@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Bart Van Assche [ Upstream commit 6a02a61e81c231cc5c680c5dbf8665275147ac52 ] Fix the following use-after-free complaint triggered by blktests nvme/004: BUG: KASAN: user-memory-access in blk_mq_complete_request_remote+0xac/0x350 Read of size 4 at addr 0000607bd1835943 by task kworker/13:1/460 Workqueue: nvmet-wq nvme_loop_execute_work [nvme_loop] Call Trace: show_stack+0x52/0x58 dump_stack_lvl+0x49/0x5e print_report.cold+0x36/0x1e2 kasan_report+0xb9/0xf0 __asan_load4+0x6b/0x80 blk_mq_complete_request_remote+0xac/0x350 nvme_loop_queue_response+0x1df/0x275 [nvme_loop] __nvmet_req_complete+0x132/0x4f0 [nvmet] nvmet_req_complete+0x15/0x40 [nvmet] nvmet_execute_io_connect+0x18a/0x1f0 [nvmet] nvme_loop_execute_work+0x20/0x30 [nvme_loop] process_one_work+0x56e/0xa70 worker_thread+0x2d1/0x640 kthread+0x183/0x1c0 ret_from_fork+0x1f/0x30 Cc: stable@vger.kernel.org Fixes: a07b4970f464 ("nvmet: add a generic NVMe target") Signed-off-by: Bart Van Assche Signed-off-by: Christoph Hellwig Signed-off-by: Sasha Levin --- drivers/nvme/target/core.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/nvme/target/core.c b/drivers/nvme/target/core.c index 1a35d73c39c3..80b5aae1bdc9 100644 --- a/drivers/nvme/target/core.c +++ b/drivers/nvme/target/core.c @@ -504,6 +504,7 @@ static void __nvmet_req_complete(struct nvmet_req *req, u16 status) { u32 old_sqhd, new_sqhd; u16 sqhd; + struct nvmet_ns *ns = req->ns; if (status) nvmet_set_status(req, status); @@ -520,9 +521,9 @@ static void __nvmet_req_complete(struct nvmet_req *req, u16 status) req->rsp->sq_id = cpu_to_le16(req->sq->qid); req->rsp->command_id = req->cmd->common.command_id; - if (req->ns) - nvmet_put_namespace(req->ns); req->ops->queue_response(req); + if (ns) + nvmet_put_namespace(ns); } void nvmet_req_complete(struct nvmet_req *req, u16 status) -- 2.35.1