From owner-svn-src-head@freebsd.org Fri Aug 24 14:53:48 2018 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 18F22108C066; Fri, 24 Aug 2018 14:53:48 +0000 (UTC) (envelope-from markm@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 9440E8933B; Fri, 24 Aug 2018 14:53:47 +0000 (UTC) (envelope-from markm@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 57BB7128A4; Fri, 24 Aug 2018 14:53:47 +0000 (UTC) (envelope-from markm@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w7OErleE010282; Fri, 24 Aug 2018 14:53:47 GMT (envelope-from markm@FreeBSD.org) Received: (from markm@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w7OErlYl010281; Fri, 24 Aug 2018 14:53:47 GMT (envelope-from markm@FreeBSD.org) Message-Id: <201808241453.w7OErlYl010281@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: markm set sender to markm@FreeBSD.org using -f From: Mark Murray Date: Fri, 24 Aug 2018 14:53:47 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r338293 - head/sys/dev/random X-SVN-Group: head X-SVN-Commit-Author: markm X-SVN-Commit-Paths: head/sys/dev/random X-SVN-Commit-Revision: 338293 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 24 Aug 2018 14:53:48 -0000 Author: markm Date: Fri Aug 24 14:53:46 2018 New Revision: 338293 URL: https://svnweb.freebsd.org/changeset/base/338293 Log: Limit the amount of "fast" entropy. We don't need nearly as much for security, and the excess just slows things down badly. PR: 230808 Submitted by: rwmaillists@googlemail.com, but tweeked by me Reported by: Danilo Egea Gondolfo Reviewed by: cem,delphij Approved by: re(rgrimes) Approved by: so(delphij) MFC after: 1 Month Differential Revision: https://reviews.freebsd.org/D16873 Modified: head/sys/dev/random/random_harvestq.c Modified: head/sys/dev/random/random_harvestq.c ============================================================================== --- head/sys/dev/random/random_harvestq.c Fri Aug 24 14:53:42 2018 (r338292) +++ head/sys/dev/random/random_harvestq.c Fri Aug 24 14:53:46 2018 (r338293) @@ -57,6 +57,10 @@ __FBSDID("$FreeBSD$"); #include #include +#include +#include + +#include #include #include @@ -213,8 +217,12 @@ random_sources_feed(void) /* It's an indenting error. Yeah, Yeah. */ #endif local_read_rate = atomic_readandclear_32(&read_rate); + /* Perform at least one read per round */ + local_read_rate = MAX(local_read_rate, 1); + /* But not exceeding RANDOM_KEYSIZE_WORDS */ + local_read_rate = MIN(local_read_rate, RANDOM_KEYSIZE_WORDS); LIST_FOREACH(rrs, &source_list, rrs_entries) { - for (i = 0; i < p_random_alg_context->ra_poolcount*(local_read_rate + 1); i++) { + for (i = 0; i < p_random_alg_context->ra_poolcount*local_read_rate; i++) { n = rrs->rrs_source->rs_read(entropy, sizeof(entropy)); KASSERT((n <= sizeof(entropy)), ("%s: rs_read returned too much data (%u > %zu)", __func__, n, sizeof(entropy))); /* It would appear that in some circumstances (e.g. virtualisation),