All of lore.kernel.org
 help / color / mirror / Atom feed
From: Konstantin Khlebnikov <k.khlebnikov@samsung.com>
To: Tejun Heo <tj@kernel.org>, "Theodore Ts'o" <tytso@mit.edu>,
	linux-kernel@vger.kernel.org
Cc: Andrey Ryabinin <a.ryabinin@samsung.com>,
	Dmitry Vyukov <dvyukov@google.com>
Subject: [PATCH] random: wait for system_wq before pushing entropy into output pools
Date: Thu, 20 Nov 2014 16:54:21 +0400	[thread overview]
Message-ID: <20141120135421.3819.24114.stgit@buzz> (raw)

First prototype of tool which injects random delays in random places
(implemented on top of kernel address sanitizer by Andrey Ryabinin)
have caught race right at the first try.

credit_entropy_bits() schedules work for pushing entropy from one pool
into another too early, when system_wq isn't yet created. It's called from
add_interrupt_randomness, so this path starts working right after enabling
interrupts in start_kernel, but system workqueues are initialized much
later in early_initcall(init_workqueues). It's impossible to create them
earlier because threads have to be forked from kthreadd.

This patch skips pushing if system_wq isn't here yet. Delaying this till
SYSTEM_RUNNING state might lead to significant lost of precious entropy.

Signed-off-by: Konstantin Khlebnikov <k.khlebnikov@samsung.com>
Reported-and-tested-by: Andrey Ryabinin <a.ryabinin@samsung.com>
---
 drivers/char/random.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/char/random.c b/drivers/char/random.c
index 04645c0..d4a684f 100644
--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -683,7 +683,7 @@ retry:
 		 * full.
 		 */
 		if (entropy_bits > random_write_wakeup_bits &&
-		    r->initialized &&
+		    system_wq && r->initialized &&
 		    r->entropy_total >= 2*random_read_wakeup_bits) {
 			static struct entropy_store *last = &blocking_pool;
 			struct entropy_store *other = &blocking_pool;
@@ -695,7 +695,7 @@ retry:
 				last = other;
 			if (last->entropy_count <=
 			    3 * last->poolinfo->poolfracbits / 4) {
-				schedule_work(&last->push_work);
+				queue_work(system_wq, &last->push_work);
 				r->entropy_total = 0;
 			}
 		}


             reply	other threads:[~2014-11-20 13:54 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-20 12:54 Konstantin Khlebnikov [this message]
2014-11-20 13:58 ` [PATCH] random: wait for system_wq before pushing entropy into output pools Konstantin Khlebnikov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20141120135421.3819.24114.stgit@buzz \
    --to=k.khlebnikov@samsung.com \
    --cc=a.ryabinin@samsung.com \
    --cc=dvyukov@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tj@kernel.org \
    --cc=tytso@mit.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.