]> Savannah Git Hosting - gnulib.git/commit
tempname: fix multithreading, ASLR leak etc.
authorPaul Eggert <eggert@cs.ucla.edu>
Mon, 22 Aug 2022 19:07:27 +0000 (12:07 -0700)
committerBruno Haible <bruno@clisp.org>
Wed, 31 Aug 2022 23:28:58 +0000 (01:28 +0200)
commit52fd4af5a646e48765bcf2dc87d11530b2aa6bec
treebfb9ff53769e23b03b349aa03bb67cee2e6d1573
parente0a0558da767b8fd64ac9e031d61d9e03a39ddd4
tempname: fix multithreading, ASLR leak etc.

Fix problems with tempname and multithreading, entropy loss,
and missing clock data (this last on non-GNU platforms).
See analysis by Bruno Haible in:
https://bugs.gnu.org/57129#149
While looking into this, I noticed that tempname can leak
info derived from ASLR into publicly-visible file names,
which is a no-no.  Fix that too.
* lib/tempname.c: Don't include stdalign.h.
(HAS_CLOCK_ENTROPY): Remove.
(mix_random_values): New function.
(random_bits): Use it.  Args are now new value address and
old value, and this function now returns a success indicator.
Omit old USE_GETRANDOM argument: always try getrandom now, as
there is no good reason not to now that GRND_NONBLOCK is used.
Caller changed.  Use CLOCK_REALTIME for for ersatz entropy,
as CLOCK_MONOTONIC doesn't work on some platforms.
Also, mix in ersatz entropy from tv_sec and from clock ().
(try_tempname_len): Do not mix in ASLR-based entropy, as
the result is published to the world and ASLR should be private.
Do not try to use a static var as that has issues if multithreaded.
Instead, simply generate new random bits.
Worry about bias only with high-quality random bits.
* modules/tempname (Depends-on): Do not depend on stdalign.
ChangeLog
lib/tempname.c
modules/tempname