On Thu, Nov 07, 2019 at 12:37:11PM +0100, Paolo Bonzini wrote: > On 07/11/19 11:25, Ard Biesheuvel wrote: > >> This looks problematic on QEMU. Entropy is a valuable resource, and > >> whatever resource SMM drivers depend on, should not be possible for e.g. > >> a 3rd party UEFI driver (or even for the runtime OS) to exhaust. > >> Therefore, it's not *only* the case that SMM drivers must not consume > >> EFI_RNG_PROTOCOL (which exists at a less critical privilege level, i.e. > >> outside of SMM/SMRAM), but also that SMM drivers must not depend on the > >> same piece of *hardware* that feeds EFI_RNG_PROTOCOL. > >> > > The typical model is to seed a DRBG [deterministic pseudorandom > > sequence generator] using a sufficient amount of high quality entropy. > > Once you have done that, it is rather hard to exhaust a DRBG - it is a > > mathematical construction that is designed to last for a long time (<= > > 2^48 invocations [not bytes] according to the NIST spec), after which > > it does not degrade although it may have generated so much output that > > its internal state may be inferred if you have captured enough of it > > (which is a rather theoretical issue IMHO) > > > > The problem is that using the output of a DRBG as a seed is > > non-trivial - the spec describes ways to do this, but wiring > > virtio-rng to a DRBG in the host and using its output to seed a DRBG > > in the guest is slighly problematic. > > > > So it seems to me that the correct way to model this is to make the > > host's true entropy source a shared resource like any other. > > > > Yes, I would make SMM use a cryptographic pseudo-random number generator > and seed it from virtio-rng from DXE, way before the OS starts and can > "attack" it. > > Once you've gotten a seed, you can create a CSPRNG with a stream cipher > such as ChaCha20, which is literally 30 lines of code.
If all we need is a one-time seed then virtio-rng is possibly overkill as that provides a continuous stream. Instead could QEMU read a few bytes from the host's /dev/urandom and pass it to EDK via fw_cfg, which can use it for the CSPRNG seed. EDK would have to erase the fw_cfg field to prevent the seed value leaking to the guest OS, but other than that its quite straightforward. Regards, Daniel -- |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|