From mboxrd@z Thu Jan 1 00:00:00 1970 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 6B754C369D2 for ; Wed, 25 Sep 2024 11:43:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=w8E8zuGVd/pAA5JWT4obFOBAbeIgNymj1+CS/0Fcnv8=; b=3PlrGzDtfT0RLedSDcWcVIMYUg A9p/4NrJiH4IbX4W9gQPuHiOTYrhUe1spHHEKS2OHghkMzO+JQjlTBY/+86cH29r4fpzlazKt5/6a 0UcHBxfdN/+lJ7KIloIK3XWbBogTMMv8Mk10rJGjQe+qJPVHR71nwRxMuLxzFp6kj/9flSUvU7yV+ dugylAM7weUQRcjdDhmMUYu0aI2vP2PF9Sq16CFgjqDAvsY1e++OzudMiMiRlqOP8Zrtilz9nIps8 wa5WUpsOGd95Xcr4rMbczB+upUv0fpsPtJ92BrJUUrdRwBnIBL9L444jix7XkMdmt7sXff/SAo0ok XuYFqlNQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1stQQN-00000004voj-1iri; Wed, 25 Sep 2024 11:43:15 +0000 Received: from nyc.source.kernel.org ([147.75.193.91]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1stQMc-00000004uHo-10b1 for linux-nvme@lists.infradead.org; Wed, 25 Sep 2024 11:39:24 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id 381E6A43F23; Wed, 25 Sep 2024 11:39:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D4A2BC4CEC3; Wed, 25 Sep 2024 11:39:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727264361; bh=t3kZ2mC0WHLQzVHQ7DFGA/qiG5jdhOk8qzbT0y53czo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KEWeEhWioseJNQsV05IVr79un+kUFL2KXKUx7Yh5OPwjEWDiG1ELzngaHzEL2iP7Z FQ8QjiAyKDKTrSLbZD5JQ3PRgEy7+PyjtnI6g6UEhKSNPl2Hfktxcvw4XAwF6ADSRn da1SVfbClH+vnjuMzeEWEq4Y/8z5+Qt/UCd2ig2XdNQUjkeDEb5NWOuLhtaBNF24A4 DpmIQhEVAB5y73/m02Q8cQMMj4uJeWUoV6wHsRUaxsjPGllpuRivFJjx/Fift5jpgz pdPb8oLs9kNxSln6HH43uQP1b9w7yAkNKESt46t2UNd0XFlJaEGQxlxvGNDyZiELYd wWHNgg6n4PTZw== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Puranjay Mohan , Christoph Hellwig , Sagi Grimberg , Anuj Gupta , Keith Busch , Sasha Levin , linux-nvme@lists.infradead.org Subject: [PATCH AUTOSEL 6.11 067/244] nvme: fix metadata handling in nvme-passthrough Date: Wed, 25 Sep 2024 07:24:48 -0400 Message-ID: <20240925113641.1297102-67-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240925113641.1297102-1-sashal@kernel.org> References: <20240925113641.1297102-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 6.11 Content-Transfer-Encoding: 8bit X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240925_043922_501764_D00A7246 X-CRM114-Status: GOOD ( 16.84 ) X-BeenThere: linux-nvme@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-nvme" Errors-To: linux-nvme-bounces+linux-nvme=archiver.kernel.org@lists.infradead.org From: Puranjay Mohan [ Upstream commit 7c2fd76048e95dd267055b5f5e0a48e6e7c81fd9 ] On an NVMe namespace that does not support metadata, it is possible to send an IO command with metadata through io-passthru. This allows issues like [1] to trigger in the completion code path. nvme_map_user_request() doesn't check if the namespace supports metadata before sending it forward. It also allows admin commands with metadata to be processed as it ignores metadata when bdev == NULL and may report success. Reject an IO command with metadata when the NVMe namespace doesn't support it and reject an admin command if it has metadata. [1] https://lore.kernel.org/all/mb61pcylvnym8.fsf@amazon.com/ Suggested-by: Christoph Hellwig Signed-off-by: Puranjay Mohan Reviewed-by: Christoph Hellwig Reviewed-by: Sagi Grimberg Reviewed-by: Anuj Gupta Signed-off-by: Keith Busch Signed-off-by: Sasha Levin --- drivers/nvme/host/ioctl.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/drivers/nvme/host/ioctl.c b/drivers/nvme/host/ioctl.c index f1d58e70933f5..15c93ce07e263 100644 --- a/drivers/nvme/host/ioctl.c +++ b/drivers/nvme/host/ioctl.c @@ -4,6 +4,7 @@ * Copyright (c) 2017-2021 Christoph Hellwig. */ #include +#include #include /* for force_successful_syscall_return */ #include #include @@ -119,9 +120,14 @@ static int nvme_map_user_request(struct request *req, u64 ubuffer, struct request_queue *q = req->q; struct nvme_ns *ns = q->queuedata; struct block_device *bdev = ns ? ns->disk->part0 : NULL; + bool supports_metadata = bdev && blk_get_integrity(bdev->bd_disk); + bool has_metadata = meta_buffer && meta_len; struct bio *bio = NULL; int ret; + if (has_metadata && !supports_metadata) + return -EINVAL; + if (ioucmd && (ioucmd->flags & IORING_URING_CMD_FIXED)) { struct iov_iter iter; @@ -143,15 +149,15 @@ static int nvme_map_user_request(struct request *req, u64 ubuffer, goto out; bio = req->bio; - if (bdev) { + if (bdev) bio_set_dev(bio, bdev); - if (meta_buffer && meta_len) { - ret = bio_integrity_map_user(bio, meta_buffer, meta_len, - meta_seed); - if (ret) - goto out_unmap; - req->cmd_flags |= REQ_INTEGRITY; - } + + if (has_metadata) { + ret = bio_integrity_map_user(bio, meta_buffer, meta_len, + meta_seed); + if (ret) + goto out_unmap; + req->cmd_flags |= REQ_INTEGRITY; } return ret; -- 2.43.0