Skip to contentSkip to conversation

random: re-add removed comment about get_random_{u32,u64} reseeding

PATCH Superseded Jason A. Donenfeld 2 participants 6 messages Mar 23, 2022 – Mar 24, 2022 Random number driver

lore
Share & tools
lore

Jason A. Donenfeld

author maintainer
#0 lore raw

PATCH 1/1 random: re-add removed comment about get_random_{u32,u64} reseeding

The comment about get_random_{u32,u64}() not invoking reseeding got added in an unrelated commit, that then was recently reverted. So this adds that little comment snippet back.

---
 drivers/char/random.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/char/random.c +1 -1
index 1d7aac2a9600..82e37d7dd9f1 100644
@@ -226,7 +226,7 @@ static void _warn_unseeded_randomness(const char *func_name, void *caller, void
  * into the given buffer or as a return value. This is equivalent to
  * a read from /dev/urandom. The integer family of functions may be
  * higher performance for one-off random integers, because they do a
- * bit of buffering.
+ * bit of buffering and do not invoke reseeding.
  *
  *********************************************************************/
 
Signature · 1 line
2.35.1
#1 lore raw

Am Tue, Mar 22, 2022 at 10:23:36PM -0600 schrieb Jason A. Donenfeld:

Quoted 15 lines

The comment about get_random_{u32,u64}() not invoking reseeding got added in an unrelated commit, that then was recently reverted. So this adds that little comment snippet back.

---
 drivers/char/random.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/char/random.c +0 -0
index 1d7aac2a9600..82e37d7dd9f1 100644

drivers/char/random.c static void _warn_unseeded_randomness(const char *func_name, void *caller, void · line 231

Quoted 7 lines
drivers/char/random.c +1 -1
@@ -226,7 +226,7 @@ static void _warn_unseeded_randomness(const char *func_name, void *caller, void
  * into the given buffer or as a return value. This is equivalent to
  * a read from /dev/urandom. The integer family of functions may be
  * higher performance for one-off random integers, because they do a
- * bit of buffering.
+ * bit of buffering and do not invoke reseeding.
  *
  *********************************************************************/

Actually, that seems wrong, as all these functions may call _get_random_bytes(), which may invoke crng_make_state(), which may invoke crng_reseed(). And it might be worthwhile to clarify that it's only get_random_bytes() that does not do the bit of buffering.

Thanks,
Dominik

author maintainer
#2 lore raw

Hi Dominik,

Good point; might as well take this opportunity to firm up that wording. How about:

"... and do not invoke reseeding until the buffer is emptied."

Jason

#3 lore raw

Am Wed, Mar 23, 2022 at 01:45:22PM -0600 schrieb Jason A. Donenfeld:

Quoted 6 lines

Hi Dominik,

Good point; might as well take this opportunity to firm up that wording. How about:

"... and do not invoke reseeding until the buffer is emptied."

Yes, that sounds better. Though "integer family of functions" still sounds a bit ambiguous.

Thanks,
Dominik

author maintainer
#4 lore raw

PATCH v2 1/1 random: re-add removed comment about get_random_{u32,u64} reseeding

The comment about get_random_{u32,u64}() not invoking reseeding got added in an unrelated commit, that then was recently reverted by 0313bc278dac ("Revert "random: block in /dev/urandom""). So this adds that little comment snippet back, and improves the wording a bit too.

---
 drivers/char/random.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/char/random.c +4 -3
index 1d7aac2a9600..40107f8b9e9e 100644
@@ -224,9 +224,10 @@ static void _warn_unseeded_randomness(const char *func_name, void *caller, void
  *
  * These interfaces will return the requested number of random bytes
  * into the given buffer or as a return value. This is equivalent to
- * a read from /dev/urandom. The integer family of functions may be
- * higher performance for one-off random integers, because they do a
- * bit of buffering.
+ * a read from /dev/urandom. The u32, u64, int, and long family of
+ * functions may be higher performance for one-off random integers,
+ * because they do a bit of buffering and do not invoke reseeding
+ * until the buffer is emptied.
  *
  *********************************************************************/
 
Signature · 1 line
2.35.1
Reviewed-by on v2 1/1
#5 lore raw

Am Wed, Mar 23, 2022 at 02:10:18PM -0600 schrieb Jason A. Donenfeld:

Quoted 7 lines

The comment about get_random_{u32,u64}() not invoking reseeding got added in an unrelated commit, that then was recently reverted by 0313bc278dac ("Revert "random: block in /dev/urandom""). So this adds that little comment snippet back, and improves the wording a bit too.