From owner-svn-src-all@freebsd.org Sat Apr 6 09:00:07 2019 Return-Path: Delivered-To: svn-src-all@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 80514157B436; Sat, 6 Apr 2019 09:00:07 +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.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 27F56703F8; Sat, 6 Apr 2019 09:00:07 +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 DDA67224D0; Sat, 6 Apr 2019 09:00:06 +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 x36906UW022394; Sat, 6 Apr 2019 09:00:06 GMT (envelope-from markm@FreeBSD.org) Received: (from markm@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x36906LW022393; Sat, 6 Apr 2019 09:00:06 GMT (envelope-from markm@FreeBSD.org) Message-Id: <201904060900.x36906LW022393@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: markm set sender to markm@FreeBSD.org using -f From: Mark Murray Date: Sat, 6 Apr 2019 09:00:06 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r345981 - stable/11/sys/dev/random X-SVN-Group: stable-11 X-SVN-Commit-Author: markm X-SVN-Commit-Paths: stable/11/sys/dev/random X-SVN-Commit-Revision: 345981 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 27F56703F8 X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.94 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.998,0]; NEURAL_HAM_SHORT(-0.94)[-0.944,0]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US] X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 06 Apr 2019 09:00:07 -0000 Author: markm Date: Sat Apr 6 09:00:06 2019 New Revision: 345981 URL: https://svnweb.freebsd.org/changeset/base/345981 Log: Backport fixes from FreeBSD-12 to help the random(4) device thread not overwhelm the OS: a) Use the correct symbolic constant when calculating 10'ths of a second. This means that expensive reseeds happen at ony 1/10 Hz, not some kHz. b) Rate limit internal high-rate harveting efforts. This stops the harvesting thread from total overkilling the high-grade entropy- gathering work, while still being very conservatively safe. PR: 230808 Reported by: danilo,eugen Tested by: eugen Approved by: so (blanket permission granted as I am the authour of this code) Relnotes: Yes Modified: stable/11/sys/dev/random/fortuna.c stable/11/sys/dev/random/random_harvestq.c Modified: stable/11/sys/dev/random/fortuna.c ============================================================================== --- stable/11/sys/dev/random/fortuna.c Sat Apr 6 06:02:42 2019 (r345980) +++ stable/11/sys/dev/random/fortuna.c Sat Apr 6 09:00:06 2019 (r345981) @@ -358,7 +358,7 @@ random_fortuna_pre_read(void) if (fortuna_state.fs_pool[0].fsp_length >= fortuna_state.fs_minpoolsize #ifdef _KERNEL /* FS&K - Use 'getsbinuptime()' to prevent reseed-spamming. */ - && (now - fortuna_state.fs_lasttime > hz/10) + && (now - fortuna_state.fs_lasttime > SBT_1S/10) #endif ) { #ifdef _KERNEL Modified: stable/11/sys/dev/random/random_harvestq.c ============================================================================== --- stable/11/sys/dev/random/random_harvestq.c Sat Apr 6 06:02:42 2019 (r345980) +++ stable/11/sys/dev/random/random_harvestq.c Sat Apr 6 09:00:06 2019 (r345981) @@ -55,6 +55,10 @@ __FBSDID("$FreeBSD$"); #include #include +#include +#include + +#include #include #include @@ -209,8 +213,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),