public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* short read from /dev/urandom
@ 2005-01-14  4:54 Ulrich Drepper
  2005-01-14  5:56 ` David Wagner
                   ` (2 more replies)
  0 siblings, 3 replies; 16+ messages in thread
From: Ulrich Drepper @ 2005-01-14  4:54 UTC (permalink / raw)
  To: Theodore Ts'o, Linux Kernel

[-- Attachment #1: Type: text/plain, Size: 1308 bytes --]

The /dev/urandom device is advertised as always returning the requested 
number of bytes.  Yet, it fails to do this under some situations. 
Compile this

int main (void)
{
   alarm (100);
   char buf[32];
   int fd = open ("/dev/urandom", 0);
   while (1)
     if (read (fd, buf, sizeof buf) != sizeof (buf))
       abort ();
}

with

   gcc -o r r.c -g -O2 -pg


Note the -pg at the end to enable profiling.  Running this code fails 
for me after less than a second.

The relevant code in the kernel is this 
(drivers/char/random.c:extract_entropy)

         while (nbytes) {
                 /*
                  * Check if we need to break out or reschedule....
                  */
                 if ((flags & EXTRACT_ENTROPY_USER) && need_resched()) {
                         if (signal_pending(current)) {
                                 if (ret == 0)
                                         ret = -ERESTARTSYS;
                                 break;
                         }


Here the loop is left prematurely if a signal is pending.

One solution is to redefine the /dev/urandom interface.  The problem is 
that this will cause program to fail.  I know since I found this while 
debugging such a program.

-- 
➧ Ulrich Drepper ➧ Red Hat, Inc. ➧ 444 Castro St ➧ Mountain View, CA ❖

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 252 bytes --]

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

end of thread, other threads:[~2005-01-20 20:03 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-01-14  4:54 short read from /dev/urandom Ulrich Drepper
2005-01-14  5:56 ` David Wagner
2005-01-14  6:54   ` Ulrich Drepper
2005-01-14 19:55     ` David Wagner
2005-01-14 19:10 ` Theodore Ts'o
2005-01-14 21:04   ` Ulrich Drepper
2005-01-14 23:21     ` Theodore Ts'o
2005-01-15  2:36       ` H. Peter Anvin
2005-01-16  2:51         ` Matt Mackall
2005-01-16  3:18           ` H. Peter Anvin
2005-01-15  2:34     ` H. Peter Anvin
2005-01-19 15:48     ` Pavel Machek
2005-01-16  2:44 ` Matt Mackall
2005-01-16  3:58   ` Ulrich Drepper
2005-01-16  4:58     ` Matt Mackall
2005-01-16 13:23     ` Andries Brouwer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox