From 19dbf72a270125621268e8b07ccc9ac99c67e7d0 Mon Sep 17 00:00:00 2001 From: Pierre Pronchery Date: Wed, 29 May 2024 20:00:02 +0200 Subject: [PATCH] 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 --- usr.sbin/bhyve/amd64/pci_gvt-d.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/usr.sbin/bhyve/amd64/pci_gvt-d.c b/usr.sbin/bhyve/amd64/pci_gvt-d.c index f64cc5984352..dfcd6a8f68c8 100644 --- a/usr.sbin/bhyve/amd64/pci_gvt-d.c +++ b/usr.sbin/bhyve/amd64/pci_gvt-d.c @@ -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);