LKML Archive on
 help / Atom feed
* [PATCH] random: Do not ignore early device randomness
@ 2017-06-26 23:30 Kees Cook
  0 siblings, 0 replies; 1+ messages in thread
From: Kees Cook @ 2017-06-26 23:30 UTC (permalink / raw)
  To: Theodore Ts'o
  Cc: Arnd Bergmann, Greg Kroah-Hartman, Ingo Molnar, Andrew Morton,
	Jessica Yu, Steven Rostedt (VMware),
	Viresh Kumar, Tejun Heo, Prarit Bhargava, Lokesh Vutla,
	Nicholas Piggin, AKASHI Takahiro, kernel-hardening, linux-kernel

The add_device_randomness() function would ignore incoming bytes if the
crng wasn't ready. This additionally makes sure to make an early enough
call to add_latent_entropy() to influence the initial stack canary, which
is especially important on non-x86 systems where it stays the same through
the life of the boot.

Signed-off-by: Kees Cook <>
 drivers/char/random.c | 5 +++++
 init/main.c           | 1 +
 2 files changed, 6 insertions(+)

diff --git a/drivers/char/random.c b/drivers/char/random.c
index 01a260f67437..23cab7a8c1c1 100644
--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -987,6 +987,11 @@ void add_device_randomness(const void *buf, unsigned int size)
 	unsigned long time = random_get_entropy() ^ jiffies;
 	unsigned long flags;
+	if (!crng_ready()) {
+		crng_fast_load(buf, size);
+		return;
+	}
 	trace_add_device_randomness(size, _RET_IP_);
 	spin_lock_irqsave(&input_pool.lock, flags);
 	_mix_pool_bytes(&input_pool, buf, size);
diff --git a/init/main.c b/init/main.c
index f866510472d7..6b2c3ab7d76b 100644
--- a/init/main.c
+++ b/init/main.c
@@ -497,6 +497,7 @@ asmlinkage __visible void __init start_kernel(void)
 	 * Set up the initial canary ASAP:
+	add_latent_entropy();

Kees Cook
Pixel Security

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

only message in thread, back to index

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-06-26 23:30 [PATCH] random: Do not ignore early device randomness Kees Cook

LKML Archive on

Archives are clonable:
	git clone --mirror lkml/git/0.git
	git clone --mirror lkml/git/1.git
	git clone --mirror lkml/git/2.git
	git clone --mirror lkml/git/3.git
	git clone --mirror lkml/git/4.git
	git clone --mirror lkml/git/5.git
	git clone --mirror lkml/git/6.git
	git clone --mirror lkml/git/7.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 lkml lkml/ \
	public-inbox-index lkml

Newsgroup available over NNTP:

AGPL code for this site: git clone public-inbox