* [PATCH] hwrng: core - Allow runtime disabling of the HW RNG
@ 2025-09-01 13:55 Jonathan McDowell
2025-09-13 3:56 ` Herbert Xu
2025-09-15 16:02 ` [PATCH v2] " Jonathan McDowell
0 siblings, 2 replies; 8+ messages in thread
From: Jonathan McDowell @ 2025-09-01 13:55 UTC (permalink / raw)
To: Olivia Mackall, Herbert Xu; +Cc: linux-crypto, linux-kernel, linux-integrity
From: Jonathan McDowell <noodles@meta.com>
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 <noodles@meta.com>
---
drivers/char/hw_random/core.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/drivers/char/hw_random/core.c b/drivers/char/hw_random/core.c
index 018316f54621..11c8077b792b 100644
--- a/drivers/char/hw_random/core.c
+++ b/drivers/char/hw_random/core.c
@@ -341,6 +341,10 @@ static ssize_t rng_current_store(struct device *dev,
if (sysfs_streq(buf, "")) {
err = enable_best_rng();
+ } else if (sysfs_streq(buf, "none")) {
+ if (current_rng)
+ cur_rng_set_by_user = 1;
+ drop_current_rng();
} else {
list_for_each_entry(rng, &rng_list, list) {
if (sysfs_streq(rng->name, buf)) {
@@ -392,7 +396,7 @@ static ssize_t rng_available_show(struct device *dev,
strlcat(buf, rng->name, PAGE_SIZE);
strlcat(buf, " ", PAGE_SIZE);
}
- strlcat(buf, "\n", PAGE_SIZE);
+ strlcat(buf, "none\n", PAGE_SIZE);
mutex_unlock(&rng_mutex);
return strlen(buf);
--
2.51.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH] hwrng: core - Allow runtime disabling of the HW RNG
2025-09-01 13:55 [PATCH] hwrng: core - Allow runtime disabling of the HW RNG Jonathan McDowell
@ 2025-09-13 3:56 ` Herbert Xu
2025-09-13 14:08 ` Jonathan McDowell
2025-09-15 16:02 ` [PATCH v2] " Jonathan McDowell
1 sibling, 1 reply; 8+ messages in thread
From: Herbert Xu @ 2025-09-13 3:56 UTC (permalink / raw)
To: Jonathan McDowell
Cc: Olivia Mackall, linux-crypto, linux-kernel, linux-integrity
On Mon, Sep 01, 2025 at 02:55:01PM +0100, Jonathan McDowell wrote:
> From: Jonathan McDowell <noodles@meta.com>
>
> 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 <noodles@meta.com>
> ---
> drivers/char/hw_random/core.c | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/char/hw_random/core.c b/drivers/char/hw_random/core.c
> index 018316f54621..11c8077b792b 100644
> --- a/drivers/char/hw_random/core.c
> +++ b/drivers/char/hw_random/core.c
> @@ -341,6 +341,10 @@ static ssize_t rng_current_store(struct device *dev,
>
> if (sysfs_streq(buf, "")) {
> err = enable_best_rng();
> + } else if (sysfs_streq(buf, "none")) {
> + if (current_rng)
> + cur_rng_set_by_user = 1;
> + drop_current_rng();
Is this setting supposed to be sticky?
Because as it stands, if another HWRNG is registered after setting
it to none, it would still become the default RNG which seems to be
surprising.
Cheers,
--
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] hwrng: core - Allow runtime disabling of the HW RNG
2025-09-13 3:56 ` Herbert Xu
@ 2025-09-13 14:08 ` Jonathan McDowell
0 siblings, 0 replies; 8+ messages in thread
From: Jonathan McDowell @ 2025-09-13 14:08 UTC (permalink / raw)
To: Herbert Xu; +Cc: Olivia Mackall, linux-crypto, linux-kernel, linux-integrity
On Sat, Sep 13, 2025 at 11:56:27AM +0800, Herbert Xu wrote:
>On Mon, Sep 01, 2025 at 02:55:01PM +0100, Jonathan McDowell wrote:
>> From: Jonathan McDowell <noodles@meta.com>
>>
>> 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 <noodles@meta.com>
>> ---
>> drivers/char/hw_random/core.c | 6 +++++-
>> 1 file changed, 5 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/char/hw_random/core.c b/drivers/char/hw_random/core.c
>> index 018316f54621..11c8077b792b 100644
>> --- a/drivers/char/hw_random/core.c
>> +++ b/drivers/char/hw_random/core.c
>> @@ -341,6 +341,10 @@ static ssize_t rng_current_store(struct device *dev,
>>
>> if (sysfs_streq(buf, "")) {
>> err = enable_best_rng();
>> + } else if (sysfs_streq(buf, "none")) {
>> + if (current_rng)
>> + cur_rng_set_by_user = 1;
>> + drop_current_rng();
>
>Is this setting supposed to be sticky?
>
>Because as it stands, if another HWRNG is registered after setting
>it to none, it would still become the default RNG which seems to be
>surprising.
Good point, I'd missed that (it's not likely to be an issue in my
situation), but I'll spin a v2 that fixes up hwrng_register() too.
J.
--
I'm an atheist myself - there is no Greg Hill.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v2] hwrng: core - Allow runtime disabling of the HW RNG
2025-09-01 13:55 [PATCH] hwrng: core - Allow runtime disabling of the HW RNG Jonathan McDowell
2025-09-13 3:56 ` Herbert Xu
@ 2025-09-15 16:02 ` Jonathan McDowell
2025-09-23 3:43 ` Herbert Xu
2025-09-23 13:33 ` [PATCH v3] " Jonathan McDowell
1 sibling, 2 replies; 8+ messages in thread
From: Jonathan McDowell @ 2025-09-15 16:02 UTC (permalink / raw)
To: Olivia Mackall, Herbert Xu; +Cc: linux-crypto, linux-kernel, linux-integrity
From: Jonathan McDowell <noodles@meta.com>
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 <noodles@meta.com>
---
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 | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/drivers/char/hw_random/core.c b/drivers/char/hw_random/core.c
index 018316f54621..1682a9f1b28c 100644
--- a/drivers/char/hw_random/core.c
+++ b/drivers/char/hw_random/core.c
@@ -341,6 +341,10 @@ static ssize_t rng_current_store(struct device *dev,
if (sysfs_streq(buf, "")) {
err = enable_best_rng();
+ } else if (sysfs_streq(buf, "none")) {
+ if (current_rng)
+ cur_rng_set_by_user = 1;
+ drop_current_rng();
} else {
list_for_each_entry(rng, &rng_list, list) {
if (sysfs_streq(rng->name, buf)) {
@@ -392,7 +396,7 @@ static ssize_t rng_available_show(struct device *dev,
strlcat(buf, rng->name, PAGE_SIZE);
strlcat(buf, " ", PAGE_SIZE);
}
- strlcat(buf, "\n", PAGE_SIZE);
+ strlcat(buf, "none\n", PAGE_SIZE);
mutex_unlock(&rng_mutex);
return strlen(buf);
@@ -544,8 +548,8 @@ int hwrng_register(struct hwrng *rng)
/* Adjust quality field to always have a proper value */
rng->quality = min_t(u16, min_t(u16, default_quality, 1024), rng->quality ?: 1024);
- if (!current_rng ||
- (!cur_rng_set_by_user && rng->quality > current_rng->quality)) {
+ if (!cur_rng_set_by_user &&
+ (!current_rng || rng->quality > current_rng->quality)) {
/*
* Set new rng as current as the new rng source
* provides better entropy quality and was not
--
2.51.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH v2] hwrng: core - Allow runtime disabling of the HW RNG
2025-09-15 16:02 ` [PATCH v2] " Jonathan McDowell
@ 2025-09-23 3:43 ` Herbert Xu
2025-09-23 8:48 ` Jonathan McDowell
2025-09-23 13:33 ` [PATCH v3] " Jonathan McDowell
1 sibling, 1 reply; 8+ messages in thread
From: Herbert Xu @ 2025-09-23 3:43 UTC (permalink / raw)
To: Jonathan McDowell
Cc: Olivia Mackall, linux-crypto, linux-kernel, linux-integrity
On Mon, Sep 15, 2025 at 05:02:15PM +0100, Jonathan McDowell wrote:
>
> diff --git a/drivers/char/hw_random/core.c b/drivers/char/hw_random/core.c
> index 018316f54621..1682a9f1b28c 100644
> --- a/drivers/char/hw_random/core.c
> +++ b/drivers/char/hw_random/core.c
> @@ -341,6 +341,10 @@ static ssize_t rng_current_store(struct device *dev,
> if (sysfs_streq(buf, "")) {
> err = enable_best_rng();
> + } else if (sysfs_streq(buf, "none")) {
> + if (current_rng)
> + cur_rng_set_by_user = 1;
Shouldn't this be set unconditionally?
Thanks,
--
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v2] hwrng: core - Allow runtime disabling of the HW RNG
2025-09-23 3:43 ` Herbert Xu
@ 2025-09-23 8:48 ` Jonathan McDowell
0 siblings, 0 replies; 8+ messages in thread
From: Jonathan McDowell @ 2025-09-23 8:48 UTC (permalink / raw)
To: Herbert Xu; +Cc: Olivia Mackall, linux-crypto, linux-kernel, linux-integrity
On Tue, Sep 23, 2025 at 11:43:12AM +0800, Herbert Xu wrote:
>On Mon, Sep 15, 2025 at 05:02:15PM +0100, Jonathan McDowell wrote:
>>
>> diff --git a/drivers/char/hw_random/core.c b/drivers/char/hw_random/core.c
>> index 018316f54621..1682a9f1b28c 100644
>> --- a/drivers/char/hw_random/core.c
>> +++ b/drivers/char/hw_random/core.c
>> @@ -341,6 +341,10 @@ static ssize_t rng_current_store(struct device *dev,
>> if (sysfs_streq(buf, "")) {
>> err = enable_best_rng();
>> + } else if (sysfs_streq(buf, "none")) {
>> + if (current_rng)
>> + cur_rng_set_by_user = 1;
>
>Shouldn't this be set unconditionally?
Yes, I guess so. I'd been guided by enable_best_rng() which only clears
it if it changes the current RNG, but re-reading I agree that's probably
the wrong thing here.
J.
--
101 things you can't have too much of : 16 - Time.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v3] hwrng: core - Allow runtime disabling of the HW RNG
2025-09-15 16:02 ` [PATCH v2] " Jonathan McDowell
2025-09-23 3:43 ` Herbert Xu
@ 2025-09-23 13:33 ` Jonathan McDowell
2025-10-17 8:17 ` Herbert Xu
1 sibling, 1 reply; 8+ messages in thread
From: Jonathan McDowell @ 2025-09-23 13:33 UTC (permalink / raw)
To: Olivia Mackall, Herbert Xu; +Cc: linux-crypto, linux-kernel, linux-integrity
From: Jonathan McDowell <noodles@meta.com>
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 <noodles@meta.com>
---
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(-)
diff --git a/drivers/char/hw_random/core.c b/drivers/char/hw_random/core.c
index 018316f54621..56d888bebe0c 100644
--- a/drivers/char/hw_random/core.c
+++ b/drivers/char/hw_random/core.c
@@ -341,6 +341,9 @@ static ssize_t rng_current_store(struct device *dev,
if (sysfs_streq(buf, "")) {
err = enable_best_rng();
+ } else if (sysfs_streq(buf, "none")) {
+ cur_rng_set_by_user = 1;
+ drop_current_rng();
} else {
list_for_each_entry(rng, &rng_list, list) {
if (sysfs_streq(rng->name, buf)) {
@@ -392,7 +395,7 @@ static ssize_t rng_available_show(struct device *dev,
strlcat(buf, rng->name, PAGE_SIZE);
strlcat(buf, " ", PAGE_SIZE);
}
- strlcat(buf, "\n", PAGE_SIZE);
+ strlcat(buf, "none\n", PAGE_SIZE);
mutex_unlock(&rng_mutex);
return strlen(buf);
@@ -544,8 +547,8 @@ int hwrng_register(struct hwrng *rng)
/* Adjust quality field to always have a proper value */
rng->quality = min_t(u16, min_t(u16, default_quality, 1024), rng->quality ?: 1024);
- if (!current_rng ||
- (!cur_rng_set_by_user && rng->quality > current_rng->quality)) {
+ if (!cur_rng_set_by_user &&
+ (!current_rng || rng->quality > current_rng->quality)) {
/*
* Set new rng as current as the new rng source
* provides better entropy quality and was not
--
2.51.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH v3] hwrng: core - Allow runtime disabling of the HW RNG
2025-09-23 13:33 ` [PATCH v3] " Jonathan McDowell
@ 2025-10-17 8:17 ` Herbert Xu
0 siblings, 0 replies; 8+ messages in thread
From: Herbert Xu @ 2025-10-17 8:17 UTC (permalink / raw)
To: Jonathan McDowell
Cc: Olivia Mackall, linux-crypto, linux-kernel, linux-integrity
On Tue, Sep 23, 2025 at 02:33:05PM +0100, Jonathan McDowell wrote:
> From: Jonathan McDowell <noodles@meta.com>
>
> 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 <noodles@meta.com>
> ---
> 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 <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2025-10-17 8:18 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-01 13:55 [PATCH] hwrng: core - Allow runtime disabling of the HW RNG Jonathan McDowell
2025-09-13 3:56 ` Herbert Xu
2025-09-13 14:08 ` Jonathan McDowell
2025-09-15 16:02 ` [PATCH v2] " Jonathan McDowell
2025-09-23 3:43 ` Herbert Xu
2025-09-23 8:48 ` Jonathan McDowell
2025-09-23 13:33 ` [PATCH v3] " Jonathan McDowell
2025-10-17 8:17 ` Herbert Xu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).