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

random: do not xor RDRAND when writing into /dev/random

stable inclusion
from stable-v5.10.119
commit 7a5b9ca583f9f00ab0f0c713379de40a66dc353a
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=7a5b9ca583f9f00ab0f0c713379de40a66dc353a

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

commit 91c2afca upstream.

Continuing the reasoning of "random: ensure early RDSEED goes through
mixer on init", we don't want RDRAND interacting with anything without
going through the mixer function, as a backdoored CPU could presumably
cancel out data during an xor, which it'd have a harder time doing when
being forced through a cryptographic hash function. There's actually no
need at all to be calling RDRAND in write_pool(), because before we
extract from the pool, we always do so with 32 bytes of RDSEED hashed in
at that stage. Xoring at this stage is needless and introduces a minor
liability.

Cc: Theodore Ts'o <tytso@mit.edu>
Reviewed-by: NDominik Brodowski <linux@dominikbrodowski.net>
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>
上级 abf9ff60
...@@ -1305,25 +1305,15 @@ static __poll_t random_poll(struct file *file, poll_table *wait) ...@@ -1305,25 +1305,15 @@ static __poll_t random_poll(struct file *file, poll_table *wait)
static int write_pool(const char __user *buffer, size_t count) static int write_pool(const char __user *buffer, size_t count)
{ {
size_t bytes; size_t bytes;
u32 t, buf[16]; u8 buf[BLAKE2S_BLOCK_SIZE];
const char __user *p = buffer; const char __user *p = buffer;
while (count > 0) { while (count > 0) {
int b, i = 0;
bytes = min(count, sizeof(buf)); bytes = min(count, sizeof(buf));
if (copy_from_user(&buf, p, bytes)) if (copy_from_user(buf, p, bytes))
return -EFAULT; return -EFAULT;
for (b = bytes; b > 0; b -= sizeof(u32), i++) {
if (!arch_get_random_int(&t))
break;
buf[i] ^= t;
}
count -= bytes; count -= bytes;
p += bytes; p += bytes;
mix_pool_bytes(buf, bytes); mix_pool_bytes(buf, bytes);
cond_resched(); cond_resched();
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册