From patchwork Fri Apr 28 09:51:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hou Wenlong X-Patchwork-Id: 88580 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp829931vqo; Fri, 28 Apr 2023 03:30:52 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7garmvUqNKw38DtmKe1pqDwawyuI627gvPL0hJfIIRGXNwuVvcOAguZsTXaZJR5E/WHrwb X-Received: by 2002:a05:6a00:22ca:b0:63b:5c82:e21a with SMTP id f10-20020a056a0022ca00b0063b5c82e21amr7748253pfj.1.1682677851668; Fri, 28 Apr 2023 03:30:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682677851; cv=none; d=google.com; s=arc-20160816; b=h2/zQ8prybFSza3wsZmCjIfkEoG3d/ftCZUUPDvt81uDyxbIYdmunrsh7xd8xkvUez pQjVbZUdJn4ejyT7f0SwvGwwrOoyQsh/NVHT57bEsz8RI2CmDCcATsu1yuQ24EaMdu14 VoehjUX2oPxYR1ZCaukv6wI+qIU1R8zzcMXqOucJijtIKtvObI4ijF9PfxHq+oBxEwXO 6AdUpVRg+avHo/AD9h7mVzd4K437a3fTUiUXaediJqdwv3hSTi8Utfz1G94a89c+wUeM AN2WeulLTOCfmzVwbG8h6DoysZqg+vXcegNmkoj2h7YBD4mXPtRTFEw1w+ptyVKMo8ES NHlw== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q16-20020aa79830000000b0063b86de9d22si21164110pfl.177.2023.04.28.03.30.38; Fri, 28 Apr 2023 03:30: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 S1345981AbjD1J7G (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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1764415611402407126?= X-GMAIL-MSGID: =?utf-8?q?1764415611402407126?= 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);