From nobody Mon Dec 1 22:35:05 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (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 0F21533769C for ; Thu, 27 Nov 2025 15:54:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764258881; cv=none; b=f4LhzHbY9IDp/32VpxrnFbp6VV9gb+5DRVkF3yFVbiF5XR0JlxXmWjm/M2pNRRQgUeXk9unIEXu3iTGdyEYAZR590HYJeBLSOnt8Yn1cD7Qyjvj/C5IFWZwLfu2gb6/XFdYfEZRZ0uvLwFmnLvVJ/I5NaFsBj5BIJKLh/d4H8ag= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764258881; c=relaxed/simple; bh=CG0WCXs5GtINbmf9Z6msAYJS70/y7x1p3+LE85tX23I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=deGIlTcS/0jHs+tsqJI+yxp3nA4L+8SVOzrDz83VSxNWLR0FHYPTBVMU/EuxCOCK9ZvsonBc7ser6+nkeNd9txGB/cIq1ECjvApriQ8i9YXrbc9ZkAHE18490vwAvRUJAHFGBBvZhE2aeAJyL1SWR9HH6y/z5GoR9ma7b9j12is= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=hTL0zVHK; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="hTL0zVHK" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1764258878; 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=4yiEqdjZP2pjR5NE43rCMghlmUF6oy2t/sXcmabl5AU=; b=hTL0zVHKDS9Q9IKWaciQ2Mh9UwWh2iVRE2gSkQFARClmH1bRapvR2NuAtz7K+HYdBRBnbk nug9iZ1L/2z5v4MMbkHJD5yrpLRY/tavkRX4qz8vozDK0RPWgSilPWO5uCGkBIK0G+z/sa c6W7GAJWU+3TBjZDvyXtVrj30+jgICQ= Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-73-TZXPpSsGNVuPgZswTFV2mw-1; Thu, 27 Nov 2025 10:54:35 -0500 X-MC-Unique: TZXPpSsGNVuPgZswTFV2mw-1 X-Mimecast-MFC-AGG-ID: TZXPpSsGNVuPgZswTFV2mw_1764258873 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (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-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 2D98D180034D; Thu, 27 Nov 2025 15:54:33 +0000 (UTC) Received: from localhost (unknown [10.2.16.53]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 1D126180047F; Thu, 27 Nov 2025 15:54:31 +0000 (UTC) From: Stefan Hajnoczi To: linux-block@vger.kernel.org Cc: Keith Busch , "Martin K. Petersen" , linux-kernel@vger.kernel.org, "James E.J. Bottomley" , Christoph Hellwig , Mike Christie , linux-nvme@lists.infradead.org, Jens Axboe , linux-scsi@vger.kernel.org, Sagi Grimberg , Stefan Hajnoczi Subject: [PATCH v2 2/4] nvme: reject invalid pr_read_keys() num_keys values Date: Thu, 27 Nov 2025 10:54:22 -0500 Message-ID: <20251127155424.617569-3-stefanha@redhat.com> In-Reply-To: <20251127155424.617569-1-stefanha@redhat.com> References: <20251127155424.617569-1-stefanha@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Hannes Reinecke --- drivers/nvme/host/pr.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/nvme/host/pr.c b/drivers/nvme/host/pr.c index ca6a74607b139..156a2ae1fac2e 100644 --- a/drivers/nvme/host/pr.c +++ b/drivers/nvme/host/pr.c @@ -233,6 +233,10 @@ static int nvme_pr_read_keys(struct block_device *bdev, int ret, i; bool eds; =20 + /* Check that keys fit into u32 rse_len */ + if (num_keys > (U32_MAX - sizeof(*rse)) / 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. --=20 2.52.0