From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752544AbdARAVQ (ORCPT ); Tue, 17 Jan 2017 19:21:16 -0500 Received: from imap.thunk.org ([74.207.234.97]:55384 "EHLO imap.thunk.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751979AbdARAVP (ORCPT ); Tue, 17 Jan 2017 19:21:15 -0500 Date: Tue, 17 Jan 2017 18:41:49 -0500 From: "Theodore Ts'o" To: "H. Peter Anvin" Cc: Denys Vlasenko , Denys Vlasenko , Linux Kernel Mailing List Subject: Re: random: /dev/random often returns short reads Message-ID: <20170117234149.alego63cw6a7azw3@thunk.org> Mail-Followup-To: Theodore Ts'o , "H. Peter Anvin" , Denys Vlasenko , Denys Vlasenko , Linux Kernel Mailing List References: <20170117043640.4ykofgcwfysvgyue@thunk.org> <20170117171539.dadciiz2kfjtqrfk@thunk.org> <09f2ce2d-3c84-bb12-560c-3208691d2c55@redhat.com> <71338f5a-83e3-4316-845d-8cdea735df0f@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <71338f5a-83e3-4316-845d-8cdea735df0f@linux.intel.com> User-Agent: NeoMutt/20161126 (1.7.1) X-SA-Exim-Connect-IP: X-SA-Exim-Mail-From: tytso@thunk.org X-SA-Exim-Scanned: No (on imap.thunk.org); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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