Re: [PATCH] block: add allocation size check in blkdev_pr_read_keys()

From: Stefan Hajnoczi

Date: Mon Dec 15 2025 - 09:21:29 EST


On Sun, Dec 14, 2025 at 09:33:59PM -0800, Christoph Hellwig wrote:
> On Fri, Dec 12, 2025 at 08:17:43PM +0530, Deepanshu Kartikey wrote:
> > How about limiting num_keys to 64K (1u << 16)? In practice, PR keys
> > are used for shared storage coordination and typical deployments have
> > only a handful of hosts, so this should be more than enough for any
> > realistic use case.
> >
> > With a bounded num_keys, the SIZE_MAX check becomes unnecessary, so
> > I've removed it. Also switched to kvzalloc/kvfree to handle larger
> > allocations gracefully.
> >
> > Something like below:
> >
> > +/* Limit the number of keys to prevent excessive memory allocation */
> > +#define PR_KEYS_MAX_NUM (1u << 16)
>
> Looks reasonable to me. Stefan?

Yes, that's good. Thanks for looking into this, Deepanshu.

Stefan

Attachment: signature.asc
Description: PGP signature