git: dbbf3e3f37d6 - main - random(9): Restore historical [0, 2^31-1] output range and related man documention.
Lawrence Stewart
lstewart at FreeBSD.org
Wed Mar 24 05:17:01 UTC 2021
The branch main has been updated by lstewart:
URL: https://cgit.FreeBSD.org/src/commit/?id=dbbf3e3f37d67d3eae0931855f8b62b9b299b80a
commit dbbf3e3f37d67d3eae0931855f8b62b9b299b80a
Author: Lawrence Stewart <lstewart at FreeBSD.org>
AuthorDate: 2021-03-24 04:25:49 +0000
Commit: Lawrence Stewart <lstewart at FreeBSD.org>
CommitDate: 2021-03-24 05:14:58 +0000
random(9): Restore historical [0,2^31-1] output range and related man
documention.
Commit SVN r364219 / Git 8a0edc914ffd changed random(9) to be a shim around
prng32(9) and inadvertently caused random(9) to begin returning numbers in the
range [0,2^32-1] instead of [0,2^31-1], where the latter has been the documented
range for decades.
The increased output range has been identified as the source of numerous bugs in
code written against the historical output range e.g. ipfw "prob" rules and
stats(3) are known to be affected, and a non-exhaustive audit of the tree
identified other random(9) consumers which are also likely affected.
As random(9) is deprecated and slated for eventual removal in 14.0, consumers
should gradually be audited and migrated to prng(9).
Submitted by: Loic Prylli <lprylli at netflix.com>
Obtained from: Netflix
Reviewed by: cem, delphij, imp
MFC after: 1 day
MFC to: stable/13, releng/13.0
Differential Revision: https://reviews.freebsd.org/D29385
---
share/man/man9/random.9 | 25 ++++++++++++++-----------
sys/libkern/random.c | 2 +-
2 files changed, 15 insertions(+), 12 deletions(-)
diff --git a/share/man/man9/random.9 b/share/man/man9/random.9
index fb5f2156df16..1c5f962b1363 100644
--- a/share/man/man9/random.9
+++ b/share/man/man9/random.9
@@ -26,7 +26,7 @@
.\"
.\" $FreeBSD$
.\" "
-.Dd December 26, 2019
+.Dd March 22, 2021
.Dt RANDOM 9
.Os
.Sh NAME
@@ -132,17 +132,13 @@ If the function is interrupted before the random device is seeded, no data is
returned.
.Pp
The deprecated
-.Xr random 9
-function will produce a sequence of pseudorandom numbers using a similar weak
-linear congruential generator as
-.Xr rand 3
-(the 1988 Park-Miller LCG).
+.Fn random
+function will return a 31-bit value.
It is obsolete and scheduled to be removed in
-.Fx 13.0 .
-It is strongly advised that the
-.Xr random 9
-function not be used to generate random numbers.
-See
+.Fx 14.0 .
+Consider
+.Xr prng 9
+instead and see
.Sx SECURITY CONSIDERATIONS .
.Sh RETURN VALUES
The
@@ -167,6 +163,13 @@ the number of bytes placed in
.Fn read_random_uio
returns zero when successful,
otherwise an error code is returned.
+.Pp
+.Fn random
+returns numbers
+in the range from 0 to
+.if t 2\u\s731\s10\d\(mi1.
+.if n (2**31)\(mi1.
+
.Sh ERRORS
.Fn read_random_uio
may fail if:
diff --git a/sys/libkern/random.c b/sys/libkern/random.c
index 23a8887fa49b..0bdfbc168409 100644
--- a/sys/libkern/random.c
+++ b/sys/libkern/random.c
@@ -45,5 +45,5 @@ __FBSDID("$FreeBSD$");
u_long
random(void)
{
- return (prng32());
+ return (prng32() & 0x7fffffff);
}
More information about the dev-commits-src-all
mailing list