提交 b860d930 编写于 作者: J Jason A. Donenfeld 提交者: Zheng Zengkai

random: zero buffer after reading entropy from userspace

stable inclusion
from stable-v5.10.119
commit bb63851c25576e83cabe2d26c6548f3d5085d0e7
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/I5L6BB

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=bb63851c25576e83cabe2d26c6548f3d5085d0e7

--------------------------------

commit 7b5164fb 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: NDominik Brodowski <linux@dominikbrodowski.net>
Reviewed-by: NJann Horn <jannh@google.com>
Reviewed-by: NEric Biggers <ebiggers@google.com>
Signed-off-by: NJason A. Donenfeld <Jason@zx2c4.com>
Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
Acked-by: NXie XiuQi <xiexiuqi@huawei.com>
上级 b3357cdf
...@@ -1336,19 +1336,24 @@ static __poll_t random_poll(struct file *file, poll_table *wait) ...@@ -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) static int write_pool(const char __user *ubuf, size_t count)
{ {
size_t len; size_t len;
int ret = 0;
u8 block[BLAKE2S_BLOCK_SIZE]; u8 block[BLAKE2S_BLOCK_SIZE];
while (count) { while (count) {
len = min(count, sizeof(block)); len = min(count, sizeof(block));
if (copy_from_user(block, ubuf, len)) if (copy_from_user(block, ubuf, len)) {
return -EFAULT; ret = -EFAULT;
goto out;
}
count -= len; count -= len;
ubuf += len; ubuf += len;
mix_pool_bytes(block, len); mix_pool_bytes(block, len);
cond_resched(); cond_resched();
} }
return 0; out:
memzero_explicit(block, sizeof(block));
return ret;
} }
static ssize_t random_write(struct file *file, const char __user *buffer, static ssize_t random_write(struct file *file, const char __user *buffer,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册