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 A2B7D213E9F; Thu, 12 Dec 2024 17:15:22 +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=1734023722; cv=none; b=T+jNzSRZ0D6ALRlfrRyNniVDO9Gv/vnGRShnT5dzsueUFfmwXFcCBPdWubnGiDG2DrQjfsJCgFQsJ591N4Yp/0fiYH7OiQLa4FcIcLnDlLG7Z3sBon4LCMiqD5HK1LiGTO8I/eqnIqGhqXFSmGX7UqdKwrngCt2uc18Pvapy/YM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734023722; c=relaxed/simple; bh=TF5HXk99vAgDN8RVbg+ui5JraA2Agub03ZiFlf4/uoQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=T+GYYeGzcVK8AGnxzrQsA036Jr8avSJuBFYw6W/CVPn8McWFZykihj+HZkfo8l2BZI1gEfpp8K82HscDCOscrNuQSGntvJkLePt04jMfijlfJHM9JaR8fEtgA4Ll+UtIqv/MwaiFZ9qIZonUvHufamfzMA92scP5wdQqwD5ERo8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=LQdmh674; 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="LQdmh674" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D6955C4CECE; Thu, 12 Dec 2024 17:15:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1734023722; bh=TF5HXk99vAgDN8RVbg+ui5JraA2Agub03ZiFlf4/uoQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LQdmh674gy35mNBpp9xE2PtoEqFV3Fq26Rsq90mOpSQIk5LgcU7IsHGD2HrhNaJMd IgbHI6824MmIWPQrpP2MYUA4/EgUU3BtFAS1PGn7iON+q1wShqLps2/ffY5hr1jk7C //5is7VDgYVxE82MPCBjE9El/GkHJ2UxB4L5mScw= 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 5.10 053/459] nvme: fix metadata handling in nvme-passthrough Date: Thu, 12 Dec 2024 15:56:31 +0100 Message-ID: <20241212144255.617489969@linuxfoundation.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241212144253.511169641@linuxfoundation.org> References: <20241212144253.511169641@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 5.10-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 5.10 ] Signed-off-by: Puranjay Mohan 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 30a642c8f5374..bee55902fe6ce 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -1121,11 +1121,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); if (IS_ERR(req)) return PTR_ERR(req); @@ -1141,7 +1146,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