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] [thread-next>] [day] [month] [year] [list]
Message-ID: <25ec7b58-08bd-3732-2a2e-52b95cbffda0@kernel.dk>
Date:   Thu, 19 May 2022 21:26:15 -0600
From:   Jens Axboe <axboe@...nel.dk>
To:     Al Viro <viro@...iv.linux.org.uk>
Cc:     tytso@....edu, Jason@...c4.com, hch@....de,
        linux-kernel@...r.kernel.org
Subject: Re: [PATCH 1/2] random: convert to using fops->read_iter()

On 5/19/22 9:11 PM, Al Viro wrote:
> On Thu, May 19, 2022 at 05:31:36PM -0600, Jens Axboe wrote:
> 
>> @@ -418,25 +419,23 @@ static ssize_t get_random_bytes_user(void __user *ubuf, size_t len)
>>  	 * the user directly.
>>  	 */
>>  	if (len <= CHACHA_KEY_SIZE) {
>> -		ret = len - copy_to_user(ubuf, &chacha_state[4], len);
>> +		ret = copy_to_iter(&chacha_state[4], len, to);
>>  		goto out_zero_chacha;
>>  	}
>>  
>>  	for (;;) {
>> +		size_t copied;
>> +
>>  		chacha20_block(chacha_state, output);
>>  		if (unlikely(chacha_state[12] == 0))
>>  			++chacha_state[13];
>>  
>>  		block_len = min_t(size_t, len, CHACHA_BLOCK_SIZE);
>> -		left = copy_to_user(ubuf, output, block_len);
>> -		if (left) {
>> -			ret += block_len - left;
>> +		copied = copy_to_iter(output, block_len, to);
>> +		ret += copied;
>> +		if (copied != block_len)
>>  			break;
>> -		}
> 
> 		copied = copy_to_iter(output, CHACHA_BLOCK_SIZE, to);
> 		ret += copied;
> 		if (copied != CHACHA_BLOCK_SIZE) {
> 			if (!ret)
> 				ret = -EFAULT;
> 			break;
> 		}
> 	}
> 
>>  SYSCALL_DEFINE3(getrandom, char __user *, ubuf, size_t, len, unsigned int, flags)
>>  {
>> +	struct iovec iov = { .iov_base = ubuf };
>> +	struct iov_iter iter;
> 
> 	import_single_range(READ, ubuf, len, &iov, &iter)
> 
> (note, BTW, that this'll cap len)

Yep both of these are good changes.

-- 
Jens Axboe

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ