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 258EAD11185 for ; Wed, 26 Nov 2025 16:38:09 +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=fLbOYH1ZNvDH2OUPDGLBHO7mvrdHvaUK8HEzMWWFf5s=; b=a6KwoCUbuxPKyrDPdNCkGacshS j8djjz18Mvck/lGylh/5rfPalmuSKPu1sb6YmFwVzhX/rkgt0T3bvDZWRpwg5WGiRRK+FVshJMN0v ZBZXB+Yz2BxwMqZVcbGlJc2hjy81Q+Etf4DN9zKf2CfyxFZVMKhK4ItKG/68O80mUPr/GMWlOvb89 hb4hiYBivZ9Cz3TbvFR3JhUGhqgZ9mUd8JmRJrb8OM3pnJ0Jv6BjnpwoNalPPaijOn1RUDLSQ2OfI 9H03R9qczstaX3vfDQ12i66xVbTelzmGlqmbXf0VexmjRBR72NwQFzJZ2+7kTG2EN6bXVEfMDyfpE zqZObVzA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1vOIWt-0000000FJnS-0yg0; Wed, 26 Nov 2025 16:38:07 +0000 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1vOIWp-0000000FJl8-3A7l for linux-nvme@lists.infradead.org; Wed, 26 Nov 2025 16:38:05 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1764175082; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=fLbOYH1ZNvDH2OUPDGLBHO7mvrdHvaUK8HEzMWWFf5s=; b=fqW+xAAZPYencl8FeRuxkZ9ufbOf+HPnhzXqzXmhKgjx4EIoPW4TmOWvjhHwc+OxEhk1x3 dS050331RGYAZpzFwcDxMvqDvaKXU9QY3L3W7GfzSvM217aBqKkn3wyhAdpfA2/ttfLkQp gF71nRPXkSd3YwXH5UodsdzoyNtpVJQ= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-111-V2gLIDVUMA231heVvoz5qg-1; Wed, 26 Nov 2025 11:36:11 -0500 X-MC-Unique: V2gLIDVUMA231heVvoz5qg-1 X-Mimecast-MFC-AGG-ID: V2gLIDVUMA231heVvoz5qg_1764174969 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 9057B1954B06; Wed, 26 Nov 2025 16:36:09 +0000 (UTC) Received: from localhost (unknown [10.2.16.50]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 80B941800878; Wed, 26 Nov 2025 16:36:08 +0000 (UTC) From: Stefan Hajnoczi To: linux-block@vger.kernel.org Cc: "Martin K. Petersen" , linux-kernel@vger.kernel.org, "James E.J. Bottomley" , Mike Christie , Jens Axboe , linux-nvme@lists.infradead.org, Keith Busch , Sagi Grimberg , linux-scsi@vger.kernel.org, Christoph Hellwig , Stefan Hajnoczi Subject: [PATCH 2/4] nvme: reject invalid pr_read_keys() num_keys values Date: Wed, 26 Nov 2025 11:35:58 -0500 Message-ID: <20251126163600.583036-3-stefanha@redhat.com> In-Reply-To: <20251126163600.583036-1-stefanha@redhat.com> References: <20251126163600.583036-1-stefanha@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20251126_083803_907556_E529B90E X-CRM114-Status: GOOD ( 12.81 ) 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 The pr_read_keys() interface has a u32 num_keys parameter. The NVMe Reservation Report command has a u32 maximum length. Reject num_keys values that are too large to fit. This will become important when pr_read_keys() is exposed to untrusted userspace via an ioctl. Signed-off-by: Stefan Hajnoczi --- drivers/nvme/host/pr.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/nvme/host/pr.c b/drivers/nvme/host/pr.c index ca6a74607b139..476a0518a11ca 100644 --- a/drivers/nvme/host/pr.c +++ b/drivers/nvme/host/pr.c @@ -233,6 +233,11 @@ static int nvme_pr_read_keys(struct block_device *bdev, int ret, i; bool eds; + /* Check that keys fit into u32 rse_len */ + if (num_keys > -(u32)offsetof(typeof(*rse), regctl_eds) / + sizeof(rse->regctl_eds[0])) + return -EINVAL; + /* * Assume we are using 128-bit host IDs and allocate a buffer large * enough to get enough keys to fill the return keys buffer. -- 2.52.0