Skip to content

Commit b4c7e2b

Browse files
rostedtRussell King
authored andcommitted
ARM: 8780/1: ftrace: Only set kernel memory back to read-only after boot
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 1623963 ("ftrace, x86: make kernel text writable only for conversions"). Link: http://lkml.kernel.org/r/20180620212906.24b7b66e@vmware.local.home Reported-by: Stefan Agner <stefan@agner.ch> Tested-by: Stefan Agner <stefan@agner.ch> Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org> Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
1 parent cea3947 commit b4c7e2b

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

arch/arm/mm/init.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -736,20 +736,29 @@ static int __mark_rodata_ro(void *unused)
736736
return 0;
737737
}
738738

739+
static int kernel_set_to_readonly __read_mostly;
740+
739741
void mark_rodata_ro(void)
740742
{
743+
kernel_set_to_readonly = 1;
741744
stop_machine(__mark_rodata_ro, NULL, NULL);
742745
debug_checkwx();
743746
}
744747

745748
void set_kernel_text_rw(void)
746749
{
750+
if (!kernel_set_to_readonly)
751+
return;
752+
747753
set_section_perms(ro_perms, ARRAY_SIZE(ro_perms), false,
748754
current->active_mm);
749755
}
750756

751757
void set_kernel_text_ro(void)
752758
{
759+
if (!kernel_set_to_readonly)
760+
return;
761+
753762
set_section_perms(ro_perms, ARRAY_SIZE(ro_perms), true,
754763
current->active_mm);
755764
}

0 commit comments

Comments
 (0)