All of lore.kernel.org
 help / color / mirror / Atom feed
* [uml-devel] /dev/random oddity
@ 2004-03-13  1:49 Thomas Schwinge
  2004-03-13 13:17 ` Sven 'Darkman' Michels
  0 siblings, 1 reply; 8+ messages in thread
From: Thomas Schwinge @ 2004-03-13  1:49 UTC (permalink / raw)
  To: user-mode-linux-devel

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

Hello again!

Could you please try to compile and execute the attached file?
It's part of skalibs <URL:http://www.skarnet.org/software/skalibs/> and
is used to check if /dev/random is working correctly.

On a native Linux system this is no problem:
#v+
thomas@speedy:~/tmp > gcc -o trydevr trydevr.c 
thomas@speedy:~/tmp > strace ./trydevr
execve("./trydevr", ["./trydevr"], [/* 59 vars */]) = 0
[...]
open("/dev/random", O_RDONLY)           = 3
read(3, "\26\3239Q^\327\246\373\f\250c\5\333W\311\266\237m\\\231"..., 64) = 64
close(3)                                = 0
open("/dev/random", O_RDONLY)           = 3
read(3, "\276Hj=W\311\237:\200F\1\262Z\266c\313\346k\202_\3348\317"..., 64) = 64
close(3)                                = 0
exit_group(0)                           = ?
#v-

Whereas on UML it is:
#v+
thomas@uml:~/tmp > gcc -o trydevr trydevr.c 
thomas@uml:~/tmp > strace ./trydevr
execve("./trydevr", ["./trydevr"], [/* 55 vars */]) = 0
[...]
open("/dev/random", O_RDONLY)           = 3
read(3, "\274\202\216\375\350\"\207W\221Y4Q\345QW\250\345\361 \305"..., 64) = 21
read(3, [hangs here]
#v-

The program is only able to read 21 bytes from /dev/random; sometimes
it's not even able to read anything at all.


#v+
thomas@uml:~ > cat /dev/random | sed 's|.|*|g'
#v-
does not return anything.

#v+
thomas@speedy:~ > cat /dev/random | sed 's|.|*|g'
#v-
returns a lot of '*' and then stops to refill until the kernel has
refilled it's entropy pool (see drivers/char/random.c) - refilling
happens by gathering random events e.g. interrupts - moving the mouse
or keeping a key pressed as examples.
/dev/random only returns random numbers from the entropy pool whereas
/dev/urandom also returns 'weak' (calculated) random numbers.
On UML the entropy pool seems never to be refilled - not matter how long
I keep a key pressed; I don't have a mouse there - so AFAICT /dev/random
stops working at the time the pool gets empty.

Might this be the problem?


UML is linux-2.6.4 with uml-patch-2.6.4-1 and
<URL:http://www.metaparadigm.com/~mclark/uml/uml-2.6.3-skas-1.patch>.


Regards,
 Thomas

[-- Attachment #2: trydevr.c --]
[-- Type: text/plain, Size: 1151 bytes --]

/* Public domain. */

#include <unistd.h>
#include <sys/types.h>
#include <fcntl.h>
#include <errno.h>

static int fd_read (int fd, char *buf, unsigned int len)
{
  register int r ;
  do r = read(fd, buf, len) ;
  while ((r == -1) && (errno == EINTR)) ;
  return r ;
}

static unsigned int allread (int fd, register char *buf, register unsigned int len)
{
  register unsigned int written = 0 ;
  while (len)
  {
    register int w = fd_read(fd, buf, len) ;
    if (!w) errno = EPIPE ;
    if (w <= 0) break ;
    written += w ;
    buf += w ;
    len -= w ;
  }
  return written ;
}

static int byte_diff (char *s, unsigned int n, char *t)
{
  for (;;)
  {
    if (!n) return 0 ;
    if (*s != *t) break ;
    ++s ; ++t ; --n ;
  }
  return ((int)(unsigned int)(unsigned char) *s)
       - ((int)(unsigned int)(unsigned char) *t);
}

int main ()
{
  char a[64] ;
  char b[64] ;
  int fd ;
  fd = open("/dev/random", O_RDONLY) ;
  if ((fd == -1) || (allread(fd, a, 64) < 64) ) return 111 ;
  close(fd) ;
  fd = open("/dev/random", O_RDONLY) ;
  if ((fd == -1) || (allread(fd, b, 64) < 64) ) return 111 ;
  close(fd) ;
  return !byte_diff(a, 64, b) ;
}

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

end of thread, other threads:[~2004-03-18 18:59 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-03-13  1:49 [uml-devel] /dev/random oddity Thomas Schwinge
2004-03-13 13:17 ` Sven 'Darkman' Michels
2004-03-13 15:12   ` Stephen D. Williams
2004-03-14 22:40     ` Matt Zimmerman
2004-03-15 19:37       ` Jeff Dike
     [not found]         ` <Pine.LNX.4.58.0403151422320.13832@gradall.private.brainfood.com>
2004-03-15 21:16           ` Jeff Dike
2004-03-18 19:06             ` BlaisorBlade
2004-03-15 19:41   ` Jeff Dike

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.