]> 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>
Thu, 1 Sep 2022 12:14:57 +0000 (14:14 +0200)
commit67835adbeeb9712cacc32ad3412c83c15df72b20
tree55928a7e488b1cafa11076d58d4c3506a5786dd6
parentf619d774ccb5ea5c993baa48b28cf3e994cd759e
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