On Tue, Sep 23, 2025 at 02:33:05PM +0100, Jonathan McDowell wrote:
> From: Jonathan McDowell <[email protected]>
> 
> The HW RNG core allows for manual selection of which RNG device to use,
> but does not allow for no device to be enabled. It may be desirable to
> do this on systems with only a single suitable hardware RNG, where we
> need exclusive access to other functionality on this device. In
> particular when performing TPM firmware upgrades this lets us ensure the
> kernel does not try to access the device.
> 
> Before:
> 
> root@debian-qemu-efi:~# grep "" /sys/devices/virtual/misc/hw_random/rng_*
> /sys/devices/virtual/misc/hw_random/rng_available:tpm-rng-0
> /sys/devices/virtual/misc/hw_random/rng_current:tpm-rng-0
> /sys/devices/virtual/misc/hw_random/rng_quality:1024
> /sys/devices/virtual/misc/hw_random/rng_selected:0
> 
> After:
> 
> root@debian-qemu-efi:~# grep "" /sys/devices/virtual/misc/hw_random/rng_*
> /sys/devices/virtual/misc/hw_random/rng_available:tpm-rng-0 none
> /sys/devices/virtual/misc/hw_random/rng_current:tpm-rng-0
> /sys/devices/virtual/misc/hw_random/rng_quality:1024
> /sys/devices/virtual/misc/hw_random/rng_selected:0
> 
> root@debian-qemu-efi:~# echo none > 
> /sys/devices/virtual/misc/hw_random/rng_current
> root@debian-qemu-efi:~# grep "" /sys/devices/virtual/misc/hw_random/rng_*
> /sys/devices/virtual/misc/hw_random/rng_available:tpm-rng-0 none
> /sys/devices/virtual/misc/hw_random/rng_current:none
> grep: /sys/devices/virtual/misc/hw_random/rng_quality: No such device
> /sys/devices/virtual/misc/hw_random/rng_selected:1
> 
> (Observe using bpftrace no calls to TPM being made)
> 
> root@debian-qemu-efi:~# echo "" > 
> /sys/devices/virtual/misc/hw_random/rng_current
> root@debian-qemu-efi:~# grep "" /sys/devices/virtual/misc/hw_random/rng_*
> /sys/devices/virtual/misc/hw_random/rng_available:tpm-rng-0 none
> /sys/devices/virtual/misc/hw_random/rng_current:tpm-rng-0
> /sys/devices/virtual/misc/hw_random/rng_quality:1024
> /sys/devices/virtual/misc/hw_random/rng_selected:0
> 
> (Observe using bpftrace that calls to the TPM resume)
> 
> Signed-off-by: Jonathan McDowell <[email protected]>
> ---
> v3: Always set cur_rng_set_by_user if user forces no HW RNG.
> v2: If the user manually forces the HWRNG to none do not override this
>     when a new driver is loaded. Pointed out by Herbert Xu.
>  drivers/char/hw_random/core.c | 9 ++++++---
>  1 file changed, 6 insertions(+), 3 deletions(-)

Patch applied.  Thanks.
-- 
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

Reply via email to