[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <2b9d5ec2452ad34418f3ddcd1e60c99dfb769909.1682673543.git.houwenlong.hwl@antgroup.com>
Date: Fri, 28 Apr 2023 17:51:21 +0800
From: "Hou Wenlong" <houwenlong.hwl@...group.com>
To: linux-kernel@...r.kernel.org
Cc: "Thomas Garnier" <thgarnie@...omium.org>,
"Lai Jiangshan" <jiangshan.ljs@...group.com>,
"Kees Cook" <keescook@...omium.org>,
"Hou Wenlong" <houwenlong.hwl@...group.com>,
"Dave Hansen" <dave.hansen@...ux.intel.com>,
"Andy Lutomirski" <luto@...nel.org>,
"Peter Zijlstra" <peterz@...radead.org>,
"Thomas Gleixner" <tglx@...utronix.de>,
"Ingo Molnar" <mingo@...hat.com>, "Borislav Petkov" <bp@...en8.de>,
<x86@...nel.org>, "H. Peter Anvin" <hpa@...or.com>
Subject: [PATCH RFC 41/43] x86/mm: Sort address_markers array when X86 PIE is enabled
When X86 PIE is enabled, kernel image is allowed to relocated in top
512G, then kernel image address could be below EFI range address. So
sort address_markers array to make the order right.
Signed-off-by: Hou Wenlong <houwenlong.hwl@...group.com>
Cc: Thomas Garnier <thgarnie@...omium.org>
Cc: Lai Jiangshan <jiangshan.ljs@...group.com>
Cc: Kees Cook <keescook@...omium.org>
---
arch/x86/mm/dump_pagetables.c | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)
diff --git a/arch/x86/mm/dump_pagetables.c b/arch/x86/mm/dump_pagetables.c
index df1a708a038a..81aa1c0b39cc 100644
--- a/arch/x86/mm/dump_pagetables.c
+++ b/arch/x86/mm/dump_pagetables.c
@@ -17,6 +17,7 @@
#include <linux/highmem.h>
#include <linux/pci.h>
#include <linux/ptdump.h>
+#include <linux/sort.h>
#include <asm/e820/types.h>
@@ -436,6 +437,27 @@ void ptdump_walk_pgd_level_checkwx(void)
ptdump_walk_pgd_level_core(NULL, &init_mm, INIT_PGD, true, false);
}
+#ifdef CONFIG_X86_PIE
+static int __init address_markers_sort_cmp(const void *pa, const void *pb)
+{
+ struct addr_marker *a = (struct addr_marker *)pa;
+ struct addr_marker *b = (struct addr_marker *)pb;
+
+ return (a->start_address > b->start_address) -
+ (a->start_address < b->start_address);
+}
+
+static void __init address_markers_sort(void)
+{
+ sort(&address_markers[0], ARRAY_SIZE(address_markers), sizeof(address_markers[0]),
+ address_markers_sort_cmp, NULL);
+}
+#else
+static void __init address_markers_sort(void)
+{
+}
+#endif
+
static int __init pt_dump_init(void)
{
/*
@@ -467,6 +489,8 @@ static int __init pt_dump_init(void)
address_markers[LDT_NR].start_address = LDT_BASE_ADDR;
# endif
#endif
+ address_markers_sort();
+
return 0;
}
__initcall(pt_dump_init);
--
2.31.1
Powered by blists - more mailing lists