New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve entropy collection in VMs #673

Open
marmarek opened this Issue Mar 8, 2015 · 20 comments

Comments

Projects
None yet
7 participants
@marmarek
Member

marmarek commented Mar 8, 2015

Reported by joanna on 15 Nov 2012 19:03 UTC
While this is only my feeling, I suspect that the entropy collection daemon in our VMs needs some improvements.. This is because of the limited interaction with the physical world of each VM (e.g. mouse events go via vchan instead of via kernel module in a VM).

This can be easily noticed when one tries to generate a new GPG key in a VM -- the gpg would complain about inadequate entropy that is available and will hang until more is produced. One can produce more entropy via various disk activities (e.g. grep through the filesystem), however this:

  1. Isn't very convenient
  2. It's questionable whether such entropy is of "first-class freshness", or is it somehow inferior to the entropy that could be collected with the help of mouse movements, etc.?

It would probably be desirable to create some entropy producing device that would run in each of the VMs, and to feed this device from Dom0 or other domains exposed to physical hardware (netvm, usbvm?). One should be careful, however, not to distribute the same "entropy bits" to more than one domain, as this would likely compromise domain isolation.

Migrated-From: https://wiki.qubes-os.org/ticket/673

@marmarek

This comment has been minimized.

Show comment
Hide comment
@marmarek

marmarek Mar 8, 2015

Member

Comment by joanna on 15 Nov 2012 23:25 UTC
Ok, I see two simple solutions:

  1. We run a set of daemons in Dom0 (one for each VM) that essentially do this in a loop:
read_a_chunk_of_bytes (/dev/ranomd);
send_bytes_to_VM(); // via qrexec
sleep (...) // let other read some Dom0's entropy also

Then, in the VM, there is a code that reads the transmitted bytes and sends them into the kernel's rng using the RNDADDENTROPY IOCTL on /dev/random:

http://git.kernel.org/?p=linux/kernel/git/stable/linux-stable.git;a=blob;f=drivers/char/random.c;h=b86eae9b77dfaeb04dd2d4efefd6ebc01b9e0a93;hb=HEAD#l1265

  1. We just enable haveged in each VM (it gathers entopry from measuring internal CPU state):

http://www.issihosts.com/haveged/index.html
http://www.irisa.fr/caps/projects/hipsor/

Note 1: haveged is incredibly fast! Just seem to be a bit TOO fast for me... So, I think I would feel better with the option #1 I think...

Note 2: Dom0 entropy seems pretty reasonable (thanks to mouse and keyboard!), so it's not unreasonable to share it among all the VMs. But perhaps we could allow to manually exclude some VMs from getting the entropy from Dom0 (e.g. those that are not very sensitive). E.g. I have almost 30 domains on my laptop, while there are maybe 4 only that are used for key generation and those are the only ones that need fresh entropy from Dom0.

Member

marmarek commented Mar 8, 2015

Comment by joanna on 15 Nov 2012 23:25 UTC
Ok, I see two simple solutions:

  1. We run a set of daemons in Dom0 (one for each VM) that essentially do this in a loop:
read_a_chunk_of_bytes (/dev/ranomd);
send_bytes_to_VM(); // via qrexec
sleep (...) // let other read some Dom0's entropy also

Then, in the VM, there is a code that reads the transmitted bytes and sends them into the kernel's rng using the RNDADDENTROPY IOCTL on /dev/random:

http://git.kernel.org/?p=linux/kernel/git/stable/linux-stable.git;a=blob;f=drivers/char/random.c;h=b86eae9b77dfaeb04dd2d4efefd6ebc01b9e0a93;hb=HEAD#l1265

  1. We just enable haveged in each VM (it gathers entopry from measuring internal CPU state):

http://www.issihosts.com/haveged/index.html
http://www.irisa.fr/caps/projects/hipsor/

Note 1: haveged is incredibly fast! Just seem to be a bit TOO fast for me... So, I think I would feel better with the option #1 I think...

Note 2: Dom0 entropy seems pretty reasonable (thanks to mouse and keyboard!), so it's not unreasonable to share it among all the VMs. But perhaps we could allow to manually exclude some VMs from getting the entropy from Dom0 (e.g. those that are not very sensitive). E.g. I have almost 30 domains on my laptop, while there are maybe 4 only that are used for key generation and those are the only ones that need fresh entropy from Dom0.

@marmarek

This comment has been minimized.

Show comment
Hide comment
@marmarek

marmarek Mar 8, 2015

Member

Comment by joanna on 21 Nov 2012 10:25 UTC
Some comments are in this thread:

https://groups.google.com/group/qubes-devel/browse_thread/thread/e7023cca06daa219

Member

marmarek commented Mar 8, 2015

Comment by joanna on 21 Nov 2012 10:25 UTC
Some comments are in this thread:

https://groups.google.com/group/qubes-devel/browse_thread/thread/e7023cca06daa219

@marmarek

This comment has been minimized.

Show comment
Hide comment
@marmarek

marmarek Mar 8, 2015

Member

Modified by joanna on 8 Feb 2013 12:59 UTC

Member

marmarek commented Mar 8, 2015

Modified by joanna on 8 Feb 2013 12:59 UTC

@marmarek

This comment has been minimized.

Show comment
Hide comment
@marmarek

marmarek Mar 8, 2015

Member

Modified by joanna on 30 Aug 2013 17:21 UTC

Member

marmarek commented Mar 8, 2015

Modified by joanna on 30 Aug 2013 17:21 UTC

@marmarek marmarek modified the milestones: Release 3, Release 2 Beta 3 Mar 8, 2015

@marmarek

This comment has been minimized.

Show comment
Hide comment
@marmarek

marmarek Mar 8, 2015

Member

Modified by joanna on 20 Apr 2014 17:04 UTC

Member

marmarek commented Mar 8, 2015

Modified by joanna on 20 Apr 2014 17:04 UTC

@marmarek marmarek modified the milestones: Release 2.1 (post R2), Release 3 Mar 8, 2015

@marmarek

This comment has been minimized.

Show comment
Hide comment
@marmarek

marmarek Mar 8, 2015

Member

Comment by joanna on 3 Jul 2014 12:07 UTC
For now (R2 release) we should just ensure haveged in the default template, I think.

Member

marmarek commented Mar 8, 2015

Comment by joanna on 3 Jul 2014 12:07 UTC
For now (R2 release) we should just ensure haveged in the default template, I think.

@marmarek marmarek modified the milestones: Release 2, Release 2.1 (post R2) Mar 8, 2015

@marmarek

This comment has been minimized.

Show comment
Hide comment
@marmarek

marmarek Mar 8, 2015

Member

Comment by marmarek on 4 Jul 2014 02:45 UTC
Why this can't be the final solution? I don't believe we ever implement any other solution for this...

Also - do we want to cover by this fix also updates to template (which would mean hard dependency on haveged from qubes-core-vm)? Or installing it in new templates would be enough (so on R2 ISO)?

Member

marmarek commented Mar 8, 2015

Comment by marmarek on 4 Jul 2014 02:45 UTC
Why this can't be the final solution? I don't believe we ever implement any other solution for this...

Also - do we want to cover by this fix also updates to template (which would mean hard dependency on haveged from qubes-core-vm)? Or installing it in new templates would be enough (so on R2 ISO)?

@marmarek

This comment has been minimized.

Show comment
Hide comment
@marmarek

marmarek Mar 8, 2015

Member

Comment by joanna on 4 Jul 2014 09:37 UTC
I think just the new template, no need to issue updates. This is no a security problem, rather a usability -- i.e. if read() on /dev/random hangs, it's an annoyance to the user.

I agree to closing this ticket with haveged.

Member

marmarek commented Mar 8, 2015

Comment by joanna on 4 Jul 2014 09:37 UTC
I think just the new template, no need to issue updates. This is no a security problem, rather a usability -- i.e. if read() on /dev/random hangs, it's an annoyance to the user.

I agree to closing this ticket with haveged.

@marmarek

This comment has been minimized.

Show comment
Hide comment

@marmarek marmarek closed this Mar 8, 2015

@adrelanos

This comment has been minimized.

Show comment
Hide comment
@adrelanos

adrelanos Jun 3, 2015

Member

From https://wiki.archlinux.org/index.php/Haveged#Virtual_Machines

As discussed at Is it appropriate to use haveged as a source of entropy on virtual machines?, it can be contested whether haveged provides quality entropy within a virtual environment.


It's not as simple as writing to /dev/random. From man random(4)

This differs from writing to /dev/random or /dev/urandom, which only adds some data but does not increment the entropy count. The following structure is used:


Looks like this could be implemented by reading from /dev/random and forwarding that entropy qrexec, ioctl(2), RNDADDENTROPY to VMs.

Member

adrelanos commented Jun 3, 2015

From https://wiki.archlinux.org/index.php/Haveged#Virtual_Machines

As discussed at Is it appropriate to use haveged as a source of entropy on virtual machines?, it can be contested whether haveged provides quality entropy within a virtual environment.


It's not as simple as writing to /dev/random. From man random(4)

This differs from writing to /dev/random or /dev/urandom, which only adds some data but does not increment the entropy count. The following structure is used:


Looks like this could be implemented by reading from /dev/random and forwarding that entropy qrexec, ioctl(2), RNDADDENTROPY to VMs.

@marmarek

This comment has been minimized.

Show comment
Hide comment
@marmarek

marmarek Jun 7, 2015

Member

Program attached there returns numbers between 10 and 100 (30-50 on my
system), so theoretically it means that VMs have access to real rdtsc.
This is on R3rc1 (Xen 4.4.2), not sure how about R2 (Xen 4.1.2). I'll
check Xen documentation later - I think I've seen some option for this.

Best Regards,
Marek Marczykowski-Górecki
Invisible Things Lab
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?

Member

marmarek commented Jun 7, 2015

Program attached there returns numbers between 10 and 100 (30-50 on my
system), so theoretically it means that VMs have access to real rdtsc.
This is on R3rc1 (Xen 4.4.2), not sure how about R2 (Xen 4.1.2). I'll
check Xen documentation later - I think I've seen some option for this.

Best Regards,
Marek Marczykowski-Górecki
Invisible Things Lab
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?

@adrelanos

This comment has been minimized.

Show comment
Hide comment

@mfc mfc added the crypto label May 22, 2016

@adrelanos

This comment has been minimized.

Show comment
Hide comment
@adrelanos

adrelanos Feb 5, 2018

Member

haveged is discouraged in VMs by Andre Seznec, one of haveged's main authors. Source:
BetterCrypto/Applied-Crypto-Hardening@cf7cef7#commitcomment-23006392

Entropy is needed before systemd / systemd-random-seed.service / haveged by the kernel (and possibly others, which is not researched). (Wrote a bit about that here #2704 (comment).)

Please reopen. @andrewdavidwong

Member

adrelanos commented Feb 5, 2018

haveged is discouraged in VMs by Andre Seznec, one of haveged's main authors. Source:
BetterCrypto/Applied-Crypto-Hardening@cf7cef7#commitcomment-23006392

Entropy is needed before systemd / systemd-random-seed.service / haveged by the kernel (and possibly others, which is not researched). (Wrote a bit about that here #2704 (comment).)

Please reopen. @andrewdavidwong

@andrewdavidwong

This comment has been minimized.

Show comment
Hide comment
@andrewdavidwong

andrewdavidwong Mar 18, 2018

Member

Relevant to this issue is the exchange between @rustybird and @adrelanos in #2704 that starts here.

Member

andrewdavidwong commented Mar 18, 2018

Relevant to this issue is the exchange between @rustybird and @adrelanos in #2704 that starts here.

@InnovativeInventor

This comment has been minimized.

Show comment
Hide comment
@InnovativeInventor

InnovativeInventor Apr 9, 2018

I think that it would be good to note that passing random data directly from dom0 to a vm is a bad idea. Linux's entropy pool is not designed to recover from pool compromise (source). This is a problem if we are seeding compromised vms with random data. Hashing/using a one-way function would protect other vms and dom0 if there is a bad vm receiving dom0's random data.

I think that it would be good to note that passing random data directly from dom0 to a vm is a bad idea. Linux's entropy pool is not designed to recover from pool compromise (source). This is a problem if we are seeding compromised vms with random data. Hashing/using a one-way function would protect other vms and dom0 if there is a bad vm receiving dom0's random data.

@v6ak

This comment has been minimized.

Show comment
Hide comment
@v6ak

v6ak Apr 10, 2018

v6ak commented Apr 10, 2018

@adrelanos

This comment has been minimized.

Show comment
Hide comment
@adrelanos

adrelanos May 19, 2018

Member

Since Qubes is using HVM and Qubes now, could we use VirtIO RNG?

https://wiki.qemu.org/Features/VirtIORNG


(As @HulaHoopWhonix suggested... Reworded by me...)

Member

adrelanos commented May 19, 2018

Since Qubes is using HVM and Qubes now, could we use VirtIO RNG?

https://wiki.qemu.org/Features/VirtIORNG


(As @HulaHoopWhonix suggested... Reworded by me...)

@v6ak

This comment has been minimized.

Show comment
Hide comment
@v6ak

v6ak May 19, 2018

v6ak commented May 19, 2018

@marmarek

This comment has been minimized.

Show comment
Hide comment
@marmarek

marmarek May 19, 2018

Member

It isn't, or at least it shouldn't be. Not leaking anything substantial about its internal state is a basic requirement of RNGs.

Regardless of actual state here, the current solution (seeding VM's RNG from dom0 as one of boot services) do hash random data extracted in dom0.

Member

marmarek commented May 19, 2018

It isn't, or at least it shouldn't be. Not leaking anything substantial about its internal state is a basic requirement of RNGs.

Regardless of actual state here, the current solution (seeding VM's RNG from dom0 as one of boot services) do hash random data extracted in dom0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment