Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 5 May 2023 13:34:31 GMT
From:      =?utf-8?Q?Corvin=20K=C3=B6hne?= <corvink@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: b10e100d1696 - main - vmm: don't free unallocated memory
Message-ID:  <202305051334.345DYVG1031200@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by corvink:

URL: https://cgit.FreeBSD.org/src/commit/?id=b10e100d1696782cfebef09b5870dfc6d1b3217b

commit b10e100d1696782cfebef09b5870dfc6d1b3217b
Author:     Corvin Köhne <corvink@FreeBSD.org>
AuthorDate: 2023-05-05 06:36:20 +0000
Commit:     Corvin Köhne <corvink@FreeBSD.org>
CommitDate: 2023-05-05 13:34:00 +0000

    vmm: don't free unallocated memory
    
    If vmx or svm is disabled in BIOS or the device isn't supported by vmm,
    modinit won't allocate these state save areas. As kmem_free panics when
    passing a NULL pointer to it, loading the vmm kernel module causes a
    panic too.
    
    PR:                     271251
    Reviewed by:            markj
    Fixes:                  74ac712f72cfd6d7b3db3c9d3b72ccf2824aa183 ("vmm: Dynamically allocate a couple of per-CPU state save areas")
    MFC after:              1 week
    Sponsored by:           Beckhoff Automation GmbH & Co. KG
    Differential Revision:  https://reviews.freebsd.org/D39974
---
 sys/amd64/vmm/amd/svm.c   | 5 ++++-
 sys/amd64/vmm/intel/vmx.c | 4 +++-
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/sys/amd64/vmm/amd/svm.c b/sys/amd64/vmm/amd/svm.c
index 0af7342128f2..d295401a9043 100644
--- a/sys/amd64/vmm/amd/svm.c
+++ b/sys/amd64/vmm/amd/svm.c
@@ -166,7 +166,10 @@ svm_modcleanup(void)
 {
 
 	smp_rendezvous(NULL, svm_disable, NULL, NULL);
-	kmem_free(hsave, (mp_maxid + 1) * PAGE_SIZE);
+
+	if (hsave != NULL)
+		kmem_free(hsave, (mp_maxid + 1) * PAGE_SIZE);
+
 	return (0);
 }
 
diff --git a/sys/amd64/vmm/intel/vmx.c b/sys/amd64/vmm/intel/vmx.c
index 55ed5fdf1a00..8b8f8fe6cb25 100644
--- a/sys/amd64/vmm/intel/vmx.c
+++ b/sys/amd64/vmm/intel/vmx.c
@@ -619,7 +619,9 @@ vmx_modcleanup(void)
 		nmi_flush_l1d_sw = 0;
 
 	smp_rendezvous(NULL, vmx_disable, NULL, NULL);
-	kmem_free(vmxon_region, (mp_maxid + 1) * PAGE_SIZE);
+
+	if (vmxon_region != NULL)
+		kmem_free(vmxon_region, (mp_maxid + 1) * PAGE_SIZE);
 
 	return (0);
 }



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202305051334.345DYVG1031200>