Index: head/sys/dev/random/fortuna.c =================================================================== --- head/sys/dev/random/fortuna.c +++ head/sys/dev/random/fortuna.c @@ -359,6 +359,13 @@ */ pl = event->he_destination % RANDOM_FORTUNA_NPOOLS; /* + * If a VM generation ID changes (clone and play or VM rewind), we want + * to incorporate that as soon as possible. Override destingation pool + * for immediate next use. + */ + if (event->he_source == RANDOM_PURE_VMGENID) + pl = 0; + /* * We ignore low entropy static/counter fields towards the end of the * he_event structure in order to increase measurable entropy when * conducting SP800-90B entropy analysis measurements of seed material Index: head/sys/dev/random/random_harvestq.c =================================================================== --- head/sys/dev/random/random_harvestq.c +++ head/sys/dev/random/random_harvestq.c @@ -354,6 +354,7 @@ [RANDOM_PURE_CCP] = "PURE_CCP", [RANDOM_PURE_DARN] = "PURE_DARN", [RANDOM_PURE_TPM] = "PURE_TPM", + [RANDOM_PURE_VMGENID] = "VMGENID", /* "ENTROPYSOURCE" */ }; Index: head/sys/dev/vmgenc/vmgenc_acpi.c =================================================================== --- head/sys/dev/vmgenc/vmgenc_acpi.c +++ head/sys/dev/vmgenc/vmgenc_acpi.c @@ -52,12 +52,14 @@ #include #include #include +#include #include #include #include #include +#include #include #ifndef ACPI_NOTIFY_STATUS_CHANGED @@ -80,6 +82,20 @@ }; static void +vmgenc_harvest_all(const void *p, size_t sz) +{ + size_t nbytes; + + while (sz > 0) { + nbytes = MIN(sz, + sizeof(((struct harvest_event *)0)->he_entropy)); + random_harvest_direct(p, nbytes, RANDOM_PURE_VMGENID); + p = (const char *)p + nbytes; + sz -= nbytes; + } +} + +static void vmgenc_status_changed(void *context) { uint8_t guid[GUID_BYTES]; @@ -97,6 +113,8 @@ /* Update cache. */ memcpy(sc->vmg_cache_guid, guid, GUID_BYTES); + vmgenc_harvest_all(sc->vmg_cache_guid, sizeof(sc->vmg_cache_guid)); + EVENTHANDLER_INVOKE(acpi_vmgenc_event); acpi_UserNotify("VMGenerationCounter", acpi_get_handle(dev), 0); } @@ -219,6 +237,9 @@ memcpy(sc->vmg_cache_guid, __DEVOLATILE(void *, sc->vmg_pguid), sizeof(sc->vmg_cache_guid)); + random_harvest_register_source(RANDOM_PURE_VMGENID); + vmgenc_harvest_all(sc->vmg_cache_guid, sizeof(sc->vmg_cache_guid)); + AcpiInstallNotifyHandler(h, ACPI_DEVICE_NOTIFY, vmgenc_notify, dev); return (0); } @@ -238,3 +259,4 @@ static devclass_t vmgenc_devclass; DRIVER_MODULE(vmgenc, acpi, vmgenc_driver, vmgenc_devclass, NULL, NULL); MODULE_DEPEND(vmgenc, acpi, 1, 1, 1); +MODULE_DEPEND(vemgenc, random_harvestq, 1, 1, 1); Index: head/sys/sys/random.h =================================================================== --- head/sys/sys/random.h +++ head/sys/sys/random.h @@ -102,6 +102,7 @@ RANDOM_PURE_CCP, RANDOM_PURE_DARN, RANDOM_PURE_TPM, + RANDOM_PURE_VMGENID, ENTROPYSOURCE }; _Static_assert(ENTROPYSOURCE <= 32,