util-linux/libuuid/man
Samanta Navarro e4be3ee01d libuuid: check quality of random bytes
If a libuuid application is unable to access /dev/random or /dev/urandom
then uuid generation by uuid_generate falls back to uuid_generate_time.
This could happen in chroot or container environments.

The function ul_random_get_bytes from lib/randutils.c uses getrandom if
it is available. This could either mean that the libuuid application
skips good random bytes because the character special files do not exist
or the application trusts in good random bytes just because these files
are accessible but not necessarily usable, e.g. limit of open file
descriptors reached, lack of data, kernel without getrandom, etc.

This commit modifies ul_random_get_bytes to return an integer which
indicates if random bytes are of good quality (0) or not (1). Callers
can decide based on this information if they want to discard the random
bytes. Only libuuid checks the return value. I decided to return 1
instead of -1 because -1 feels more like an error, but weak random bytes
can be totally fine.

Another issue is that getrandom sets errno to specific values only in
case of an error, i.e. with return value -1. Set errno to 0 explicitly
if getrandom succeeds so we do not enter the fallback routine for
ENOSYS by mistake. I do not think that this is likely to happen, but it
really depends on possible wrapper function supplied by a C library.

Signed-off-by: Samanta Navarro <ferivoz@riseup.net>
2020-11-08 11:48:23 +00:00
..
.gitignore build-sys: use top-level directory for libuuid rather than shlibs/uuid 2011-06-09 21:54:05 +02:00
Makemodule.am build-sys: create static uuid_generate_*.3 files 2012-06-26 20:50:54 +02:00
uuid.3 Manual pages: order AUTHORS / COPYRIGHT / SEE ALSO / AVAILABILITY consistently 2020-05-22 10:25:49 +02:00
uuid_clear.3 Manual pages: order AUTHORS / COPYRIGHT / SEE ALSO / AVAILABILITY consistently 2020-05-22 10:25:49 +02:00
uuid_compare.3 Manual pages: order AUTHORS / COPYRIGHT / SEE ALSO / AVAILABILITY consistently 2020-05-22 10:25:49 +02:00
uuid_copy.3 Manual pages: order AUTHORS / COPYRIGHT / SEE ALSO / AVAILABILITY consistently 2020-05-22 10:25:49 +02:00
uuid_generate.3 libuuid: check quality of random bytes 2020-11-08 11:48:23 +00:00
uuid_generate_random.3 build-sys: create static uuid_generate_*.3 files 2012-06-26 20:50:54 +02:00
uuid_generate_time.3 build-sys: create static uuid_generate_*.3 files 2012-06-26 20:50:54 +02:00
uuid_generate_time_safe.3 build-sys: create static uuid_generate_*.3 files 2012-06-26 20:50:54 +02:00
uuid_is_null.3 Manual pages: order AUTHORS / COPYRIGHT / SEE ALSO / AVAILABILITY consistently 2020-05-22 10:25:49 +02:00
uuid_parse.3 Manual pages: order AUTHORS / COPYRIGHT / SEE ALSO / AVAILABILITY consistently 2020-05-22 10:25:49 +02:00
uuid_time.3 Manual pages: rename RETURN VALUES to RETURN VALUE 2020-05-22 10:25:54 +02:00
uuid_unparse.3 Manual pages: order AUTHORS / COPYRIGHT / SEE ALSO / AVAILABILITY consistently 2020-05-22 10:25:49 +02:00