[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[RFC PATCH 5/5] x86/pvh: Enable memory KASLR


  • To: xen-devel@xxxxxxxxxxxxxxxxxxxx, x86@xxxxxxxxxx
  • From: Teddy Astie <teddy.astie@xxxxxxxxxx>
  • Date: Mon, 30 Nov 2026 15:36:50 +0100
  • Authentication-results: eu.smtp.expurgate.cloud; dkim=pass header.s=selector1 header.d=vates.tech header.i="@vates.tech" header.h="From:Subject:Date:Message-ID:To:Cc:MIME-Version:Content-Type:In-Reply-To:References:Feedback-ID"
  • Cc: Teddy Astie <teddy.astie@xxxxxxxxxx>, Juergen Gross <jgross@xxxxxxxx>, Boris Ostrovsky <boris.ostrovsky@xxxxxxxxxx>
  • Delivery-date: Mon, 30 Nov 2026 14:37:40 +0000
  • Feedback-id: default:8631fc262581453bbf619ec5b2062170:Sweego
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

PVH guests boot the uncompressed kernel directly, so nothing sets
KASLR_FLAG and memory randomization is never enabled, although the
regular setup_arch() path is used and works fine with it.

Set KASLR_FLAG in init_pvh_bootparams() unless "nokaslr" is passed on
the command line.

Tested as PVH domU (1G and 16G) with upstream Xen, with and without
"nokaslr".

Signed-off-by: Teddy Astie <teddy.astie@xxxxxxxxxx>
Assisted-by: LLM
---
CC: Juergen Gross <jgross@xxxxxxxx>
CC: Boris Ostrovsky <boris.ostrovsky@xxxxxxxxxx>

 arch/x86/platform/pvh/enlighten.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/arch/x86/platform/pvh/enlighten.c 
b/arch/x86/platform/pvh/enlighten.c
index 88632c661430..41057d42c92a 100644
--- a/arch/x86/platform/pvh/enlighten.c
+++ b/arch/x86/platform/pvh/enlighten.c
@@ -4,6 +4,7 @@
 #include <xen/hvc-console.h>
 
 #include <asm/bootparam.h>
+#include <asm/cmdline.h>
 #include <asm/io_apic.h>
 #include <asm/hypervisor.h>
 #include <asm/e820/api.h>
@@ -74,6 +75,16 @@ static void __init init_pvh_bootparams(bool xen_guest)
        pvh_bootparams.hdr.cmd_line_ptr =
                pvh_start_info.cmdline_paddr;
 
+       /*
+        * There is no decompressor to handle "nokaslr" and set KASLR_FLAG,
+        * do it here so that memory randomization is enabled.
+        */
+       if (IS_ENABLED(CONFIG_RANDOMIZE_MEMORY) &&
+           !(pvh_start_info.cmdline_paddr &&
+             cmdline_find_option_bool(__va(pvh_start_info.cmdline_paddr),
+                                      "nokaslr")))
+               pvh_bootparams.hdr.loadflags |= KASLR_FLAG;
+
        /* The first module is always ramdisk. */
        if (pvh_start_info.nr_modules) {
                struct hvm_modlist_entry *modaddr =
-- 
2.56.1



--
Teddy Astie | Vates XCP-ng Developer

XCP-ng & Xen Orchestra - Vates solutions

web: https://vates.tech

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.