public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] random: zero buffer after reading secret entropy from userspace
@ 2022-02-09 17:44 Jason A. Donenfeld
  2022-02-09 18:56 ` Dominik Brodowski
  2022-02-21  3:59 ` Eric Biggers
  0 siblings, 2 replies; 3+ messages in thread
From: Jason A. Donenfeld @ 2022-02-09 17:44 UTC (permalink / raw)
  To: linux-kernel; +Cc: Jason A. Donenfeld, Dominik Brodowski, Jann Horn

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 <linux@dominikbrodowski.net>
Cc: Jann Horn <jannh@google.com>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
---
 drivers/char/random.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/drivers/char/random.c b/drivers/char/random.c
index 81cfbbf5f462..9c7a0297a7d4 100644
--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -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,
-- 
2.35.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-02-21  3:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-02-09 17:44 [PATCH] random: zero buffer after reading secret entropy from userspace Jason A. Donenfeld
2022-02-09 18:56 ` Dominik Brodowski
2022-02-21  3:59 ` Eric Biggers

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox