public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libc/15813] New: Multiple issues in __gen_tempname
@ 2013-08-02  5:16 bugdal at aerifal dot cx
  2013-10-11 21:25 ` [Bug libc/15813] " neleai at seznam dot cz
                   ` (11 more replies)
  0 siblings, 12 replies; 13+ messages in thread
From: bugdal at aerifal dot cx @ 2013-08-02  5:16 UTC (permalink / raw)
  To: glibc-bugs

http://sourceware.org/bugzilla/show_bug.cgi?id=15813

            Bug ID: 15813
           Summary: Multiple issues in __gen_tempname
           Product: glibc
           Version: unspecified
            Status: NEW
          Severity: normal
          Priority: P2
         Component: libc
          Assignee: unassigned at sourceware dot org
          Reporter: bugdal at aerifal dot cx
                CC: drepper.fsp at gmail dot com

(1) Access to the static object value is unsynchronized, resulting in undefined
behavior. Undefined behavior is not desirable entropy.

(2) Low-resolution gettimeofday rather than high-resolution clock_gettime is
used as an entropy source.

(3) Entropy is only gathered once per run; subsequent attempts merely add 7777
to value, so that if an attacker can guess the initial temp name that will be
tried, the attacker can also guess all subsequent attempts for the same run.

Proposed solutions:

(1) Make value automatic. There is no value (pardon the pun) to keeping it
between runs.

(2) Use clock_gettime, possibly with multiple clocks (e.g. realtime and
cputime).

(3) Get new entropy on each attempt rather than adding the fixed value 7777.

-- 
You are receiving this mail because:
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug libc/15813] Multiple issues in __gen_tempname
  2013-08-02  5:16 [Bug libc/15813] New: Multiple issues in __gen_tempname bugdal at aerifal dot cx
@ 2013-10-11 21:25 ` neleai at seznam dot cz
  2013-10-11 21:29 ` bugdal at aerifal dot cx
                   ` (10 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: neleai at seznam dot cz @ 2013-10-11 21:25 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=15813

Ondrej Bilka <neleai at seznam dot cz> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |neleai at seznam dot cz
           Severity|normal                      |enhancement

--- Comment #1 from Ondrej Bilka <neleai at seznam dot cz> ---
I do not see how could attacker use __gen_tempname weakness, worst he could do
is dos/ cause mkxtemp to fail which should be handled correctly. If you want
this fixed write a patch.

keeping value is more entropic than calculating anew as entropy of sum of
uncorrelated variables is at least maximum of entropies of variables. Without
that we would call clock_gettime twice in quick succession which has almost
same entropy as calling it once.

As __gen_tempname call does disk access we can affort on linux just read 64bits
from /dev/urandom.

If attacker can guess that we have bigger worries than temporary files.

-- 
You are receiving this mail because:
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug libc/15813] Multiple issues in __gen_tempname
  2013-08-02  5:16 [Bug libc/15813] New: Multiple issues in __gen_tempname bugdal at aerifal dot cx
  2013-10-11 21:25 ` [Bug libc/15813] " neleai at seznam dot cz
@ 2013-10-11 21:29 ` bugdal at aerifal dot cx
  2014-06-13 13:16 ` fweimer at redhat dot com
                   ` (9 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: bugdal at aerifal dot cx @ 2013-10-11 21:29 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=15813

--- Comment #2 from Rich Felker <bugdal at aerifal dot cx> ---
Issue 1, the undefined behavior, is the most serious. All cases of UB should be
fixed; this should simply be a set-in-stone policy.

Issue 2 is low-priority, but switching to a higher-quality entropy source would
be the easiest way to solve issue 3 and would improve the quality of the
simplest solution to issue 1 (removing the static state).

Issue 3 is possibly an attack vector, but fairly low priority (DoS only).

-- 
You are receiving this mail because:
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug libc/15813] Multiple issues in __gen_tempname
  2013-08-02  5:16 [Bug libc/15813] New: Multiple issues in __gen_tempname bugdal at aerifal dot cx
  2013-10-11 21:25 ` [Bug libc/15813] " neleai at seznam dot cz
  2013-10-11 21:29 ` bugdal at aerifal dot cx
@ 2014-06-13 13:16 ` fweimer at redhat dot com
  2020-09-09  9:37 ` jakub at redhat dot com
                   ` (8 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: fweimer at redhat dot com @ 2014-06-13 13:16 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=15813

Florian Weimer <fweimer at redhat dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |fweimer at redhat dot com

-- 
You are receiving this mail because:
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug libc/15813] Multiple issues in __gen_tempname
  2013-08-02  5:16 [Bug libc/15813] New: Multiple issues in __gen_tempname bugdal at aerifal dot cx
                   ` (2 preceding siblings ...)
  2014-06-13 13:16 ` fweimer at redhat dot com
@ 2020-09-09  9:37 ` jakub at redhat dot com
  2020-09-09  9:51 ` jakub at redhat dot com
                   ` (7 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: jakub at redhat dot com @ 2020-09-09  9:37 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=15813

Jakub Jelinek <jakub at redhat dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|FIXED                       |---
                 CC|                            |jakub at redhat dot com

--- Comment #6 from Jakub Jelinek <jakub at redhat dot com> ---
(In reply to cvs-commit@gcc.gnu.org from comment #4)
> The master branch has been updated by Adhemerval Zanella
> <azanella@sourceware.org>:
> 
> https://sourceware.org/git/gitweb.cgi?p=glibc.git;
> h=e1df30fbc2e2167a982c0e77a7ebee28f4dd0800
> 
> commit e1df30fbc2e2167a982c0e77a7ebee28f4dd0800
> Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
> Date:   Thu Jul 25 11:22:17 2019 -0300
> 
>     Get new entropy on each attempt __gen_tempname (BZ #15813)
>     
>     This is missing bit for fully fix BZ#15813 (the other two were fixed
>     by 359653aaacad463).
>     
>     Checked on x86_64-linux-gnu.
>     
>     	[BZ #15813]
>     	sysdeps/posix/tempname.c (__gen_tempname): get entrypy on each
>     	attempt.

This change is completely broken.
As random_bits is defined as:
static inline uint32_t
random_bits (void)
{
  struct __timespec64 tv;
  __clock_gettime64 (CLOCK_MONOTONIC, &tv);
  /* Shuffle the lower bits to minimize the clock bias.  */
  uint32_t ret = tv.tv_nsec ^ tv.tv_sec;
  ret ^= (ret << 24) | (ret >> 8);
  return ret;
}
on a fast machine instead of making sure that in the loop the value is even
more random it makes sure that each attempt uses the exact same value, which it
knows from the earlier attempt that it exists already.
So, either it needs to ensure the entropy source is not imprecise time based,
or it needs e.g. add to the initial value in each iteration rather than use the
same value.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug libc/15813] Multiple issues in __gen_tempname
  2013-08-02  5:16 [Bug libc/15813] New: Multiple issues in __gen_tempname bugdal at aerifal dot cx
                   ` (3 preceding siblings ...)
  2020-09-09  9:37 ` jakub at redhat dot com
@ 2020-09-09  9:51 ` jakub at redhat dot com
  2020-09-09 12:19 ` adhemerval.zanella at linaro dot org
                   ` (6 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: jakub at redhat dot com @ 2020-09-09  9:51 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=15813

--- Comment #7 from Jakub Jelinek <jakub at redhat dot com> ---
Perhaps upon the first EEXIST it could getrandom (with GRND_NONBLOCK) and from
that decide the addend to be used instead of 7777 and use RANDOM_BITS only
before the loop as the base?  The code should make sure the addend isn't
something like 0 or that would cause only very few possibilities in the TMP_MAX
attempts.  And/or the addend could change every few hundred attempts.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug libc/15813] Multiple issues in __gen_tempname
  2013-08-02  5:16 [Bug libc/15813] New: Multiple issues in __gen_tempname bugdal at aerifal dot cx
                   ` (4 preceding siblings ...)
  2020-09-09  9:51 ` jakub at redhat dot com
@ 2020-09-09 12:19 ` adhemerval.zanella at linaro dot org
  2020-09-09 12:35 ` kdudka at redhat dot com
                   ` (5 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: adhemerval.zanella at linaro dot org @ 2020-09-09 12:19 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=15813

--- Comment #8 from Adhemerval Zanella <adhemerval.zanella at linaro dot org> ---
(In reply to Jakub Jelinek from comment #7)
> Perhaps upon the first EEXIST it could getrandom (with GRND_NONBLOCK) and
> from that decide the addend to be used instead of 7777 and use RANDOM_BITS
> only before the loop as the base?  The code should make sure the addend
> isn't something like 0 or that would cause only very few possibilities in
> the TMP_MAX attempts.  And/or the addend could change every few hundred
> attempts.

I am more inclined to sync with latest gnulib implementation and just remove
the RANDOM_BITS part which is used only for _LIBC.  This makes the
implementation to use getrandom or it fallbacks to a 64-bit linear congruential
generator.

The fallback will be always used on kernels older than 3.17 (due missing
__NR_getrandom support) and I am wondering if it is worth to implement the
fallback to read the random device (as Hurd implementation).

Also, the gnulib fallback relies on UB (the linear congruential generator uses
the unitialized value a stack variable), so I think it would be better to fix
it as well.  A simple solution might to initialize the variable to its own
address.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug libc/15813] Multiple issues in __gen_tempname
  2013-08-02  5:16 [Bug libc/15813] New: Multiple issues in __gen_tempname bugdal at aerifal dot cx
                   ` (5 preceding siblings ...)
  2020-09-09 12:19 ` adhemerval.zanella at linaro dot org
@ 2020-09-09 12:35 ` kdudka at redhat dot com
  2020-09-09 12:44 ` jakub at redhat dot com
                   ` (4 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: kdudka at redhat dot com @ 2020-09-09 12:35 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=15813

Kamil Dudka <kdudka at redhat dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |kdudka at redhat dot com

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug libc/15813] Multiple issues in __gen_tempname
  2013-08-02  5:16 [Bug libc/15813] New: Multiple issues in __gen_tempname bugdal at aerifal dot cx
                   ` (6 preceding siblings ...)
  2020-09-09 12:35 ` kdudka at redhat dot com
@ 2020-09-09 12:44 ` jakub at redhat dot com
  2020-09-09 13:30 ` adhemerval.zanella at linaro dot org
                   ` (3 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: jakub at redhat dot com @ 2020-09-09 12:44 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=15813

--- Comment #9 from Jakub Jelinek <jakub at redhat dot com> ---
The non-_LIBC fallback is actually worse (gettimeofday with usec precision).
Anyway, I think the usec timer with pid is just fine for the first attempt, so
reading from /dev/urandom or using similar syscall is I think a waste of time
for the common case, it is just in the unlikely case that the file exists that
perhaps something more expensive is needed.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug libc/15813] Multiple issues in __gen_tempname
  2013-08-02  5:16 [Bug libc/15813] New: Multiple issues in __gen_tempname bugdal at aerifal dot cx
                   ` (7 preceding siblings ...)
  2020-09-09 12:44 ` jakub at redhat dot com
@ 2020-09-09 13:30 ` adhemerval.zanella at linaro dot org
  2020-09-15 13:38 ` carlos at redhat dot com
                   ` (2 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: adhemerval.zanella at linaro dot org @ 2020-09-09 13:30 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=15813

--- Comment #10 from Adhemerval Zanella <adhemerval.zanella at linaro dot org> ---
I meant the updated gnulib version from its repository, not the outdated
version glibc packs now.  The gnulib version currently does not use neither the
process pid nor the clock for source of entropy, it uses either getrandom or a
simple linear congruential generator if getrandom fails.

I think using getentropy where available should make it more robust. These
interface contains inherent concurrent issues and applications should either
use O_TMPFILE or at leat tmpfile.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug libc/15813] Multiple issues in __gen_tempname
  2013-08-02  5:16 [Bug libc/15813] New: Multiple issues in __gen_tempname bugdal at aerifal dot cx
                   ` (8 preceding siblings ...)
  2020-09-09 13:30 ` adhemerval.zanella at linaro dot org
@ 2020-09-15 13:38 ` carlos at redhat dot com
  2020-09-22 13:14 ` fweimer at redhat dot com
  2020-09-22 13:15 ` fweimer at redhat dot com
  11 siblings, 0 replies; 13+ messages in thread
From: carlos at redhat dot com @ 2020-09-15 13:38 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=15813

--- Comment #11 from Carlos O'Donell <carlos at redhat dot com> ---
(In reply to Adhemerval Zanella from comment #10)
> I meant the updated gnulib version from its repository, not the outdated
> version glibc packs now.  The gnulib version currently does not use neither
> the process pid nor the clock for source of entropy, it uses either
> getrandom or a simple linear congruential generator if getrandom fails.
> 
> I think using getentropy where available should make it more robust. These
> interface contains inherent concurrent issues and applications should either
> use O_TMPFILE or at leat tmpfile.

We should backport this to the release branch also since this is a regression.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug libc/15813] Multiple issues in __gen_tempname
  2013-08-02  5:16 [Bug libc/15813] New: Multiple issues in __gen_tempname bugdal at aerifal dot cx
                   ` (9 preceding siblings ...)
  2020-09-15 13:38 ` carlos at redhat dot com
@ 2020-09-22 13:14 ` fweimer at redhat dot com
  2020-09-22 13:15 ` fweimer at redhat dot com
  11 siblings, 0 replies; 13+ messages in thread
From: fweimer at redhat dot com @ 2020-09-22 13:14 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=15813

Florian Weimer <fweimer at redhat dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://sourceware.org/bugz
                   |                            |illa/show_bug.cgi?id=26648

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug libc/15813] Multiple issues in __gen_tempname
  2013-08-02  5:16 [Bug libc/15813] New: Multiple issues in __gen_tempname bugdal at aerifal dot cx
                   ` (10 preceding siblings ...)
  2020-09-22 13:14 ` fweimer at redhat dot com
@ 2020-09-22 13:15 ` fweimer at redhat dot com
  11 siblings, 0 replies; 13+ messages in thread
From: fweimer at redhat dot com @ 2020-09-22 13:15 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=15813

Florian Weimer <fweimer at redhat dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|REOPENED                    |RESOLVED
         Resolution|---                         |FIXED

--- Comment #12 from Florian Weimer <fweimer at redhat dot com> ---
I filed bug 26648 for the regression.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2020-09-22 13:15 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-08-02  5:16 [Bug libc/15813] New: Multiple issues in __gen_tempname bugdal at aerifal dot cx
2013-10-11 21:25 ` [Bug libc/15813] " neleai at seznam dot cz
2013-10-11 21:29 ` bugdal at aerifal dot cx
2014-06-13 13:16 ` fweimer at redhat dot com
2020-09-09  9:37 ` jakub at redhat dot com
2020-09-09  9:51 ` jakub at redhat dot com
2020-09-09 12:19 ` adhemerval.zanella at linaro dot org
2020-09-09 12:35 ` kdudka at redhat dot com
2020-09-09 12:44 ` jakub at redhat dot com
2020-09-09 13:30 ` adhemerval.zanella at linaro dot org
2020-09-15 13:38 ` carlos at redhat dot com
2020-09-22 13:14 ` fweimer at redhat dot com
2020-09-22 13:15 ` fweimer at redhat dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).