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 via email to