[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20230908102610.1039767-1-minipli@grsecurity.net>
Date: Fri, 8 Sep 2023 12:26:10 +0200
From: Mathias Krause <minipli@...ecurity.net>
To: linux-hyperv@...r.kernel.org
Cc: Mathias Krause <minipli@...ecurity.net>,
"K. Y. Srinivasan" <kys@...rosoft.com>,
Haiyang Zhang <haiyangz@...rosoft.com>,
Wei Liu <wei.liu@...nel.org>, Dexuan Cui <decui@...rosoft.com>,
linux-kernel@...r.kernel.org,
Saurabh Sengar <ssengar@...ux.microsoft.com>, stable@...nel.org
Subject: [PATCH] x86/hyperv/vtl: Replace real_mode_header only under Hyper-V
Booting a CONFIG_HYPERV_VTL_MODE=y enabled kernel on bare metal or a
non-Hyper-V hypervisor leads to serve memory corruption as
hv_vtl_early_init() will run even though hv_vtl_init_platform() did not.
This skips no-oping the 'realmode_reserve' and 'realmode_init' platform
hooks, making init_real_mode() -> setup_real_mode() try to copy
'real_mode_blob' over 'real_mode_header' which we set to the stub
'hv_vtl_real_mode_header'. However, as 'real_mode_blob' isn't just a
'struct real_mode_header' -- it's the complete code! -- copying it over
'hv_vtl_real_mode_header' will corrupt quite some memory following it.
The real cause for this erroneous behaviour is that hv_vtl_early_init()
blindly assumes the kernel is running on Hyper-V, which it may not.
Fix this by making sure the code only replaces the real mode header with
the stub one iff the kernel is running under Hyper-V.
Fixes: 3be1bc2fe9d2 ("x86/hyperv: VTL support for Hyper-V")
Cc: Saurabh Sengar <ssengar@...ux.microsoft.com>
Cc: stable@...nel.org
Signed-off-by: Mathias Krause <minipli@...ecurity.net>
---
arch/x86/hyperv/hv_vtl.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/arch/x86/hyperv/hv_vtl.c b/arch/x86/hyperv/hv_vtl.c
index 57df7821d66c..54c06f4b8b4c 100644
--- a/arch/x86/hyperv/hv_vtl.c
+++ b/arch/x86/hyperv/hv_vtl.c
@@ -12,6 +12,7 @@
#include <asm/desc.h>
#include <asm/i8259.h>
#include <asm/mshyperv.h>
+#include <asm/hypervisor.h>
#include <asm/realmode.h>
extern struct boot_params boot_params;
@@ -214,6 +215,9 @@ static int hv_vtl_wakeup_secondary_cpu(int apicid, unsigned long start_eip)
static int __init hv_vtl_early_init(void)
{
+ if (!hypervisor_is_type(X86_HYPER_MS_HYPERV))
+ return 0;
+
/*
* `boot_cpu_has` returns the runtime feature support,
* and here is the earliest it can be used.
--
2.30.2
Powered by blists - more mailing lists