From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp-fw-52004.amazon.com (smtp-fw-52004.amazon.com [52.119.213.154]) (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 21B8F19992D for ; Mon, 25 Nov 2024 12:10:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=52.119.213.154 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732536637; cv=none; b=Ck7FgkATp8hLr6of3XkKgXquj5qz5hFQkCXssfb+4ISdRQrC26+m7PWwRhvFkVbXZc+1coOBqOrDLkMeocVkno1XMdgC383ceAEKUk4T6BjQvaiyhVIplwshOsZ6jwOhW5orZ+zrsDZSu/eKjagg4ZWUIwWSJKFInX6rfQx3gdA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732536637; c=relaxed/simple; bh=L+9KSGjxrQweZD+UbRxPaZ2b8qNFoJ58Wa1z1LIUtuA=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=Uweo0JT0/6ljh0eJWd8U1LrzYNX8iw0LzWsd4+hedZUlizWtifuxpk8PDA2WWR6QLemnjZ82wgd9QZinD80oFC8Dp0j4g9ZJTKPcJAuW7/VGAkcBdMnCZAC/y4RR1xZFM2FaJHmu+6ypAVtImg8NzUe9NolYlDh6fUzD/LrQGIU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com; spf=pass smtp.mailfrom=amazon.com; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b=ayV3s4eZ; arc=none smtp.client-ip=52.119.213.154 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=amazon.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="ayV3s4eZ" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1732536637; x=1764072637; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=RqUWvFwb2lK5ezve66UQnRLCr2CsWg7NYYmXBa8owhg=; b=ayV3s4eZ8yYCq3GLjTH1KaDwY2bVRcINFx4V9EJNZtC2jZ7dzYAleqSh zz5uwUMYmIIAdDv2H0u+a/DCt4JjtCRwHIzLkdPkOjkfo27+RmtbUbXDn ilDN+oBOFfQKmZ0AZUtm1bztghKmapgDgylgxv3wvovjeSDPaZ5Qat+ef w=; X-IronPort-AV: E=Sophos;i="6.12,182,1728950400"; d="scan'208";a="249932978" Received: from iad6-co-svc-p1-lb1-vlan2.amazon.com (HELO smtpout.prod.us-west-2.prod.farcaster.email.amazon.dev) ([10.124.125.2]) by smtp-border-fw-52004.iad7.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Nov 2024 12:10:33 +0000 Received: from EX19MTAUWC001.ant.amazon.com [10.0.7.35:54240] by smtpin.naws.us-west-2.prod.farcaster.email.amazon.dev [10.0.52.223:2525] with esmtp (Farcaster) id 5edace04-9df3-4b2f-ab67-84b977e37bfb; Mon, 25 Nov 2024 12:10:32 +0000 (UTC) X-Farcaster-Flow-ID: 5edace04-9df3-4b2f-ab67-84b977e37bfb Received: from EX19EXOUWB002.ant.amazon.com (10.250.64.247) by EX19MTAUWC001.ant.amazon.com (10.250.64.174) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1258.34; Mon, 25 Nov 2024 12:10:32 +0000 Received: from EX19MTAUWB001.ant.amazon.com (10.250.64.248) by EX19EXOUWB002.ant.amazon.com (10.250.64.247) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1258.34; Mon, 25 Nov 2024 12:10:32 +0000 Received: from email-imr-corp-prod-pdx-1box-2b-8c2c6aed.us-west-2.amazon.com (10.25.36.214) by mail-relay.amazon.com (10.250.64.254) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1258.34 via Frontend Transport; Mon, 25 Nov 2024 12:10:32 +0000 Received: from dev-dsk-hagarhem-1b-b868d8d5.eu-west-1.amazon.com (dev-dsk-hagarhem-1b-b868d8d5.eu-west-1.amazon.com [10.253.65.58]) by email-imr-corp-prod-pdx-1box-2b-8c2c6aed.us-west-2.amazon.com (Postfix) with ESMTP id F1848A0732; Mon, 25 Nov 2024 12:10:31 +0000 (UTC) Received: by dev-dsk-hagarhem-1b-b868d8d5.eu-west-1.amazon.com (Postfix, from userid 23002382) id 8554822462; Mon, 25 Nov 2024 12:10:31 +0000 (UTC) From: Hagar Hemdan To: CC: , Puranjay Mohan , "Christoph Hellwig" , Sagi Grimberg , Anuj Gupta , Keith Busch , Hagar Hemdan Subject: [PATCH 6.6] nvme: fix metadata handling in nvme-passthrough Date: Mon, 25 Nov 2024 12:10:06 +0000 Message-ID: <20241125121009.17855-1-hagarhem@amazon.com> X-Mailer: git-send-email 2.40.1 Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain 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 [ Minor changes to make it work on 6.6 ] Signed-off-by: Hagar Hemdan --- drivers/nvme/host/ioctl.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/nvme/host/ioctl.c b/drivers/nvme/host/ioctl.c index 875dee6ecd40..19a7f0160618 100644 --- 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 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; 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 request *req, u64 ubuffer, 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)) { -- 2.40.1