From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from verein.lst.de (verein.lst.de [213.95.11.211]) (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 D997F3ACA7B for ; Tue, 24 Mar 2026 06:53:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.95.11.211 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774335203; cv=none; b=Ue6ii2S7SBYWKipBKFCN73XNJZmjqdlBjxPcuKrAmCwnxNZIqyGSk8dUZRja0QxFWreCSYwe2gqmNHvQoYqkwDIO/iZauFcKuX0hCyl8SwLJreY0BttPpxVS3lV7hdNwS1XRj4zLbzyUisNtJtUmI816oGZ4zss8Z+AdayiwJYM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774335203; c=relaxed/simple; bh=/RwagedobnHXi7HKSELgEwQ9r+r3SIkmnqsu3exhyU8=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=P122StLAkdgrtWoxJwC+fZSKW2PuZ8OpOE2FJde9+y9c0Jddr9K1auFTM0TxOfSGIeEPanaVQ8DGa+2y3S5CE3nWYh5Wm98BYvBO/0dqZEImEAQCsuJq0UWlmtggP5FNvDN/PqtXn7BNlzJs/zlIVJzgDKFICWT7ENjvhAtEU98= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=lst.de; spf=pass smtp.mailfrom=lst.de; arc=none smtp.client-ip=213.95.11.211 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=lst.de Received: by verein.lst.de (Postfix, from userid 2407) id D769C68AFE; Tue, 24 Mar 2026 07:53:08 +0100 (CET) Date: Tue, 24 Mar 2026 07:53:08 +0100 From: Christoph Hellwig To: Keith Busch Cc: Dan Carpenter , Sungwoo Kim , Jens Axboe , Christoph Hellwig , Sagi Grimberg , linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org, Harshit Mogalapalli Subject: Re: [PATCH] nvme: remove bogus check in nvme_pr_read_keys() Message-ID: <20260324065308.GA1578@lst.de> References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.17 (2007-11-01) On Mon, Mar 23, 2026 at 11:53:23AM -0600, Keith Busch wrote: > On Sat, Mar 21, 2026 at 01:26:25PM +0300, Dan Carpenter wrote: > > This check for if (rse_len > U32_MAX) is confusing because if > > rse_len is > INT_MAX, that will trigger a WARN() in kvzalloc(). > > Fortunately, the caller blkdev_pr_read_keys(), puts a limit on num_keys. > > The number of keys can't be more than PR_KEYS_MAX (65536) and the > > condition is impossible. > > There's actually two callers: blkdev_pr_read_keys() ensures the number of > keys is smaller than 65536 and iblock_pr_read_keys() is a fixed size at > 16. But begs the question, what guarantee does nvme_pr_read_keys() have > that all the callers validated the number of keys such that it can > bravely skip checking it? I think nvme should validate that it's a > reasonable value before calling kvalloc so we return an apporpriate > EINVAL instead of ENOMEM. The existing UINT_MAX check is certainly far > too high, but I think something like a 4MB payload would be a totally > reasonable upper limit for nvme on this function. Agreed.