Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp1334923imm; Thu, 23 Aug 2018 01:01:34 -0700 (PDT) X-Google-Smtp-Source: ANB0VdaA6qvRN22jw3WWF0DhAZBmQMKM5d8yLl4RSD4otH4uRKf2rxWJHYv2CRulVvwD1XxdK/fG X-Received: by 2002:a62:2bc2:: with SMTP id r185-v6mr6884674pfr.154.1535011294185; Thu, 23 Aug 2018 01:01:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535011294; cv=none; d=google.com; s=arc-20160816; b=ZLrqm8UT4uwiLblbG8PSsu/kV+f5XyRG/zcAN75ZkbUCKecwbmKpSeVnRiBD6uNQlC VWDQnDzDhg3iRoq2TuFLLSlh/hqIFyjBRB2FBKE5q89+FECiW64bVA+2IJNGHfoH6HcX h+a/+EP3d+ApD3zc9K22jQpV+koKE4dvBjaOlv4iAn52byYNbj92uxOocrC1BelD+yw3 7LqatTE4GNH7iqwtK4lNxBON2HvG+AEmhWiyackgPIv16m2gi3L7tBEFUotI5pIgDwHI rF9zIP8ELc3oxXuDjah1CC1K0MwY9ITKpcP+1yKOTGUcMkaYs0a5KMfCoOjiqxhOgRZ5 MySw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=LSojkf0DFFYEbKTe8MCq5xPrs/1wrVgLi+g2/P2K5xE=; b=uudos9y82p0FrpiNiSMpDc1Jmy1PySbridjy6pgnzkJ7siKzyrtPyDL3KfWuCX8HrE pA5qH+So+Q3HHSCfA70yRda8e8ZNXm7JjhzzpjnXum6lctoNYc2NHWuAL6GkcfvNFOy2 y+t7DSIsjWFtAePrk8G4VH/Lba1+Au08ABDXceN3uEpI8L2+/m3JoUv3KUqCgKs4YusD qDSPs4+FVviIR2uf/Vt4wgLuVpMEQAG9yZNU5Oer7QxPBMZwEG6+BLrVhcL7xwciVPLi ebnWcG8V7X7Edm4EfF6MeB8o0rx3MZIVstlnOMY2Aa/b9ulup1tjhr6vu8cPj4xR1pSl v4rA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f24-v6si2283388plj.510.2018.08.23.01.01.18; Thu, 23 Aug 2018 01:01:34 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728478AbeHWL1x (ORCPT + 99 others); Thu, 23 Aug 2018 07:27:53 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:42036 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726836AbeHWL1w (ORCPT ); Thu, 23 Aug 2018 07:27:52 -0400 Received: from localhost (5355525A.cm-6-6b.dynamic.ziggo.nl [83.85.82.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 81DEF9D2; Thu, 23 Aug 2018 07:59:29 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Stefan Agner , "Steven Rostedt (VMware)" , Russell King , Sasha Levin Subject: [PATCH 4.4 53/79] ARM: 8780/1: ftrace: Only set kernel memory back to read-only after boot Date: Thu, 23 Aug 2018 09:53:29 +0200 Message-Id: <20180823074922.583222760@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180823074918.641878835@linuxfoundation.org> References: <20180823074918.641878835@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: "Steven Rostedt (VMware)" [ Upstream commit b4c7e2bd2eb4764afe3af9409ff3b1b87116fa30 ] Dynamic ftrace requires modifying the code segments that are usually set to read-only. To do this, a per arch function is called both before and after the ftrace modifications are performed. The "before" function will set kernel code text to read-write to allow for ftrace to make the modifications, and the "after" function will set the kernel code text back to "read-only" to keep the kernel code text protected. The issue happens when dynamic ftrace is tested at boot up. The test is done before the kernel code text has been set to read-only. But the "before" and "after" calls are still performed. The "after" call will change the kernel code text to read-only prematurely, and other boot code that expects this code to be read-write will fail. The solution is to add a variable that is set when the kernel code text is expected to be converted to read-only, and make the ftrace "before" and "after" calls do nothing if that variable is not yet set. This is similar to the x86 solution from commit 162396309745 ("ftrace, x86: make kernel text writable only for conversions"). Link: http://lkml.kernel.org/r/20180620212906.24b7b66e@vmware.local.home Reported-by: Stefan Agner Tested-by: Stefan Agner Signed-off-by: Steven Rostedt (VMware) Signed-off-by: Russell King Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- arch/arm/mm/init.c | 9 +++++++++ 1 file changed, 9 insertions(+) --- a/arch/arm/mm/init.c +++ b/arch/arm/mm/init.c @@ -716,19 +716,28 @@ int __mark_rodata_ro(void *unused) return 0; } +static int kernel_set_to_readonly __read_mostly; + void mark_rodata_ro(void) { + kernel_set_to_readonly = 1; stop_machine(__mark_rodata_ro, NULL, NULL); } void set_kernel_text_rw(void) { + if (!kernel_set_to_readonly) + return; + set_section_perms(ro_perms, ARRAY_SIZE(ro_perms), false, current->active_mm); } void set_kernel_text_ro(void) { + if (!kernel_set_to_readonly) + return; + set_section_perms(ro_perms, ARRAY_SIZE(ro_perms), true, current->active_mm); }