From nobody Mon Dec 1 23:33:18 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.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 3281B285C8C for ; Mon, 1 Dec 2025 21:43:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764625424; cv=none; b=DkKo7r1+QufSE2Ly+gwcyhlm5iWQ/378zck64E+kur2glW6Nc42yZ21CeEaPbYsW5N/3dFyR0npGV8BPyFP8xwFIXX3Nz3Aoc7HfAB6yHJfe0gftl3JR4uZnKDSz8y1yTP+2efmJc6vdbaJRzmQMqLuY1uZij4tXg8DV2yqKLIs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764625424; c=relaxed/simple; bh=49L/LnDII58bUSi0yl2+j9Hx3Cuk6PLob2aDru1JQdY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KmIyzzjE45Okb87YivUBlHACtgoYp/GOu7Pk/KfTdWOy7rbO+QvVZvnvryoD6I/srTovSeil47UuFXZNePw+ftT9/cY/3Gv1SqzCdf6aRSntOT1hmIkj/rpJgBlidyQ4PGVYb1faDhWCB4CngrAQAmVXu8tF2O/eBFAkHo1aVpA= 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=eAWLZzBe; arc=none smtp.client-ip=170.10.133.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="eAWLZzBe" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1764625422; 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=jMFwoOksHHE5cqY2VlDWWpug5apQFnrEoUUMM1BHdZM=; b=eAWLZzBeBfjP49ZqkYITU7FeNncOTCh17LNpsfWIcBaSkB8D0ElWkSRqxgFBGeHxHZ0+HW fYTXBfRTU8DyvuAqtB6fiu7wFRZ5eJsKSlltw8y8uStqVxfd9zZYGbPHdJIQGuOGk9mxok XHcD3Pue4U379RpfvLAld9Ylb/pRRxA= 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-528-l0f1X0LbMJCJ0PRFNBW5jQ-1; Mon, 01 Dec 2025 16:43:39 -0500 X-MC-Unique: l0f1X0LbMJCJ0PRFNBW5jQ-1 X-Mimecast-MFC-AGG-ID: l0f1X0LbMJCJ0PRFNBW5jQ_1764625417 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (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 25C4F1800343; Mon, 1 Dec 2025 21:43:37 +0000 (UTC) Received: from localhost (unknown [10.2.16.172]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 7E79A19560A7; Mon, 1 Dec 2025 21:43:36 +0000 (UTC) From: Stefan Hajnoczi To: linux-block@vger.kernel.org Cc: Christoph Hellwig , linux-kernel@vger.kernel.org, linux-scsi@vger.kernel.org, "James E.J. Bottomley" , "Martin K. Petersen" , Keith Busch , Jens Axboe , Sagi Grimberg , Mike Christie , Krzysztof Kozlowski , linux-nvme@lists.infradead.org, Stefan Hajnoczi Subject: [PATCH v3 2/4] nvme: reject invalid pr_read_keys() num_keys values Date: Mon, 1 Dec 2025 16:43:27 -0500 Message-ID: <20251201214329.933945-3-stefanha@redhat.com> In-Reply-To: <20251201214329.933945-1-stefanha@redhat.com> References: <20251201214329.933945-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.0 on 10.30.177.12 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 --- drivers/nvme/host/pr.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/nvme/host/pr.c b/drivers/nvme/host/pr.c index ca6a74607b139..ad2ecc2f49a97 100644 --- a/drivers/nvme/host/pr.c +++ b/drivers/nvme/host/pr.c @@ -228,7 +228,8 @@ static int nvme_pr_resv_report(struct block_device *bde= v, void *data, static int nvme_pr_read_keys(struct block_device *bdev, struct pr_keys *keys_info) { - u32 rse_len, num_keys =3D keys_info->num_keys; + size_t rse_len; + u32 num_keys =3D keys_info->num_keys; struct nvme_reservation_status_ext *rse; int ret, i; bool eds; @@ -238,6 +239,9 @@ static int nvme_pr_read_keys(struct block_device *bdev, * enough to get enough keys to fill the return keys buffer. */ rse_len =3D struct_size(rse, regctl_eds, num_keys); + if (rse_len > U32_MAX) + return -EINVAL; + rse =3D kzalloc(rse_len, GFP_KERNEL); if (!rse) return -ENOMEM; --=20 2.52.0