Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp2274728imm; Thu, 21 Jun 2018 09:48:11 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIi585nM5Q2xQ0k2lXTUrYrtR6ZKZEloPNl0099jyqNi88Eowysc8XmcLIQ3v/269U3fTgu X-Received: by 2002:a62:3ad8:: with SMTP id v85-v6mr28448528pfj.184.1529599691574; Thu, 21 Jun 2018 09:48:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529599691; cv=none; d=google.com; s=arc-20160816; b=lR0G1cabpEdqIu6Z8t8Vd/tGr4aXSO7rPSHHQy0VKmaFaCxQajfFEBMsiptgYqRzBJ fdWpN8CG+4/xHDPmFT8NvXMk2zFNLb/vQ2TuREhR+kWoysqcfV5K8IKfmosNNBialjvV +coLPFg4d8DjGgmxZsm1+LQ9LSTgB0vegAJDwzcgXtw38DYG7RiTRU9PGPnqxwHWPhPP b/tbsELGLtc0lah81jUP52QwqM+grIwgWy1j/c5t9uB5hD1lKIhJ20TA3N3epgCcrKuL 425ecqpyXfJfYRPQdsmmAB7LlYrl5zLLBSKV0PD3j4QqyTlcYRCXQUxCPfxA6+1JxcIT crrA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:subject:cc:to:from:date:arc-authentication-results; bh=hMss1KQ1od9nOoCYTZ5Fuipb2ICutSn9pwX1Ea8suWk=; b=OV5x129CUs0ngzzOcyDa3co9bHwW9VvUOljCat9OoLif0NBGK+9x7iDv0xOkoHfYEh OWeUDPM+5QHcoYt4FisT0Abfmo3sedYMIZ1r3qPfCUjh0LiWC6u/oBBuWvzcOjx7IxS0 kuCG5Kl4HEOGPAwLBJaC74komDzTRR/pjODTyTqdjolW8FDXC5DFtB3riKixcecgCur/ LHSFcReJfTOcRJeI/wmGaoTcZwXl5ndR1Xf/prUFfc8BZk7oX7qfN1GvGlnjymZN71/C DvXeyIEPrSZEWOQkN2yYqnroDqpxBL3GSoxS8MwBiQFoSWJyQFTdlo9xLlGLI26okWYo vReQ== 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 t82-v6si5288192pfi.221.2018.06.21.09.47.54; Thu, 21 Jun 2018 09:48:11 -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 S933468AbeFUQrN (ORCPT + 99 others); Thu, 21 Jun 2018 12:47:13 -0400 Received: from mail.kernel.org ([198.145.29.99]:59168 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933409AbeFUQrN (ORCPT ); Thu, 21 Jun 2018 12:47:13 -0400 Received: from gandalf.local.home (cpe-66-24-56-78.stny.res.rr.com [66.24.56.78]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id C93B82168C; Thu, 21 Jun 2018 16:47:11 +0000 (UTC) Date: Thu, 21 Jun 2018 12:47:10 -0400 From: Steven Rostedt To: LKML , linux-arm-kernel@lists.infradead.org, Russell King - ARM Linux Cc: Stefan Agner , abelvesa@linux.com, Abhishek Sagar , Ingo Molnar Subject: [PATCH] ARM: ftrace: Only set kernel memory back to read-only after boot Message-ID: <20180621124710.453ee0ae@gandalf.local.home> X-Mailer: Claws Mail 3.16.0 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Steven Rostedt (VMware) 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"). Reported-by: Stefan Agner Tested-by: Stefan Agner Link: http://lkml.kernel.org/r/20180620212906.24b7b66e@vmware.local.home Signed-off-by: Steven Rostedt (VMware) --- diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c index c186474422f3..0cc8e04295a4 100644 --- a/arch/arm/mm/init.c +++ b/arch/arm/mm/init.c @@ -736,20 +736,29 @@ static 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); debug_checkwx(); } 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); }