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 22C851527AC; Fri, 6 Dec 2024 15:12:54 +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=1733497974; cv=none; b=rOFCwrvtgPfqytb7ofXRdnpND/PpB0kj8PF2JdhnRlNjWXmrm3w8LL+djg42sp8gQhus4PdQtsOBPNIokkcxGXhReo8n5nIti2cERXy9SfGhluwlemQcXHGTQSycAM1OQn05O7wbxCSZ6m7HL1zGzdRLWxY+fnNckGhN2osQxdU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733497974; c=relaxed/simple; bh=W+a9ZDLBrEMbxi6c+8Og+iPDOcqabWt6qrMayfIk3vE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=T4GtzS78pj4RXG90g36tvvTZ2g7YyPy0IGlsN6i0Zh7xvANd1iQcIvH+1GCHiPUakq3USuzQewlDfv3NJc+XBnCHY7Vp0jP9a3d9VXv+fmoIGLQ+NEXsQrZ3hwzWXPgd2eoeFtcLXdhI0o+ZNlyhwoAdjQNU84uadPI1tij4igg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=gLcoSbMY; 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="gLcoSbMY" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 82638C4CED1; Fri, 6 Dec 2024 15:12:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1733497974; bh=W+a9ZDLBrEMbxi6c+8Og+iPDOcqabWt6qrMayfIk3vE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gLcoSbMYGxLkx85CV7Qhu/fqneMb++/MZ17wCx6lYkPYETyNOWyeq4K67ULL3Nmpf V0coh5GtX12gKKjOaaHsL1RkxdFA4p2/R9W8hIIVDCxPOY5msKBp8lh0/VLnr001B0 fpxrdim6+WuVnNs9WUt2fvIKFqMeeRk88ffmCAuA= 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 Subject: [PATCH 6.6 447/676] nvme: fix metadata handling in nvme-passthrough Date: Fri, 6 Dec 2024 15:34:26 +0100 Message-ID: <20241206143710.829435088@linuxfoundation.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241206143653.344873888@linuxfoundation.org> References: <20241206143653.344873888@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 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Puranjay Mohan commit 7c2fd76048e95dd267055b5f5e0a48e6e7c81fd9 upstream. 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 [ Minor changes to make it work on 6.6 ] Signed-off-by: Hagar Hemdan Signed-off-by: Greg Kroah-Hartman --- drivers/nvme/host/ioctl.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) --- a/drivers/nvme/host/ioctl.c +++ b/drivers/nvme/host/ioctl.c @@ -3,6 +3,7 @@ * Copyright (c) 2011-2014, Intel Corporation. * Copyright (c) 2017-2021 Christoph Hellwig. */ +#include #include /* for force_successful_syscall_return */ #include #include @@ -171,10 +172,15 @@ static int nvme_map_user_request(struct 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; void *meta = NULL; int ret; + if (has_metadata && !supports_metadata) + return -EINVAL; + if (ioucmd && (ioucmd->flags & IORING_URING_CMD_FIXED)) { struct iov_iter iter; @@ -198,7 +204,7 @@ static int nvme_map_user_request(struct if (bdev) bio_set_dev(bio, bdev); - if (bdev && meta_buffer && meta_len) { + if (has_metadata) { meta = nvme_add_user_metadata(req, meta_buffer, meta_len, meta_seed); if (IS_ERR(meta)) {