From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3F2611F4276; Tue, 3 Dec 2024 14:33:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733236426; cv=none; b=Ukf8Tq4WdAAeo4WpzbkMQOPZEh8DPq9yZHV3jyJZaIALxG3NZnOqobkelTDfclEIrU8/mwtRdViHp8E8Ot2zVDqYJYT55sVxJXTkp8RRIBWvaHQoeFsLvQuHozckIslceSWHHCYd0KNuWySyPxT9i1edg7u8YIfEkKKbiGPcVdc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733236426; c=relaxed/simple; bh=gSbCp1fbFV7f5MaQiOitXRGBbtI4YZHeyTKJSZItU0k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=S1erbqxPqihiLnqQE6ZzRGvJtYvhrwIS27YCBbonPDAq32gzI5L41GaOW26iE9jeABVMIlyyEGffRtLkXhU4zqw/sCnB62BIagXWS5JBHuhfaOBV9rklyLbkmUxUJyMuxB4ycDt4cUPAQcjIhz9Tp2sWslzmlB+IG7mxWjwFb2k= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=V9aXHv17; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="V9aXHv17" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4F829C4CECF; Tue, 3 Dec 2024 14:33:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1733236425; bh=gSbCp1fbFV7f5MaQiOitXRGBbtI4YZHeyTKJSZItU0k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=V9aXHv17Pd0g30cx60IbwvZkerfBFC3mV4/lBNRkkNjjdgwJeSM9cGu1VpiE+hrX+ 5DvhRyLkPHge8QuWnvbakvR9Jc8yC8LCZC7vSgiueKLlrhV18HntRstF498xkkBghu asfN6bbaT/I5zwEwqeyL/ESwCkNRDOdwkxFCapok= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Christoph Hellwig , Puranjay Mohan , Sagi Grimberg , Anuj Gupta , Keith Busch , Hagar Hemdan , Sasha Levin Subject: [PATCH 4.19 016/138] nvme: fix metadata handling in nvme-passthrough Date: Tue, 3 Dec 2024 15:30:45 +0100 Message-ID: <20241203141924.166757779@linuxfoundation.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241203141923.524658091@linuxfoundation.org> References: <20241203141923.524658091@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 4.19-stable review patch. If anyone has any objections, please let me know. ------------------ 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 [ Move the changes from nvme_map_user_request() to nvme_submit_user_cmd() to make it work on 4.19 ] Signed-off-by: Hagar Hemdan Signed-off-by: Sasha Levin --- drivers/nvme/host/core.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c index 6adff541282be..fcf062f3b507d 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -802,11 +802,16 @@ static int nvme_submit_user_cmd(struct request_queue *q, bool write = nvme_is_write(cmd); struct nvme_ns *ns = q->queuedata; struct gendisk *disk = ns ? ns->disk : NULL; + bool supports_metadata = disk && blk_get_integrity(disk); + bool has_metadata = meta_buffer && meta_len; struct request *req; struct bio *bio = NULL; void *meta = NULL; int ret; + if (has_metadata && !supports_metadata) + return -EINVAL; + req = nvme_alloc_request(q, cmd, 0, NVME_QID_ANY); if (IS_ERR(req)) return PTR_ERR(req); @@ -821,7 +826,7 @@ static int nvme_submit_user_cmd(struct request_queue *q, goto out; bio = req->bio; bio->bi_disk = disk; - if (disk && meta_buffer && meta_len) { + if (has_metadata) { meta = nvme_add_user_metadata(bio, meta_buffer, meta_len, meta_seed, write); if (IS_ERR(meta)) { -- 2.43.0