From nobody Mon Sep 8 08:46:42 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 52A22C6FA89 for ; Tue, 13 Sep 2022 15:05:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235245AbiIMPFr (ORCPT ); Tue, 13 Sep 2022 11:05:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54206 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235254AbiIMPDo (ORCPT ); Tue, 13 Sep 2022 11:03:44 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1E52E12AE8; Tue, 13 Sep 2022 07:30:02 -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 ams.source.kernel.org (Postfix) with ESMTPS id A8E76B80F1A; Tue, 13 Sep 2022 14:29:52 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 198D7C433C1; Tue, 13 Sep 2022 14:29:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1663079391; bh=qCVth4/8yW7umEyG9bOFYKwyaYG5yoB7+h3QeJB41SU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vu8qtabrWj6dmokDx5BrQTpMwwVb2IMu7n7hJdEjKN6hdzSvGpd3WTaNonBhZuHAr dRCxIj9wlnHmZTMFrX4+qvw5TohM2hxrrWk/R73+P5bHqYYrHfbKv9Bvkr4/YIYG7t enreVNolcJnLa9K1g3iwT4gd5MgMKCXEs6162uL4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Bart Van Assche , Christoph Hellwig Subject: [PATCH 5.4 082/108] nvmet: fix a use-after-free Date: Tue, 13 Sep 2022 16:06:53 +0200 Message-Id: <20220913140357.151512934@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220913140353.549108748@linuxfoundation.org> References: <20220913140353.549108748@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Bart Van Assche commit 6a02a61e81c231cc5c680c5dbf8665275147ac52 upstream. 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: Greg Kroah-Hartman --- drivers/nvme/target/core.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) --- a/drivers/nvme/target/core.c +++ b/drivers/nvme/target/core.c @@ -709,6 +709,8 @@ static void nvmet_set_error(struct nvmet =20 static void __nvmet_req_complete(struct nvmet_req *req, u16 status) { + struct nvmet_ns *ns =3D req->ns; + if (!req->sq->sqhd_disabled) nvmet_update_sq_head(req); req->cqe->sq_id =3D cpu_to_le16(req->sq->qid); @@ -719,9 +721,9 @@ static void __nvmet_req_complete(struct =20 trace_nvmet_req_complete(req); =20 - if (req->ns) - nvmet_put_namespace(req->ns); req->ops->queue_response(req); + if (ns) + nvmet_put_namespace(ns); } =20 void nvmet_req_complete(struct nvmet_req *req, u16 status)