bhyve: correctly remove a memory mapping

In a normal code path while setting up GPU passthrough, the size
parameter to munmap() is wrong and its operation not checked for errors,
therefore leaking resources.

Reported by:	Coverity Scan
CID:		1519830
Sponsored by:	The FreeBSD Foundation

Reviewed by: imp
Pull Request: https://github.com/freebsd/freebsd-src/pull/1262
This commit is contained in:
Pierre Pronchery 2024-05-29 20:00:02 +02:00 committed by Warner Losh
parent f13275cf03
commit 19dbf72a27

View file

@ -220,7 +220,7 @@ gvt_d_setup_opregion(struct pci_devinst *const pi)
opregion->hpa = asls;
opregion->len = header->size * KB;
munmap(header, sizeof(header));
munmap(header, sizeof(*header));
opregion->hva = mmap(NULL, opregion->len * KB, PROT_READ, MAP_SHARED,
memfd, opregion->hpa);