Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp1679044iob; Thu, 19 May 2022 11:47:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyHtH8wu2+ymzjv9ybhPCX2CHWO8OgdJUiGk4Pod8KKSJKV2T0gYQe3UYpVvJJzl7oXCESm X-Received: by 2002:a17:90a:c7c5:b0:1df:45ca:ef8b with SMTP id gf5-20020a17090ac7c500b001df45caef8bmr7271978pjb.15.1652986027973; Thu, 19 May 2022 11:47:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652986027; cv=none; d=google.com; s=arc-20160816; b=p2B1HnrzyOaf0OZ/ZnRpN16604dH4mJpJ9e/CUr86QkiIykDW9/EfI20jHbclWM9xD LrStLPaQM9qdqD9pOKlhscSf5juIbaPrRCwptB8ri0tJMFX5Ju0WGYzR3xPWgTo3VQkm Hs9U/83M+/wKusZdEKiMFk0j56kSLflFm23gYaWRsHKC7Scw+Hhug5Q70PBa+53L2aFg 6Zo2YSrl7S65N/9oTVknAXumRbR27JOEbkhSKqK6pTNFyXu5AwOAY66dxT9qVQa+1qKD KVDmp+6dBd8FXdZvKd1rrzcSdT2l4GNveqI+lSyj7Mloc9wF5wluW2+gJWpJbBgqMDMu Y9Hg== 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 :message-id:date:subject:cc:to:from; bh=UzzsQovvjB6K+2gB9toJ2FDdKQVvVQVBr4aty1adIuM=; b=UYVk5JlWNoUxBN1z/Vo8Egr1nJ9ORXOahw/I/tenJIanZLVP7AyoOk+9sDcYWsGPtn +HHdNqllhoUNh/SnFq05RnV3yBgAYZ/hRbiBxjH1zJ9XzEbNDuFB0veeW2cryHhuywfq C/oF19O/KUj4MU0Jk0vBc1S6GKWq8Tvp9EJOKHZ5/tXyJekI4I7LqPcqaBA6jaqz1lKp CA8FdXBbH52ic+U8zOQ5XYGemxqwbtbBiE/jROzOBz+yt0iZ5SYlFvR70SlbShVBA9tu 5Y5h92K/BInU7uhzZg4Hr/rQmbXePiEQPWJ7C6TEFX36jVy5Q0odhHV4YWWMyabnqkC9 HA2A== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i133-20020a62878b000000b0050e0a0b03afsi7272249pfe.362.2022.05.19.11.46.48; Thu, 19 May 2022 11:47:07 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242580AbiESRYq (ORCPT + 99 others); Thu, 19 May 2022 13:24:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55796 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242584AbiESRYk (ORCPT ); Thu, 19 May 2022 13:24:40 -0400 Received: from pegase2.c-s.fr (pegase2.c-s.fr [93.17.235.10]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ED119A5033 for ; Thu, 19 May 2022 10:24:35 -0700 (PDT) Received: from localhost (mailhub3.si.c-s.fr [172.26.127.67]) by localhost (Postfix) with ESMTP id 4L3xYZ08qcz9t0v; Thu, 19 May 2022 19:24:34 +0200 (CEST) X-Virus-Scanned: amavisd-new at c-s.fr Received: from pegase2.c-s.fr ([172.26.127.65]) by localhost (pegase2.c-s.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id ddt7bRaOl9UR; Thu, 19 May 2022 19:24:33 +0200 (CEST) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase2.c-s.fr (Postfix) with ESMTP id 4L3xYY6QdZz9t0Q; Thu, 19 May 2022 19:24:33 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id CE1468B77E; Thu, 19 May 2022 19:24:33 +0200 (CEST) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id iY_bcdOXjTrp; Thu, 19 May 2022 19:24:33 +0200 (CEST) Received: from PO20335.IDSI0.si.c-s.fr (unknown [192.168.203.71]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 898AF8B763; Thu, 19 May 2022 19:24:33 +0200 (CEST) Received: from PO20335.IDSI0.si.c-s.fr (localhost [127.0.0.1]) by PO20335.IDSI0.si.c-s.fr (8.17.1/8.16.1) with ESMTPS id 24JHOJFK3119573 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 19 May 2022 19:24:19 +0200 Received: (from chleroy@localhost) by PO20335.IDSI0.si.c-s.fr (8.17.1/8.17.1/Submit) id 24JHOGv43119570; Thu, 19 May 2022 19:24:16 +0200 X-Authentication-Warning: PO20335.IDSI0.si.c-s.fr: chleroy set sender to christophe.leroy@csgroup.eu using -f From: Christophe Leroy To: Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman Cc: Christophe Leroy , linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, Guenter Roeck Subject: [PATCH] powerpc/fsl_book3e: Don't set rodata RO too early Date: Thu, 19 May 2022 19:24:15 +0200 Message-Id: <2e35f0fd649c83c5add17a99514ac040767be93a.1652981047.git.christophe.leroy@csgroup.eu> X-Mailer: git-send-email 2.35.3 MIME-Version: 1.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1652981054; l=2109; s=20211009; h=from:subject:message-id; bh=p6ejnAcRp1DXCMNYT2kdvj6nTKpgEruWDwQ7V/yK0UA=; b=YCxyW82yvhrDvdTSZOrtzTfRi2z5vOF3Fu4aR6vzJqRcB4CS0JKWHqwXmVUOviWs9NxEnzw57ItE Tp4MuPFZBVgkR7/y//Ec9JvC9ux9b2/xvuVmYe1tiac1Lq+GtZok X-Developer-Key: i=christophe.leroy@csgroup.eu; a=ed25519; pk=HIzTzUj91asvincQGOFx6+ZF5AoUuP9GdOtQChs7Mm0= 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 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 On fsl_book3e, rodata is set read-only at the same time as init text is set NX at the end of init. That's too early. As both action are performed at the same time, delay both actions to the time rodata is expected to be made read-only. It means we will have a small window with init mem freed but still executable. It shouldn't be an issue though, especially because the said memory gets poisoned and should therefore result to a bad instruction fault in case it gets executer. mmu_mark_initmem_nx() is bailing out before doing anything when CONFIG_STRICT_KERNEL_RWX is not selected or rodata_enabled is false. mmu_mark_rodata_ro() is called only when CONFIG_STRICT_KERNEL_RWX is selected and rodata_enabled is true so this is equivalent. Move code from mmu_mark_initmem_nx() into mmu_mark_rodata_ro() and remove the call to strict_kernel_rwx_enabled() which is not needed anymore. Reported-by: Guenter Roeck Fixes: d5970045cf9e ("powerpc/fsl_booke: Update of TLBCAMs after init") Signed-off-by: Christophe Leroy --- arch/powerpc/mm/nohash/fsl_book3e.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/arch/powerpc/mm/nohash/fsl_book3e.c b/arch/powerpc/mm/nohash/fsl_book3e.c index 08a984e29433..036e6a0e0137 100644 --- a/arch/powerpc/mm/nohash/fsl_book3e.c +++ b/arch/powerpc/mm/nohash/fsl_book3e.c @@ -285,22 +285,19 @@ void __init adjust_total_lowmem(void) #ifdef CONFIG_STRICT_KERNEL_RWX void mmu_mark_rodata_ro(void) -{ - /* Everything is done in mmu_mark_initmem_nx() */ -} -#endif - -void mmu_mark_initmem_nx(void) { unsigned long remapped; - if (!strict_kernel_rwx_enabled()) - return; - remapped = map_mem_in_cams(__max_low_memory, CONFIG_LOWMEM_CAM_NUM, false, false); WARN_ON(__max_low_memory != remapped); } +#endif + +void mmu_mark_initmem_nx(void) +{ + /* Everything is done in mmu_mark_rodata_ro() */ +} void setup_initial_memory_limit(phys_addr_t first_memblock_base, phys_addr_t first_memblock_size) -- 2.35.3