From nobody Thu Feb 12 04:56:33 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 914C9C77B60 for ; Fri, 28 Apr 2023 09:59:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345889AbjD1J7H (ORCPT ); Fri, 28 Apr 2023 05:59:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37104 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346069AbjD1J6n (ORCPT ); Fri, 28 Apr 2023 05:58:43 -0400 Received: from out0-204.mail.aliyun.com (out0-204.mail.aliyun.com [140.205.0.204]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CF0896197 for ; Fri, 28 Apr 2023 02:58:03 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R201e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018047198;MF=houwenlong.hwl@antgroup.com;NM=1;PH=DS;RN=13;SR=0;TI=SMTPD_---.STDfsIh_1682675647; Received: from localhost(mailfrom:houwenlong.hwl@antgroup.com fp:SMTPD_---.STDfsIh_1682675647) by smtp.aliyun-inc.com; Fri, 28 Apr 2023 17:54:07 +0800 From: "Hou Wenlong" To: linux-kernel@vger.kernel.org Cc: "Thomas Garnier" , "Lai Jiangshan" , "Kees Cook" , "Hou Wenlong" , "Dave Hansen" , "Andy Lutomirski" , "Peter Zijlstra" , "Thomas Gleixner" , "Ingo Molnar" , "Borislav Petkov" , , "H. Peter Anvin" Subject: [PATCH RFC 41/43] x86/mm: Sort address_markers array when X86 PIE is enabled Date: Fri, 28 Apr 2023 17:51:21 +0800 Message-Id: <2b9d5ec2452ad34418f3ddcd1e60c99dfb769909.1682673543.git.houwenlong.hwl@antgroup.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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 Cc: Thomas Garnier Cc: Lai Jiangshan Cc: Kees Cook --- 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 #include #include +#include =20 #include =20 @@ -436,6 +437,27 @@ void ptdump_walk_pgd_level_checkwx(void) ptdump_walk_pgd_level_core(NULL, &init_mm, INIT_PGD, true, false); } =20 +#ifdef CONFIG_X86_PIE +static int __init address_markers_sort_cmp(const void *pa, const void *pb) +{ + struct addr_marker *a =3D (struct addr_marker *)pa; + struct addr_marker *b =3D (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_mar= kers[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 =3D LDT_BASE_ADDR; # endif #endif + address_markers_sort(); + return 0; } __initcall(pt_dump_init); --=20 2.31.1