aboutsummaryrefslogtreecommitdiff
path: root/drivers/char
diff options
context:
space:
mode:
authorJason A. Donenfeld2022-02-09 18:42:13 +0100
committerJason A. Donenfeld2022-02-21 21:14:00 +0100
commit7b5164fb1279bf0251371848e40bae646b59b3a8 (patch)
treeb733a6458feeaa478acc849f5d238c397accaaa5 /drivers/char
parent434537ae54ad37e93555de21b6ac8133d6d773a9 (diff)
random: zero buffer after reading entropy from userspace
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>
Diffstat (limited to 'drivers/char')
-rw-r--r--drivers/char/random.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/drivers/char/random.c b/drivers/char/random.c
index 896ec54f8f5c..8ae7d0b30280 100644
--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -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,