git: d6f10a5d013f - main - random: allow disabling of entropy harvesting from keyboard & mice

From: David E. O'Brien <obrien_at_FreeBSD.org>
Date: Tue, 11 Nov 2025 04:18:08 UTC
The branch main has been updated by obrien:

URL: https://cgit.FreeBSD.org/src/commit/?id=d6f10a5d013fdcc92847644ffbaf65cbf491bb39

commit d6f10a5d013fdcc92847644ffbaf65cbf491bb39
Author:     David E. O'Brien <obrien@FreeBSD.org>
AuthorDate: 2025-10-28 02:57:21 +0000
Commit:     David E. O'Brien <obrien@FreeBSD.org>
CommitDate: 2025-11-11 02:47:41 +0000

    random: allow disabling of entropy harvesting from keyboard & mice
    
    Reviewed by:    jmg
    Sponsored by:   Juniper Networks
    Differential Revision:  https://reviews.freebsd.org/D53390
---
 sys/amd64/conf/GENERIC       | 2 ++
 sys/amd64/conf/MINIMAL       | 2 ++
 sys/arm/conf/GENERIC         | 2 ++
 sys/arm64/conf/std.arm64     | 2 ++
 sys/conf/NOTES               | 2 ++
 sys/conf/options             | 2 ++
 sys/dev/vt/vt_core.c         | 2 ++
 sys/dev/vt/vt_sysmouse.c     | 3 ++-
 sys/powerpc/conf/GENERIC64   | 4 ++++
 sys/powerpc/conf/GENERIC64LE | 4 ++++
 sys/riscv/conf/GENERIC       | 4 ++++
 11 files changed, 28 insertions(+), 1 deletion(-)

diff --git a/sys/amd64/conf/GENERIC b/sys/amd64/conf/GENERIC
index 1de895a5b333..4e710e47fdae 100644
--- a/sys/amd64/conf/GENERIC
+++ b/sys/amd64/conf/GENERIC
@@ -326,6 +326,8 @@ device		bpf			# Berkeley packet filter
 device		rdrand_rng		# Intel Bull Mountain RNG
 device		tpm			# Trusted Platform Module
 options 	RANDOM_ENABLE_TPM	# enable entropy from TPM 2.0
+options 	RANDOM_ENABLE_KBD
+options 	RANDOM_ENABLE_MOUSE
 
 # USB support
 options 	USB_DEBUG		# enable debug msgs
diff --git a/sys/amd64/conf/MINIMAL b/sys/amd64/conf/MINIMAL
index 2bd8851ab20c..8df3349b4c34 100644
--- a/sys/amd64/conf/MINIMAL
+++ b/sys/amd64/conf/MINIMAL
@@ -124,6 +124,8 @@ device		bpf			# Berkeley packet filter
 device		rdrand_rng		# Intel Bull Mountain RNG
 device		tpm			# Trusted Platform Module
 options 	RANDOM_ENABLE_TPM	# enable entropy from TPM 2.0
+options 	RANDOM_ENABLE_KBD
+options 	RANDOM_ENABLE_MOUSE
 
 # VirtIO support
 device		virtio			# Generic VirtIO bus (required)
diff --git a/sys/arm/conf/GENERIC b/sys/arm/conf/GENERIC
index 0d741a7e584a..89841947713d 100644
--- a/sys/arm/conf/GENERIC
+++ b/sys/arm/conf/GENERIC
@@ -219,6 +219,8 @@ device		smsc			# SMSC LAN91C111
 # random(4)
 device		tpm			# Trusted Platform Module
 options 	RANDOM_ENABLE_TPM	# enable entropy from TPM 2.0
+options 	RANDOM_ENABLE_KBD
+options 	RANDOM_ENABLE_MOUSE
 
 # Sound support
 device		sound
diff --git a/sys/arm64/conf/std.arm64 b/sys/arm64/conf/std.arm64
index 003f13c8f1cc..02bdd25f2d52 100644
--- a/sys/arm64/conf/std.arm64
+++ b/sys/arm64/conf/std.arm64
@@ -110,3 +110,5 @@ device		smbios
 # random(4)
 device		tpm			# Trusted Platform Module
 options 	RANDOM_ENABLE_TPM	# enable entropy from TPM 2.0
+options 	RANDOM_ENABLE_KBD
+options 	RANDOM_ENABLE_MOUSE
diff --git a/sys/conf/NOTES b/sys/conf/NOTES
index 71d14dc8915f..3d5f7dd8a71b 100644
--- a/sys/conf/NOTES
+++ b/sys/conf/NOTES
@@ -2825,6 +2825,8 @@ options 	RANDOM_ENABLE_UMA	# slab allocator
 # environment.
 options 	RANDOM_ENABLE_ETHER	# ether_input
 
+options 	RANDOM_ENABLE_KBD
+options 	RANDOM_ENABLE_MOUSE
 options 	RANDOM_ENABLE_TPM	# implies TPM_HARVEST
 
 # Module to enable execution of application via emulators like QEMU
diff --git a/sys/conf/options b/sys/conf/options
index 963263e8a732..2437c2c6908a 100644
--- a/sys/conf/options
+++ b/sys/conf/options
@@ -956,6 +956,8 @@ RANDOM_LOADABLE	opt_global.h
 # the uma slab allocator.
 RANDOM_ENABLE_UMA	opt_global.h
 RANDOM_ENABLE_ETHER	opt_global.h
+RANDOM_ENABLE_KBD	opt_global.h
+RANDOM_ENABLE_MOUSE	opt_global.h
 RANDOM_ENABLE_TPM	opt_global.h
 
 # This options turns TPM into entropy source.
diff --git a/sys/dev/vt/vt_core.c b/sys/dev/vt/vt_core.c
index bcf67ddc9689..a1376be954ee 100644
--- a/sys/dev/vt/vt_core.c
+++ b/sys/dev/vt/vt_core.c
@@ -876,7 +876,9 @@ vt_processkey(keyboard_t *kbd, struct vt_device *vd, int c)
 {
 	struct vt_window *vw = vd->vd_curwindow;
 
+#ifdef RANDOM_ENABLE_KBD
 	random_harvest_queue(&c, sizeof(c), RANDOM_KEYBOARD);
+#endif
 #if VT_ALT_TO_ESC_HACK
 	if (c & RELKEY) {
 		switch (c & ~RELKEY) {
diff --git a/sys/dev/vt/vt_sysmouse.c b/sys/dev/vt/vt_sysmouse.c
index f2f5a0fa5c3a..873dce123f7a 100644
--- a/sys/dev/vt/vt_sysmouse.c
+++ b/sys/dev/vt/vt_sysmouse.c
@@ -32,7 +32,6 @@
  * SUCH DAMAGE.
  */
 
-#include <sys/cdefs.h>
 #include "opt_evdev.h"
 
 #include <sys/param.h>
@@ -222,7 +221,9 @@ sysmouse_process_event(mouse_info_t *mi)
 	unsigned char buf[MOUSE_SYS_PACKETSIZE];
 	int x, y, iy, z;
 
+#ifdef RANDOM_ENABLE_MOUSE
 	random_harvest_queue(mi, sizeof *mi, RANDOM_MOUSE);
+#endif
 
 	mtx_lock(&sysmouse_lock);
 	switch (mi->operation) {
diff --git a/sys/powerpc/conf/GENERIC64 b/sys/powerpc/conf/GENERIC64
index 91c91d58d058..e215651e4c3d 100644
--- a/sys/powerpc/conf/GENERIC64
+++ b/sys/powerpc/conf/GENERIC64
@@ -207,6 +207,10 @@ device		xz		# lzma decompression
 # Note that 'bpf' is required for DHCP.
 device		bpf		# Berkeley packet filter
 
+# random(4)
+options 	RANDOM_ENABLE_KBD
+options 	RANDOM_ENABLE_MOUSE
+
 # USB support
 options 	USB_DEBUG	# enable debug msgs
 device		uhci		# UHCI PCI->USB interface
diff --git a/sys/powerpc/conf/GENERIC64LE b/sys/powerpc/conf/GENERIC64LE
index 5fb9715de655..4759b70a3d1f 100644
--- a/sys/powerpc/conf/GENERIC64LE
+++ b/sys/powerpc/conf/GENERIC64LE
@@ -203,6 +203,10 @@ device		xz		# lzma decompression
 # Note that 'bpf' is required for DHCP.
 device		bpf		# Berkeley packet filter
 
+# random(4)
+options 	RANDOM_ENABLE_KBD
+options 	RANDOM_ENABLE_MOUSE
+
 # USB support
 options 	USB_DEBUG	# enable debug msgs
 device		uhci		# UHCI PCI->USB interface
diff --git a/sys/riscv/conf/GENERIC b/sys/riscv/conf/GENERIC
index a7e1200e3884..36e3fcd41970 100644
--- a/sys/riscv/conf/GENERIC
+++ b/sys/riscv/conf/GENERIC
@@ -197,6 +197,10 @@ device		mmcsd			# MMC/SD flash cards
 # Note that 'bpf' is required for DHCP.
 device		bpf		# Berkeley packet filter
 
+# random(4)
+options 	RANDOM_ENABLE_KBD
+options 	RANDOM_ENABLE_MOUSE
+
 # Flattened Device Tree
 options 	FDT