Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2195320iof; Tue, 7 Jun 2022 22:51:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwBB2mVjNFY55lBOvi2YsHxll1UTvpjdeHSSoMz8REGtSniCh3OGrLJU6Jo+nTmDJGvmLqe X-Received: by 2002:a05:6a00:2392:b0:51b:fe0e:2b8 with SMTP id f18-20020a056a00239200b0051bfe0e02b8mr19398688pfc.84.1654667488327; Tue, 07 Jun 2022 22:51:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654667488; cv=none; d=google.com; s=arc-20160816; b=DfcTtSIQZ/P/mu6S9A/GepZoFQ185BcHqs1K0GW2jlpzlN+EKbE/L4Zp0s8HiHFk4i GYj7zWe2mxbm6CIrB7IRx0trxWZdgKZ/wV8ADYAG48d9MHU9g/6Yjce3j/9d8rXLGE1f gbD1Vz7gd4WdX2lN6gVzzCM29az/wkn3Lf3BnV3r0WzGnB0ovrTc7/x96f6Szg5s9yjL lq8MiasnJQyVCeh3sccYMRbGWiFElH/ecyLlVTqbiFACc7yJ7ijddwWTz/gwLf6QEj/D FNWhuJQcRlcTBouNJwIc4r/ic30LI+PmDI6m0cYU9PpPx0c9/bch1j3Tl5FLLfjt+VrB dvUg== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=5/LGrGvpblEFUYBx+4CEteM6mMf6l1G6xyhVoq5wZUw=; b=RvPbxYzRCnoXvNhlok1ceWY96BNAh2MhaucrwESx4Ea5qrKJuyWnPlAr05lJ/S7k9D RHfj/xcJQZ3Z53ngl01qTftcTE6/jJ2DNdgnaOfmzAjjWFiUarvhcYZekSfdCfaho2/B fJi/23lSF+WwNdAecXU8DcARSi17ZCWtIMEcexgG1FpRkcFKyTuOD/RE3BQc5bYWlRHY AvwLzluyR/gFKLLDTx5VXcwWEgZ5CtNjDA1n/pb+9U/VJ0SW1IFg1aELNE+EOkE+l4dy o3ZdLXatovM05wm/P3/I8PNRPY5Pz+tmXSZHbajuCjkCwQ3qFalLu/6dYcIr1UbEz7G6 qf/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=UoIWpnSc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id p17-20020a170903249100b0015ea266647fsi5493434plw.394.2022.06.07.22.51.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 22:51:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=UoIWpnSc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id BA524403629; Tue, 7 Jun 2022 22:18:21 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377467AbiFHAog (ORCPT + 99 others); Tue, 7 Jun 2022 20:44:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40386 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1382374AbiFGWDV (ORCPT ); Tue, 7 Jun 2022 18:03:21 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8263B2514B0; Tue, 7 Jun 2022 12:15:15 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id EBF28B82368; Tue, 7 Jun 2022 19:15:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5B62BC385A2; Tue, 7 Jun 2022 19:15:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1654629312; bh=K1VJeX5GCDsY+9X8S0bObVsEpIXlCrJ6Ne/vbZkkzvU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UoIWpnSc8T8zAS+vo4YbLV+BOU8vfL6HoNWtfHbp8tz1kAS8rJH12g0oYcofekbtL oysX0y5QgpJlM06Fsh/7ORe51/b5smeXHwdl2aAbSE1543Lt040HSXUuixHu4ZhlVH A2h9zF0bF1mxznEv6Lc/v86uQx9ldB3dri62sc0E= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Guenter Roeck , Christophe Leroy , Michael Ellerman , Sasha Levin Subject: [PATCH 5.18 647/879] powerpc/fsl_book3e: Dont set rodata RO too early Date: Tue, 7 Jun 2022 19:02:45 +0200 Message-Id: <20220607165021.627479518@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220607165002.659942637@linuxfoundation.org> References: <20220607165002.659942637@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 From: Christophe Leroy [ Upstream commit ad91f66f5fa7c6f9346e721c3159ce818568028b ] 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 executed. 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. Fixes: d5970045cf9e ("powerpc/fsl_booke: Update of TLBCAMs after init") Reported-by: Guenter Roeck Tested-by: Guenter Roeck Signed-off-by: Christophe Leroy Signed-off-by: Michael Ellerman Link: https://lore.kernel.org/r/2e35f0fd649c83c5add17a99514ac040767be93a.1652981047.git.christophe.leroy@csgroup.eu Signed-off-by: Sasha Levin --- 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 dfe715e0f70a..388f7c7dabd3 100644 --- a/arch/powerpc/mm/nohash/fsl_book3e.c +++ b/arch/powerpc/mm/nohash/fsl_book3e.c @@ -287,22 +287,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.1