qemu-server/PVE/QemuServer
Stefan Reiter 2cf61f33d9 fix #2264: add virtio-rng device
Allow a user to add a virtio-rng-pci (an emulated hardware random
number generator) to a VM with the rng0 setting. The setting is
version_guard()-ed.

Limit the selection of entropy source to one of three:
/dev/urandom (preferred): Non-blocking kernel entropy source
/dev/random: Blocking kernel source
/dev/hwrng: Hardware RNG on the host for passthrough

QEMU itself defaults to /dev/urandom (or the equivalent getrandom()
call) if no source file is given, but I don't fully trust that
behaviour to stay constant, considering the documentation [0] already
disagrees with the code [1], so let's always specify the file ourselves.

/dev/urandom is preferred, since it prevents host entropy starvation.
The quality of randomness is still good enough to emulate a hwrng, since
a) it's still seeded from the kernel's true entropy pool periodically
and b) it's mixed with true entropy in the guest as well.

Additionally, all sources about entropy predicition attacks I could find
mention that to predict /dev/urandom results, /dev/random has to be
accessed or manipulated in one way or the other - this is not possible
from a VM however, as the entropy we're talking about comes from the
*hosts* blocking pool.

More about the entropy and security implications of the non-blocking
interface in [2] and [3].

Note further that only one /dev/hwrng exists at any given time, if
multiple RNGs are available, only the one selected in
'/sys/devices/virtual/misc/hw_random/rng_current' will feed the file.
Selecting this is left as an exercise to the user, if at all required.

We limit the available entropy to 1 KiB/s by default, but allow the user
to override this. Interesting to note is that the limiter does not work
linearly, i.e. max_bytes=1024/period=1000 means that up to 1 KiB of data
becomes available on a 1000 millisecond timer, not that 1 KiB is
streamed to the guest over the course of one second - hence the
configurable period.

The default used here is the same as given in the QEMU documentation [0]
and has been verified to affect entropy availability in a guest by
measuring /dev/random throughput. 1 KiB/s is enough to avoid any
early-boot entropy shortages, and already has a significant impact on
/dev/random availability in the guest.

[0] https://wiki.qemu.org/Features/VirtIORNG
[1] https://git.qemu.org/?p=qemu.git;a=blob;f=crypto/random-platform.c;h=f92f96987d7d262047c7604b169a7fdf11236107;hb=HEAD
[2] https://lwn.net/Articles/261804/
[3] https://lwn.net/Articles/808575/

Signed-off-by: Stefan Reiter <s.reiter@proxmox.com>
2020-03-06 18:09:04 +01:00
..
Agent.pm fix #2612: allow input-data in guest exec and make command optional 2020-03-03 14:34:02 +01:00
Cloudinit.pm cloudinit: fix vm start hanging with disk on ZFS 2019-10-18 21:40:34 +02:00
CPUConfig.pm cpu models: add missing comma 2020-03-06 17:57:46 +01:00
Helpers.pm add new helper to calculate timeout based on vm config 2020-01-15 17:36:16 +01:00
ImportDisk.pm qm importdisk: tell user to what VM disk we actually imported 2019-10-29 19:11:21 +01:00
Machine.pm version_guard scsi drive count 2020-02-12 10:32:57 +01:00
Makefile Add CPUConfig file and migrate some helpers 2020-01-22 15:47:32 +01:00
Memory.pm refactor: create QemuServer::Monitor for high-level QMP access 2019-11-20 16:29:23 +01:00
Monitor.pm mon_cmd: add explicit return 2019-11-30 17:24:55 +01:00
OVF.pm Initial support for importing OVF virtual machines 2017-09-25 13:31:55 +02:00
PCI.pm fix #2264: add virtio-rng device 2020-03-06 18:09:04 +01:00
USB.pm usb: Add USB3 capabilities to Spice USB devices 2019-09-21 13:22:17 +02:00