Skip to content

Commit

Permalink
bhyve: verify OpRegion size
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ckoehne committed Jun 4, 2024
1 parent 5e09c5a commit e425e60
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions usr.sbin/bhyve/amd64/pci_gvt-d.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit e425e60

Please sign in to comment.