Skip to contentSkip to conversation

random: give sysctl_random_min_urandom_seed a more sensible value

PATCH In review Jason A. Donenfeld 2 participants 4 messages Feb 28, 2022 – Mar 1, 2022 Random number driver

lore
Share & tools
lore

Jason A. Donenfeld

author maintainer
#0 lore raw

PATCH 1/2 random: give sysctl_random_min_urandom_seed a more sensible value

This isn't used by anything or anywhere, but we can't delete it due to compatibility. So at least give it the correct value of what it's supposed to be instead of a garbage one.

Cc Dominik Brodowski <[email protected]>
Cc Theodore Ts'o <[email protected]>
---
 drivers/char/random.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/char/random.c +2 -2
index 8171c3bbf460..116ebf50d791 100644
@@ -1619,7 +1619,7 @@ const struct file_operations urandom_fops = {
  *   to avoid breaking old userspaces, but writing to it does not
  *   change any behavior of the RNG.
  *
- * - urandom_min_reseed_secs - fixed to the meaningless value "60".
+ * - urandom_min_reseed_secs - fixed to the value CRNG_RESEED_INTERVAL.
  *   It is writable to avoid breaking old userspaces, but writing
  *   to it does not change any behavior of the RNG.
  *
@@ -1629,7 +1629,7 @@ const struct file_operations urandom_fops = {
 
 #include <linux/sysctl.h>
 
-static int sysctl_random_min_urandom_seed = 60;
+static int sysctl_random_min_urandom_seed = CRNG_RESEED_INTERVAL / HZ;
 static int sysctl_random_write_wakeup_bits = POOL_MIN_BITS;
 static int sysctl_poolsize = POOL_BITS;
 static u8 sysctl_bootid[UUID_SIZE];
Signature · 1 line
2.35.1
author maintainer
#1 lore raw

PATCH 2/2 random: don't let 644 read-only sysctls be written to

We leave around these old sysctls for compatibility, and we keep them "writable" for compatibility, but even after writing, we should keep reporting the same value. This is consistent with how userspaces tend to use sysctl_random_write_wakeup_bits, writing to it, and then later reading from it and using the value.

Cc Dominik Brodowski <[email protected]>
Cc Theodore Ts'o <[email protected]>
---
 drivers/char/random.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
drivers/char/random.c +9 -2
index 116ebf50d791..06c6e15b5f3d 100644
@@ -1669,6 +1669,13 @@ static int proc_do_uuid(struct ctl_table *table, int write, void *buffer,
 	return proc_dostring(&fake_table, 0, buffer, lenp, ppos);
 }
 
+/* The same as proc_dointvec, but writes don't change anything. */
+static int proc_do_rointvec(struct ctl_table *table, int write, void *buffer,
+			    size_t *lenp, loff_t *ppos)
+{
+	return write ? 0 : proc_dointvec(table, write, buffer, lenp, ppos);
+}
+
 static struct ctl_table random_table[] = {
 	{
 		.procname	= "poolsize",
@@ -1689,14 +1696,14 @@ static struct ctl_table random_table[] = {
 		.data		= &sysctl_random_write_wakeup_bits,
 		.maxlen		= sizeof(int),
 		.mode		= 0644,
-		.proc_handler	= proc_dointvec,
+		.proc_handler	= proc_do_rointvec,
 	},
 	{
 		.procname	= "urandom_min_reseed_secs",
 		.data		= &sysctl_random_min_urandom_seed,
 		.maxlen		= sizeof(int),
 		.mode		= 0644,
-		.proc_handler	= proc_dointvec,
+		.proc_handler	= proc_do_rointvec,
 	},
 	{
 		.procname	= "boot_id",
Signature · 1 line
2.35.1
Reviewed-by on v1 2/2
#2 lore raw

Re: [PATCH 2/2] random: don't let 644 read-only sysctls be written to

Am Mon, Feb 28, 2022 at 02:37:43PM +0100 schrieb Jason A. Donenfeld:

Quoted 18 lines

We leave around these old sysctls for compatibility, and we keep them "writable" for compatibility, but even after writing, we should keep reporting the same value. This is consistent with how userspaces tend to use sysctl_random_write_wakeup_bits, writing to it, and then later reading from it and using the value.

Cc Dominik Brodowski <[email protected]>
Cc Theodore Ts'o <[email protected]>
---
 drivers/char/random.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
drivers/char/random.c +0 -0
index 116ebf50d791..06c6e15b5f3d 100644

drivers/char/random.c static int proc_do_uuid(struct ctl_table *table, int write, void *buffer, · line 1677

Quoted 9 lines
drivers/char/random.c +6 -0
@@ -1669,6 +1669,13 @@ static int proc_do_uuid(struct ctl_table *table, int write, void *buffer,
 	return proc_dostring(&fake_table, 0, buffer, lenp, ppos);
 }
 
+/* The same as proc_dointvec, but writes don't change anything. */
+static int proc_do_rointvec(struct ctl_table *table, int write, void *buffer,
+			    size_t *lenp, loff_t *ppos)
+{
+	return write ? 0 : proc_dointvec(table, write, buffer, lenp, ppos);
+}

While it would be better if we could return -EINVAL or something like that, I see the point of this patch:

Reviewed-by on v1 1/2
#3 lore raw
In reply to Jason A. Donenfeld

Am Mon, Feb 28, 2022 at 02:37:42PM +0100 schrieb Jason A. Donenfeld:

Quoted 7 lines

This isn't used by anything or anywhere, but we can't delete it due to compatibility. So at least give it the correct value of what it's supposed to be instead of a garbage one.

Cc Dominik Brodowski <[email protected]>
Cc Theodore Ts'o <[email protected]>

Thanks,
Dominik