Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp1876912rwr; Fri, 28 Apr 2023 03:08:52 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5noOP+iGSP0+oScjjOc+Mntc9z5eZmKKxcmV6RRfppE9QV+Aul8tYxfLGGZ1InuyDum5h2 X-Received: by 2002:a05:6a00:2daa:b0:641:3f5:5cba with SMTP id fb42-20020a056a002daa00b0064103f55cbamr6975121pfb.31.1682676531810; Fri, 28 Apr 2023 03:08:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682676531; cv=none; d=google.com; s=arc-20160816; b=wf5KB6MPrQGCap1Y0NaUh6AOQwKUgRD52hglnbgjMec4XtThddNTeo48E8Pgq6KMkT MO5DcMIEeSVNMtYIoymPrCbS3MaETYLWP64eNiOHQi6XWTKlkBHY29KBYxrIU6PZpRiy 7Gdjh5galdwfOfPJqDSs2U+gSmGhXcATycFg7ksW1dxDvCX4kdX7Haw7SiTVERLOx5IX a+c8NGu4V6dKdNWIzA1OYjNZEXUrZti5qYDaXfmIa7lZ1pgglnuWr0q1FMYxQ1FHSn9B 2qv9bPDmzZ+fXCDiTs1lG0sT16DtvJaROyzKs1msG0Ywg5F6TnIkg8tKeZv8WTJVtBKW 5LSg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=2G0tpcP99N5G1X+z1tzLiyViEOHuarLgNEBobLqxUiM=; b=SZGOGadGeLqqXJxN/QSetQHu7gUh7cSzd4G7boev/O7UzMXKzpivPtV+RzDGbdsmsf rFj+/b8KulOtY3Vc0F5Jf22NFQHdkLw4IqO3blcQktXH4JT8df72wJP7Br7MZGUfGa2g RagejaHG5bROyH21WW8R7cp1xBS4rjbhF/wk88wlPOCABEQITlJ9DB6dpevTEnHnOxVz BxK747i2IsgvoiY1iE+O+fk/nG6z/h3lE7z1atL90riZxI0JzMQMr768G+f7xkBsWreQ eFUQiC2MyPPdcPYGFNLxHWNxVRnQsS2Y6V1VHrbh5N7ZkjWKHEgCliqOxf4X8rqD1iIq wD4A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=antgroup.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a28-20020aa78e9c000000b0063d26262efasi21439876pfr.187.2023.04.28.03.08.37; Fri, 28 Apr 2023 03:08:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=antgroup.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345896AbjD1J7G (ORCPT + 99 others); Fri, 28 Apr 2023 05:59:06 -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: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 #include @@ -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