From d0b1ac2d42b728be592e5985596a1946f17d08cc Mon Sep 17 00:00:00 2001
From: "iliya.saroukha" <iliya.saroukhanian@etu.hesge.ch>
Date: Mon, 9 Dec 2024 10:55:58 +0100
Subject: [PATCH] fix: trying to allocate the size specified by the
 IA32_VMX_BASIC MSR

atm, the returned pointer isn't aligned to a 4KB boundary which is
problematic..
---
 proto/hypervisor.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/proto/hypervisor.c b/proto/hypervisor.c
index 7faf47b..fc44b49 100755
--- a/proto/hypervisor.c
+++ b/proto/hypervisor.c
@@ -23,7 +23,7 @@
 #define IA32_VMX_BASIC (0x480)
 
 #define VMCS_REVISION_ID (__rdmsr(IA32_VMX_BASIC) & 0x7fffffff)
-#define REGION_SIZE ((__rdmsr(IA32_VMX_BASIC) >> 32) & 0xfff)
+#define REGION_SIZE ((__rdmsr(IA32_VMX_BASIC) >> 32) & 0x1fff)
 
 // Appendix 8 p. 4'592 of Intel SDM
 #define IA32_VMX_CR0_FIXED0 (0x486)
@@ -118,7 +118,7 @@ static void restrictions_cr_msrs(void) {
 }
 
 static int vmxon_region_alloc(void) {
-    void *region = kzalloc(PAGE_SIZE, GFP_KERNEL);
+    void *region = kzalloc(REGION_SIZE, GFP_KERNEL);
 
     if (!region) {
         return -1;
@@ -178,7 +178,7 @@ static int my_init(void) {
     pr_debug("IA32_VMX_BASIC_MSR = 0x%llx\n", vmx_basic_msr);
 
     unsigned long size_to_alloc = REGION_SIZE;
-    pr_debug("Region size to allocate = 0x%lx\n", size_to_alloc);
+    pr_debug("Region size to allocate = %lu bytes\n", size_to_alloc);
 
     unsigned long vmcs_revision_id = VMCS_REVISION_ID;
     pr_debug("VMCS revision identifier = 0x%lx\n", vmcs_revision_id);
-- 
GitLab