lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20251201163306.GF866564@fedora>
Date: Mon, 1 Dec 2025 11:33:06 -0500
From: Stefan Hajnoczi <stefanha@...hat.com>
To: Christoph Hellwig <hch@....de>
Cc: linux-block@...r.kernel.org, Keith Busch <kbusch@...nel.org>,
	"Martin K. Petersen" <martin.petersen@...cle.com>,
	linux-kernel@...r.kernel.org,
	"James E.J. Bottomley" <James.Bottomley@...senpartnership.com>,
	Mike Christie <michael.christie@...cle.com>,
	linux-nvme@...ts.infradead.org, Jens Axboe <axboe@...nel.dk>,
	linux-scsi@...r.kernel.org, Sagi Grimberg <sagi@...mberg.me>
Subject: Re: [PATCH v2 3/4] block: add IOC_PR_READ_KEYS ioctl

On Mon, Dec 01, 2025 at 07:40:16AM +0100, Christoph Hellwig wrote:
> On Thu, Nov 27, 2025 at 10:54:23AM -0500, Stefan Hajnoczi wrote:
> > +static int blkdev_pr_read_keys(struct block_device *bdev, blk_mode_t mode,
> > +		struct pr_read_keys __user *arg)
> > +{
> > +	const struct pr_ops *ops = bdev->bd_disk->fops->pr_ops;
> > +	struct pr_keys *keys_info __free(kfree) = NULL;
> 
> Please avoid the use of the __free mess and write readable and maintainable
> code instead.

Okay.

> > +	struct pr_read_keys inout;
> 
> Inout is not a very good variable name, as it doesn't really have much
> of meaning.  

It's the ioctl argument. I will change it to read_keys in the next
revision. I'm not sure if that's any better, but it reminds us which
struct this is.

> > +	if (copy_from_user(&inout, arg, sizeof(inout)))
> > +		return -EFAULT;
> > +
> > +	/*
> > +	 * 64-bit hosts could handle more keys than 32-bit hosts, but this
> > +	 * limit is more than enough in practice.
> > +	 */
> > +	if (inout.num_keys > (U32_MAX - sizeof(*keys_info)) /
> > +	                     sizeof(keys_info->keys[0]))
> > +		return -EINVAL;
> > +
> > +	keys_info_len = struct_size(keys_info, keys, inout.num_keys);
> 
> Do the size check on the calculate len here?

Yes, that's better. Checking SIZE_MAX also gets rid of the 32-bit vs
64-bit host comment.

> > +		return ret;
> > +
> > +	/* Copy out individual keys */
> > +	keys_ptr = u64_to_user_ptr(inout.keys_ptr);
> > +	num_copy_keys = min(inout.num_keys, keys_info->num_keys);
> > +	keys_copy_len = num_copy_keys * sizeof(keys_info->keys[0]);
> 
> num_copy_keys is only used once, so maybe drop it?

Will fix.

Stefan

Download attachment "signature.asc" of type "application/pgp-signature" (485 bytes)

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ