waywardgeek / infnoise

The world's easiest TRNG to get right
Creative Commons Zero v1.0 Universal
732 stars 100 forks source link

Writing to /dev/random on newer Linux seems to be blocked forever #89

Closed psiegl closed 1 year ago

psiegl commented 4 years ago

It seems as if on a newer Linux (5.6.3), the following is blocked forever:

poll(&pfd, 1, -1); // waits until /dev/random is in usage

jaysonlarose commented 1 year ago

Yeah, I just ran an strace on the infnoise process that udev is spawning to supposedly seed /dev/random, and it just sits there like a dead fish.

ioctl(4</dev/bus/usb/001/025>, USBDEVFS_REAPURBNDELAY, 0x7fffe45d0ac8) = -1 EAGAIN (Resource temporarily unavailable)
pselect6(5, NULL, [4</dev/bus/usb/001/025>], NULL, {tv_sec=0, tv_nsec=1000000}, NULL) = 1 (out [4], left {tv_sec=0, tv_nsec=353417})
ioctl(4</dev/bus/usb/001/025>, USBDEVFS_REAPURBNDELAY, 0x7fffe45d0ac8) = 0
rt_sigaction(SIGTERM, {sa_handler=0x55bfdf00cd10, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f8a71a42520}, NULL, 8) = 0
rt_sigaction(SIGINT, {sa_handler=0x55bfdf00cd10, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f8a71a42520}, NULL, 8) = 0
ioctl(4</dev/bus/usb/001/025>, USBDEVFS_SUBMITURB, 0x7fffe45d0b20) = 0
ioctl(4</dev/bus/usb/001/025>, USBDEVFS_REAPURBNDELAY, 0x7fffe45d0ae8) = -1 EAGAIN (Resource temporarily unavailable)
pselect6(5, NULL, [4</dev/bus/usb/001/025>], NULL, {tv_sec=0, tv_nsec=1000000}, NULL) = 1 (out [4], left {tv_sec=0, tv_nsec=434592})
ioctl(4</dev/bus/usb/001/025>, USBDEVFS_REAPURBNDELAY, 0x7fffe45d0ae8) = 0
ioctl(4</dev/bus/usb/001/025>, USBDEVFS_SUBMITURB, 0x7fffe45d0af0) = 0
ioctl(4</dev/bus/usb/001/025>, USBDEVFS_REAPURBNDELAY, 0x7fffe45d0ab8) = -1 EAGAIN (Resource temporarily unavailable)
pselect6(5, NULL, [4</dev/bus/usb/001/025>], NULL, {tv_sec=0, tv_nsec=1000000}, NULL) = 1 (out [4], left {tv_sec=0, tv_nsec=436776})
ioctl(4</dev/bus/usb/001/025>, USBDEVFS_REAPURBNDELAY, 0x7fffe45d0ab8) = 0
ioctl(3</dev/random>, RNDGETENTCNT, [256]) = 0
poll([{fd=3</dev/random>, events=POLLOUT}], 1, -1

This original issue has been open since 2020, so am I correct in saying that this has been broken for 2 years?

glasspelican commented 1 year ago

Yes, linux kernel 5.6 drastically changed how random numbers are handled once the generator for /dev/random seeds, it nolonger blocks
https://lwn.net/Articles/808575/
https://www.phoronix.com/news/Linux-5.6-Random-Rework
it looks like the debian fork of rng-tools was updated to force feed random numbers every 60 seconds

manuel-domke commented 1 year ago

Indeed, the Linux kernels new approach for handling random numbers had/has significant impact on how we can interact with it.

For now, a new command line option -f has been added to allow configuring the frequency in which the entropy pool is written to. Default is 30 seconds.

jaysonlarose commented 1 year ago

Yes... I've since noticed this after opening this issue... it appears that everything I thought I knew about how the linux /dev/random system has changed while I wasn't looking.