jirka-h / haveged

Entropy daemon ![Continuous Integration](https://github.com/jirka-h/haveged/workflows/Continuous%20Integration/badge.svg)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Very low entropy in the /proc/sys/kernel files haveged uses

ThePythonicCow opened this issue · comments

When I looked to see what files haveged uses, besides /dev/random, to obtain some entropy, I find that the files used are:

/proc/sys/kernel/osrelease
/proc/sys/kernel/random/poolsize
/proc/sys/kernel/random/write_wakeup_threshold

When I look at those three /proc/sys/kernel files, I find that they have very low entropy. They are small (one line) text files recording what look to be three parameters, one per file, that seem to be constant at least for each boot, if not for the entire life of a particular hardware and kernel configuration:

The command:

head /proc/sys/kernel/{osrelease,random/poolsize,random/write_wakeup_threshold}

produces, on my Ryzen 1700 box:

==> /proc/sys/kernel/osrelease <==
5.4.0-100-generic

==> /proc/sys/kernel/random/poolsize <==
4096

==> /proc/sys/kernel/random/write_wakeup_threshold <==
1024

I have been experimenting, on my Ubuntu LTS 20.04 system, with various /proc files, and so far I am finding much more apparent entropy in the following files:

/proc/self/{sched,stat,status}

Reading these three files produces over 3000 bytes of output on my system right now, and the output varies every time I read them, as might be expected from what they purport to show. These files are also quick to read, taking less than 0.01 seconds total to read all three of them on my system.

Wouldn't it make more sense for haveged to use these three /proc/self files? Reading the same /proc/sys/kernel files over and over again, to get the same, short, low entropy results seems like a waste of time and a poor basis for obtaining random entropy.

Hi Paul,

I think there is a misunderstanding. The files {osrelease,random/poolsize,random/write_wakeup_threshold} are not used to generate/seed the entropy at all.

Haveged is using these files to determine if it should send entropy to the kernel and how many bytes. For more details, please see man -S4 random. In the source code, please check for example function get_poolsize

static int get_poolsize( /* RETURN: number of bits */

or set_watermark:

* Set random write threshold

I hope this clarifies the issue. Please let me know if you have more questions.

Thanks
Jirka

$man -S4 random
.....
   /proc interfaces
       The files in the directory /proc/sys/kernel/random (present since 2.3.16) provide additional information about the /dev/random device:

       entropy_avail
              This read-only file gives the available entropy, in bits.  This will be a number in the range 0 to 4096.

       poolsize
              This file gives the size of the entropy pool.  The semantics of this file vary across kernel versions:

              Linux 2.4:
                     This file gives the size of the entropy pool in bytes.  Normally, this file will have the value 512, but it is writable, and can be changed to any value for which an algorithm is available.  The  choices  are
                     32, 64, 128, 256, 512, 1024, or 2048.

              Linux 2.6 and later:
                     This file is read-only, and gives the size of the entropy pool in bits.  It contains the value 4096.

       read_wakeup_threshold
              This file contains the number of bits of entropy required for waking up processes that sleep waiting for entropy from /dev/random.  The default is 64.

       write_wakeup_threshold
              This file contains the number of bits of entropy below which we wake up processes that do a select(2) or poll(2) for write access to /dev/random.  These values can be changed by writing to the files.

I think there is a misunderstanding.

Right you are.

Thanks for the good explanation.

You are welcome!

I'm closing the ticket.