mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Theodore Ts'o" <tytso@mit.edu>
To: "H. Peter Anvin" <hpa@linux.intel.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>,
	Denys Vlasenko <vda.linux@googlemail.com>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: random: /dev/random often returns short reads
Date: Tue, 17 Jan 2017 18:41:49 -0500	[thread overview]
Message-ID: <20170117234149.alego63cw6a7azw3@thunk.org> (raw)
In-Reply-To: <71338f5a-83e3-4316-845d-8cdea735df0f@linux.intel.com>

On Tue, Jan 17, 2017 at 02:29:30PM -0800, H. Peter Anvin wrote:
> If there is a real need to hack around this, then I would instead
> suggest modifying random_read() to block rather than return if the user
> requests below a certain value, O_NONBLOCK is not set, and the whole
> request cannot be fulfilled.  It probably needs to be a sysctl
> configurable, though, and most likely defaulting to 1, as it could just
> as easily break properly functioning applications.

Ugh.  This seems horribly complicated.  If we _really_ need to give
aid and comfort to people trying to do pointless FIPS certification
workarounds (as opposed to closing bugzilla complaints with "working
as intended"), how about this?

diff --git a/drivers/char/random.c b/drivers/char/random.c
index 7f0622426b97..d35281492e04 100644
--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -1460,7 +1460,13 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
 	int large_request = (nbytes > 256);
 
 	trace_extract_entropy_user(r->name, nbytes, ENTROPY_BITS(r), _RET_IP_);
-	xfer_secondary_pool(r, nbytes);
+	if (r->entropy_count < (nbytes << (ENTROPY_SHIFT + 3))) {
+		int hack_xfer_size = nbytes;
+
+		if (3 * r->entropy_count < r->poolinfo->poolfracbits)
+			hack_xfer_size *= 2;
+		_xfer_secondary_pool(r, hack_xfer_size);
+	}
 	nbytes = account(r, nbytes, 0, 0);
 
 	while (nbytes) {

					- Ted

  reply	other threads:[~2017-01-18  0:21 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-16 18:50 Denys Vlasenko
2017-01-16 18:52 ` Denys Vlasenko
2017-01-17  4:36 ` Theodore Ts'o
2017-01-17  8:21   ` Denys Vlasenko
2017-01-17 17:15     ` Theodore Ts'o
2017-01-17 17:34       ` Denys Vlasenko
2017-01-17 22:29         ` H. Peter Anvin
2017-01-17 23:41           ` Theodore Ts'o [this message]
2017-01-18  1:54             ` H. Peter Anvin
2017-01-18 15:44           ` Denys Vlasenko
2017-01-18 18:07             ` Theodore Ts'o
2017-01-19 21:45               ` Denys Vlasenko
2017-01-20  3:17                 ` H. Peter Anvin
2017-02-15 17:55               ` Denys Vlasenko

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=20170117234149.alego63cw6a7azw3@thunk.org \
    --to=tytso@mit.edu \
    --cc=dvlasenk@redhat.com \
    --cc=hpa@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=vda.linux@googlemail.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®