From nobody Wed Oct 6 07:00:06 2021 X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id C72DD12D4634; Wed, 6 Oct 2021 07:00:06 +0000 (UTC) (envelope-from git@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) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4HPQLt5ClZz3Qck; Wed, 6 Oct 2021 07:00:06 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 92E1E1B92B; Wed, 6 Oct 2021 07:00:06 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 1967064Q014291; Wed, 6 Oct 2021 07:00:06 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 196706Mn014288; Wed, 6 Oct 2021 07:00:06 GMT (envelope-from git) Date: Wed, 6 Oct 2021 07:00:06 GMT Message-Id: <202110060700.196706Mn014288@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Kyle Evans Subject: git: 40f9f2279c0f - stable/13 - kern: random: drop read_rate and associated functionality List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kevans X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 40f9f2279c0fd6f9e1829f786eea3d49e45c9f32 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=40f9f2279c0fd6f9e1829f786eea3d49e45c9f32 commit 40f9f2279c0fd6f9e1829f786eea3d49e45c9f32 Author: Kyle Evans AuthorDate: 2021-09-20 04:59:09 +0000 Commit: Kyle Evans CommitDate: 2021-10-06 06:41:18 +0000 kern: random: drop read_rate and associated functionality Refer to discussion in PR 230808 for a less incomplete discussion, but the gist of this change is that we currently collect orders of magnitude more entropy than we need. The excess comes from bytes being read out of /dev/*random. The default rate at which we collect entropy without the read_rate increase is already more than we need to recover from a compromise of an internal state. For stable/13, the read_rate_increment symbol remains as a stub to avoid breaking loadable random modules. (cherry picked from commit 6895cade9421238abf541f24fb9327ebd19e94ff) --- sys/dev/random/random_harvestq.c | 13 +++---------- sys/dev/random/randomdev.c | 2 -- 2 files changed, 3 insertions(+), 12 deletions(-) diff --git a/sys/dev/random/random_harvestq.c b/sys/dev/random/random_harvestq.c index 6838cf23fb2e..1c0ba0774687 100644 --- a/sys/dev/random/random_harvestq.c +++ b/sys/dev/random/random_harvestq.c @@ -75,8 +75,6 @@ __FBSDID("$FreeBSD$"); static void random_kthread(void); static void random_sources_feed(void); -static u_int read_rate; - /* * Random must initialize much earlier than epoch, but we can initialize the * epoch code before SMP starts. Prior to SMP, we can safely bypass @@ -231,7 +229,7 @@ random_sources_feed(void) uint32_t entropy[HARVESTSIZE]; struct epoch_tracker et; struct random_sources *rrs; - u_int i, n, local_read_rate; + u_int i, n; bool rse_warm; rse_warm = epoch_inited; @@ -240,15 +238,10 @@ random_sources_feed(void) * Step over all of live entropy sources, and feed their output * to the system-wide RNG. */ - 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); if (rse_warm) epoch_enter_preempt(rs_epoch, &et); CK_LIST_FOREACH(rrs, &source_list, rrs_entries) { - for (i = 0; i < p_random_alg_context->ra_poolcount*local_read_rate; i++) { + for (i = 0; i < p_random_alg_context->ra_poolcount; 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))); /* @@ -276,7 +269,7 @@ void read_rate_increment(u_int chunk) { - atomic_add_32(&read_rate, chunk); + /* Stubbed to maintain KBI; removed in FreeBSD 14.0. */ } /* ARGSUSED */ diff --git a/sys/dev/random/randomdev.c b/sys/dev/random/randomdev.c index 114246415aa6..4b032cd3feb9 100644 --- a/sys/dev/random/randomdev.c +++ b/sys/dev/random/randomdev.c @@ -187,7 +187,6 @@ int if (error != 0) return (error); - read_rate_increment(howmany(uio->uio_resid + 1, sizeof(uint32_t))); total_read = 0; /* Easy to deal with the trivial 0 byte case. */ @@ -286,7 +285,6 @@ void (void)randomdev_wait_until_seeded(SEEDWAIT_UNINTERRUPTIBLE); } - read_rate_increment(roundup2(len, sizeof(uint32_t))); p_random_alg_context->ra_read(random_buf, len); }