[PATCH v2 1/4] scsi: sd: reject invalid pr_read_keys() num_keys values

Stefan Hajnoczi stefanha at redhat.com
Mon Dec 1 08:23:17 PST 2025


On Mon, Dec 01, 2025 at 07:34:13AM +0100, Christoph Hellwig wrote:
> On Thu, Nov 27, 2025 at 10:54:21AM -0500, Stefan Hajnoczi wrote:
> > +	/*
> > +	 * Each reservation key takes 8 bytes and there is an 8-byte header
> > +	 * before the reservation key list. The total size must fit into the
> > +	 * 16-bit ALLOCATION LENGTH field.
> > +	 */
> > +	if (num_keys > (USHRT_MAX / 8) - 1)
> > +		return -EINVAL;
> > +
> > +	data_len = num_keys * 8 + 8;
> 
> Having the same arithmerics express here in two different ways is a bit
> odd.
> 
> I'd expected this to be something like:
> 
> 	if (check_mul_overflow(num_keys, 8, &data_len) || data_len > USHRT_MAX)
> 		return -EINVAL;

Will fix, thanks.

Stefan
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-nvme/attachments/20251201/643c474e/attachment.sig>


More information about the Linux-nvme mailing list