bhyve: verify OpRegion size

If the OpRegion size doesn't match the size of our igd_opregion struct, it's
using a different layout than we're expecting. To avoid strange issues, we
should exit hard. If we see any devices in the field with a different OpRegion
size, we can analyse it and fix it accordingly.

Reviewed by:		markj
MFC after:		1 week
Sponsored by:		Beckhoff Automation GmbH & Co. KG
Differential Revision:	https://reviews.freebsd.org/D45335
This commit is contained in:
Corvin Köhne 2023-12-15 12:46:09 +01:00
parent 5e09c5a1ed
commit e425e601b9
No known key found for this signature in database
GPG key ID: D854DA56315E026A

View file

@ -222,6 +222,13 @@ gvt_d_setup_opregion(struct pci_devinst *const pi)
opregion->len = header->size * KB;
munmap(header, sizeof(*header));
if (opregion->len != sizeof(struct igd_opregion)) {
warnx("%s: Invalid OpRegion size of 0x%lx", __func__,
opregion->len);
close(memfd);
return (-1);
}
opregion->hva = mmap(NULL, opregion->len, PROT_READ, MAP_SHARED, memfd,
opregion->hpa);
if (opregion->hva == MAP_FAILED) {