random: zero buffer after reading secret entropy from userspace
Jason A. Donenfeld
maintainerPATCH 1/1 random: zero buffer after reading secret entropy from userspace
This buffer may contain entropic data that shouldn't stick around longer than needed, zero it out our temporary buffer at the end of write_pool().
Cc Dominik Brodowski <[email protected]>
Cc Jann Horn <[email protected]>
Signed-off-by Jason A. Donenfeld <[email protected]>
--- drivers/char/random.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)
drivers/char/random.c +8 -3
@@ -1357,19 +1357,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,
Signature · 1 line
2.35.0
Am Wed, Feb 09, 2022 at 06:44:56PM +0100 schrieb Jason A. Donenfeld:
Quoted 7 lines
This buffer may contain entropic data that shouldn't stick around longer than needed, zero it out our temporary buffer at the end of
write_pool().Cc Dominik Brodowski <[email protected]>Cc Jann Horn <[email protected]>Signed-off-by Jason A. Donenfeld <[email protected]>
Reviewed-by Dominik Brodowski <[email protected]>
Thanks,
Dominik
Quoted 4 lines · Jason A. Donenfeld
This buffer may contain entropic data that shouldn't stick around longer than needed, zero it out our temporary buffer at the end of
write_pool().
Quoted 8 lines
Cc Dominik Brodowski <[email protected]>Cc Jann Horn <[email protected]>Signed-off-by Jason A. Donenfeld <[email protected]>Reviewed-by Dominik Brodowski <[email protected]>--- drivers/char/random.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)
Reviewed-by Eric Biggers <[email protected]>
- Eric