From nobody Mon Sep 8 15:26:34 2025 X-Original-To: dev-commits-src-main@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 4cL9lv099dz66kb7; Mon, 08 Sep 2025 15:26:35 +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 "R12" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4cL9lt5fqxz3NW6; Mon, 08 Sep 2025 15:26:34 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1757345194; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=x28UgVJM9/FMgRsGVZl4cTQazP25uxSmmGD3DO014Vk=; b=CqVTQhghgA1DJQ1BWVj9G4VBLwFHz67Am2xTGD+JywPE83kHSezj5J7LfyNDuLldHxW8gZ 9Bi9Alnzkm3Sjm7cR0TJ/BQCWYjoPDxwbhgartYen+d/TC3BVAGYm+pg95aOaqs2tBzLtb emBOOC2xbR8Kla1R+6gxxYFF8qkKnglA4cb+JwlifzseIptfED73xPXPgAysrb8IO5uXYA pHIK/+x8LxqVaPVhO97+UbHhKcow/pZwfbJVIzfFTri6TWtD+j94ejQjjm76RR3DLXBX18 wOnHRPoEiPBCItdTgFqi2EZ55DwVv2ZxKjpi1t/BceIZj8u2fc8rtlRSWWE6AQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1757345194; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=x28UgVJM9/FMgRsGVZl4cTQazP25uxSmmGD3DO014Vk=; b=HM+6TqFSgHlcSu/JF2u+YC+SDtQeoiuiv0FcsWH1sWCq/mzKQkeIsXBr5syL3HOOpZbygM PpOzklDarpdDGLrCxUiLosJ1IY1q5HcaDJxLeGiR5w5lEgNBHydGK77DAJUkvLakxItGDW kWAHkkzfZR0ykPvp3nuRDCpXNADHL0mY7Vd8EzNmJm713t+E+Yw2wSKe4uWrHMpllzQp76 3pHGqUaoku2sE1zcnmZQ1ggtkgxdIVI2WG7PN1OYb8GiIp9kkl1z6rLsIbp5jNLi5KXZ73 9edM8A97nKuzvHYyz76TV+uT3A+wUJfOiTLHKO1APekXP94urKVTOyQXmdwibw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1757345194; a=rsa-sha256; cv=none; b=fiTiJuE4yXMAwzHrKhUjIGnd20KXybbYCG1eqLZ8yRHtMJs9ZLS+LTJk4ia6ufcC5MStwk Pzpkyxnq9DE+oEbaMhSMTLB6X8T2rLmeDe1lfQzwycC2TN5CZjiymLDGe6oHu1DJOAvVGn 7XKExnRyPEUUxjOMa4DuOtZ79yEk9l/OMpgb0PSw49SfGuRotQ0Ak7sZ8mnl2kv6EDH/Q/ zwlwUPey4byXVKB4MBygIZEiVIioRP77ugc+KFWdD1fb9RF6UeAXlXRtm/c24cm2WcGT8+ zxXF8oCqoL+kVlPC4ax8iGoLZ3mcJMPnp52I0OWrVbSLLrNHSxUnYIbcbDjHGg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none 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 4cL9lt5Fdgz19qb; Mon, 08 Sep 2025 15:26:34 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 588FQYOR076635; Mon, 8 Sep 2025 15:26:34 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 588FQYPw076632; Mon, 8 Sep 2025 15:26:34 GMT (envelope-from git) Date: Mon, 8 Sep 2025 15:26:34 GMT Message-Id: <202509081526.588FQYPw076632@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mark Johnston Subject: git: f865264f6a5e - main - random: Allow pure entropy sources to provide a min-entropy estimate List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: f865264f6a5eba4025c0f6284a48f383717fd74e Auto-Submitted: auto-generated The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=f865264f6a5eba4025c0f6284a48f383717fd74e commit f865264f6a5eba4025c0f6284a48f383717fd74e Author: Mark Johnston AuthorDate: 2025-09-08 14:45:23 +0000 Commit: Mark Johnston CommitDate: 2025-09-08 15:21:43 +0000 random: Allow pure entropy sources to provide a min-entropy estimate The current implementation of the NIST health tests assumes a min-entropy estimate of one bit per sample, which is quite conservative. For so-called "pure" sources (e.g., virtio-random, TPM) it might be nice to support larger estimates so that the tests catch failed devices more quickly. Thus: - let each pure random source provide an estimate, so that downstreams or driver implementors can override defaults if they want to; - increase the default estimate for pure sources; - for pure sources initialize the state machine at source registration time. Reviewed by: cem MFC after: 2 weeks Sponsored by: Stormshield Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D52232 --- sys/dev/random/random_harvestq.c | 21 +++++++++++++++++---- sys/dev/random/randomdev.h | 1 + 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/sys/dev/random/random_harvestq.c b/sys/dev/random/random_harvestq.c index 6d1f9daf649b..c308f6f80d59 100644 --- a/sys/dev/random/random_harvestq.c +++ b/sys/dev/random/random_harvestq.c @@ -478,6 +478,7 @@ random_healthtest_init(enum random_entropy_source source, int min_entropy) struct health_test_softc *ht; ht = &healthtest[source]; + memset(ht, 0, sizeof(*ht)); KASSERT(ht->ht_state == INIT, ("%s: health test state is %d for source %d", __func__, ht->ht_state, source)); @@ -532,12 +533,22 @@ random_healthtest_init(enum random_entropy_source source, int min_entropy) }; const int error_rate = 34; - if (min_entropy == 0) - min_entropy = 1; - else if (min_entropy < 0 || min_entropy >= nitems(apt_cutoffs)) { + if (min_entropy == 0) { + /* + * For environmental sources, the main source of entropy is the + * associated timecounter value. Since these sources can be + * influenced by unprivileged users, we conservatively use a + * min-entropy estimate of 1 bit per sample. For "pure" + * sources, we assume 8 bits per sample, as such sources provide + * a variable amount of data per read and in particular might + * only provide a single byte at a time. + */ + min_entropy = source >= RANDOM_PURE_START ? 8 : 1; + } else if (min_entropy < 0 || min_entropy >= nitems(apt_cutoffs)) { panic("invalid min_entropy %d for %s", min_entropy, random_source_descr[source]); } + ht->ht_rct_limit = 1 + howmany(error_rate, min_entropy); ht->ht_apt_cutoff = apt_cutoffs[min_entropy]; } @@ -707,7 +718,7 @@ random_harvestq_init(void *unused __unused) RANDOM_HARVEST_INIT_LOCK(); harvest_context.hc_active_buf = 0; - for (int i = 0; i < ENTROPYSOURCE; i++) + for (int i = RANDOM_START; i <= RANDOM_ENVIRONMENTAL_END; i++) random_healthtest_init(i, 0); } SYSINIT(random_device_h_init, SI_SUB_RANDOM, SI_ORDER_THIRD, random_harvestq_init, NULL); @@ -901,6 +912,8 @@ random_source_register(const struct random_source *rsource) printf("random: registering fast source %s\n", rsource->rs_ident); + random_healthtest_init(rsource->rs_source, rsource->rs_min_entropy); + RANDOM_HARVEST_LOCK(); hc_source_mask |= (1 << rsource->rs_source); CK_LIST_INSERT_HEAD(&source_list, rrs, rrs_entries); diff --git a/sys/dev/random/randomdev.h b/sys/dev/random/randomdev.h index 0fa92f8c9575..a6ca66c7d92e 100644 --- a/sys/dev/random/randomdev.h +++ b/sys/dev/random/randomdev.h @@ -103,6 +103,7 @@ struct random_source { const char *rs_ident; enum random_entropy_source rs_source; random_source_read_t *rs_read; + int rs_min_entropy; }; void random_source_register(const struct random_source *);