From nobody Fri Oct 30 22:30:23 2026 X-Original-To: dev-commits-src-all@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 4jGbQR4gFPz6xgs2 for ; Fri, 30 Oct 2026 22:30:23 +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) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 4jGbQR1fPqz4fGM for ; Fri, 30 Oct 2026 22:30:23 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1793399423; 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=/HzozyDFbX6a2Kqg7VeFYyUWUl4jMxLd0BVWVaKHrl4=; b=khVewG4wxe+UE+90//hEJziENOKBStc4Dn5KzXN9lNvNi/BHz08pzByths5eR7K33u25TN Y54aMXBOMyZaqadqqIXpJGUqqX6VHGsXUrr4gM3L7XEq7vLTMpPn1fS03K14oWrD8d2zzL 8Jf7Hgrdec9UeLgG2PkDE26+RHs+m0Q8p7rO/qUspDoaxp2MUU2tTYCQOlBf9XXftm6zyN 6slIG8nIZNqEvDtPJq6SmvPLPc4Kf3ws3i2Rj7Cn2/aLNqYX7R+aMNkmbc0fkQWI5EAEvR yxVR0+QqFVFGi0PTBQuZawju9O9zKBgxarr37pQ6e1j15N4oimTYPnSTjThANA== ARC-Seal: i=1; a=rsa-sha256; d=freebsd.org; s=dkim; cv=none; t=1793399423; b=rBgmoThUe5ZtbX9YxwLxFodiyty9IukzkwqTD1c5HSeJTOtYZu/h4kHw6tfqMJ7ioe0Hbp xe76p3tKXRS7U0U2O/zQld6tbNP1cyjXxwQklifBSrhbt0bZsovfD4ofmdHmP6eDxYx+Az BbPLoEAYJ2+3ALP27++ZrU5exuzZ6om3jfdfCbVGCwYwZB6QkmHZBcefbiDvMC9ALjy/9V m2cC4v68fIin6mVMYQ0UlCre8qKVdjz23ADoISm2nZBqszz7fkwnBH8L5nL8QtlIMhDUHK CfKOMZD3BvL8y+UvYLUFxBo9agrVF4D4jQOzTzMmsymaXUcMuPA38BFLU4l14g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1793399423; 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=/HzozyDFbX6a2Kqg7VeFYyUWUl4jMxLd0BVWVaKHrl4=; b=jCCrk6ttTn3VZ0ovZ3s3E5VLtd1UcSKGziPbE8i6eq2aJPe5L47QC2EY+GCY5gPaO1/m27 GPpOa7nLIT4sKEp+5D0ZVr6SoIpbHKtc5O3zvcwx+R8HlojV8PvMECc1RHeGMEuGNDo+y5 PSSBKcOOxOI0r1AxAGTtC/quBvgWUEJ4S1RWaSO7mXILr6NLccFq2VwaZKLO1uBlAzPrBT Y10AG4M/9ofWDsz5IFtYDifL0Uyxof3NNyqKc46bwWRDK1Dl73rxNzWjoGwP+RIq6f9SYr lb3ePBZ1uouyHeKbawbAI/+EcRPTloGaW6TzHHCv4iERvw1YoD1DlO/Na01/MQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4jGbQR1C7CznNk for ; Fri, 30 Oct 2026 22:30:23 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 37eca by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Fri, 30 Oct 2026 22:30:23 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Kevin Bowling Subject: git: 914892d374e9 - main - tpm20: Preserve all harvested random bytes List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org List-Id: Commit messages for all branches of the src repository List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kbowling X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 914892d374e924cae2a0a1d7a669f246a845ad35 Auto-Submitted: auto-generated Date: Fri, 30 Oct 2026 22:30:23 +0000 Message-Id: <6ae51a7f.37eca.1dfeee2b@gitrepo.freebsd.org> The branch main has been updated by kbowling: URL: https://cgit.FreeBSD.org/src/commit/?id=914892d374e924cae2a0a1d7a669f246a845ad35 commit 914892d374e924cae2a0a1d7a669f246a845ad35 Author: Kevin Bowling AuthorDate: 2026-08-28 00:32:33 +0000 Commit: Kevin Bowling CommitDate: 2026-10-30 22:29:45 +0000 tpm20: Preserve all harvested random bytes The TPM requests 16 random bytes every ten seconds, but a random harvest event retains at most eight bytes. random_harvest_queue() reduces a larger input to one 32-bit Jenkins hash, so each successful TPM request contributed only four bytes to the entropy accumulator. Split the response into harvest event sized chunks. This preserves all 16 random bytes without increasing the TPM command rate or changing its high quality source classification. MFC after: 2 weeks Sponsored by: BBOX.io Differential Revision: https://reviews.freebsd.org/D59246 --- sys/dev/tpm/tpm20.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/sys/dev/tpm/tpm20.c b/sys/dev/tpm/tpm20.c index 6c96f1ce848d..b5d40eeac7d7 100644 --- a/sys/dev/tpm/tpm20.c +++ b/sys/dev/tpm/tpm20.c @@ -32,6 +32,10 @@ #include "tpm20.h" +#if defined TPM_HARVEST || defined RANDOM_ENABLE_TPM +#include +#endif + #define TPM_HARVEST_SIZE 16 #define TPM2_ST_NO_SESSIONS 0x8001 @@ -57,6 +61,7 @@ MALLOC_DEFINE(M_TPM20, "tpm_buffer", "buffer for tpm 2.0 driver"); #if defined TPM_HARVEST || defined RANDOM_ENABLE_TPM static void tpm20_harvest(void *arg, int unused); +static void tpm20_harvest_enqueue(const uint8_t *, size_t); #endif static int tpm20_command(device_t, uint32_t, uint16_t, uint32_t, const char *); @@ -388,6 +393,23 @@ tpm20_shutdown(device_t dev) } #if defined TPM_HARVEST || defined RANDOM_ENABLE_TPM +static void +tpm20_harvest_enqueue(const uint8_t *entropy, size_t entropy_size) +{ + size_t chunk_size; + + /* Preserve all RNG bytes rather than squashing an oversized event. */ + chunk_size = sizeof(((struct harvest_event *)0)->he_entropy); + while (entropy_size != 0) { + size_t size; + + size = MIN(entropy_size, chunk_size); + random_harvest_queue(entropy, (u_int)size, RANDOM_PURE_TPM); + entropy += size; + entropy_size -= size; + } +} + /* * Get TPM_HARVEST_SIZE random bytes and add them * into system entropy pool. @@ -434,7 +456,7 @@ tpm20_harvest(void *arg, int unused) sx_xunlock(&sc->dev_lock); if (entropy_size > 0) - random_harvest_queue(entropy, entropy_size, RANDOM_PURE_TPM); + tpm20_harvest_enqueue(entropy, entropy_size); } #endif /* TPM_HARVEST */