Skip to content

Commit

Permalink
random: zero buffer after reading entropy from userspace
Browse files Browse the repository at this point in the history
commit 7b5164f upstream.

This buffer may contain entropic data that shouldn't stick around longer
than needed, so zero out the temporary buffer at the end of write_pool().

Reviewed-by: Dominik Brodowski <linux@dominikbrodowski.net>
Reviewed-by: Jann Horn <jannh@google.com>
Reviewed-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
zx2c4 authored and gregkh committed May 30, 2022
1 parent 3272ad7 commit 06460c4
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions drivers/char/random.c
Original file line number Diff line number Diff line change
Expand Up @@ -1336,19 +1336,24 @@ static __poll_t random_poll(struct file *file, poll_table *wait)
static int write_pool(const char __user *ubuf, size_t count)
{
size_t len;
int ret = 0;
u8 block[BLAKE2S_BLOCK_SIZE];

while (count) {
len = min(count, sizeof(block));
if (copy_from_user(block, ubuf, len))
return -EFAULT;
if (copy_from_user(block, ubuf, len)) {
ret = -EFAULT;
goto out;
}
count -= len;
ubuf += len;
mix_pool_bytes(block, len);
cond_resched();
}

return 0;
out:
memzero_explicit(block, sizeof(block));
return ret;
}

static ssize_t random_write(struct file *file, const char __user *buffer,
Expand Down

0 comments on commit 06460c4

Please sign in to comment.