Skip to contentSkip to conversation

ftrace/x86: Add a comment to why we take text_mutex in ftrace_arch_code_modify_prepare()

PATCH In review Steven Rostedt 3 participants 4 messages Jun 28, 2019

Subsystems (3)
lore
Share & tools
lore

Steven Rostedt

author maintainer
#0 lore raw

PATCH 1/1 ftrace/x86: Add a comment to why we take text_mutex in ftrace_arch_code_modify_prepare()

From: "Steven Rostedt (VMware)" <[email protected]>

Taking the text_mutex in ftrace_arch_code_modify_prepare() is to fix a race against module loading and live kernel patching that might try to change the text permissions while ftrace has it as read/write. This really needs to be documented in the code. Add a comment that does such.

---
 arch/x86/kernel/ftrace.c | 5 +++++
 1 file changed, 5 insertions(+)
arch/x86/kernel/ftrace.c +5 -0
index 33786044d5ac..d7e93b2783fd 100644
@@ -36,6 +36,11 @@
 
 int ftrace_arch_code_modify_prepare(void)
 {
+	/*
+	 * Need to grab text_mutex to prevent a race from module loading
+	 * and live kernel patching from changing the text permissions while
+	 * ftrace has it set to "read/write".
+	 */
 	mutex_lock(&text_mutex);
 	set_kernel_text_rw();
 	set_all_modules_text_rw();
Signature · 1 line
2.20.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 33 lines · Steven Rostedt

From: "Steven Rostedt (VMware)" <[email protected]>

Taking the text_mutex in ftrace_arch_code_modify_prepare() is to fix a race against module loading and live kernel patching that might try to change the text permissions while ftrace has it as read/write. This really needs to be documented in the code. Add a comment that does such.

---
 arch/x86/kernel/ftrace.c | 5 +++++
 1 file changed, 5 insertions(+)
arch/x86/kernel/ftrace.c +5 -0
index 33786044d5ac..d7e93b2783fd 100644
@@ -36,6 +36,11 @@
 
 int ftrace_arch_code_modify_prepare(void)
 {
+	/*
+	 * Need to grab text_mutex to prevent a race from module loading
+	 * and live kernel patching from changing the text permissions while
+	 * ftrace has it set to "read/write".
+	 */
 	mutex_lock(&text_mutex);
 	set_kernel_text_rw();
 	set_all_modules_text_rw();
Signature · 1 line
2.20.1
Signature · 1 line
Josh
author maintainer
#2 lore raw
Quoted 9 lines · On Thu, 27 Jun 2019 20:21:09 -0500 Josh Poimboeuf <[email protected]> wrote:
Quoted 8 lines · Steven Rostedt

From: "Steven Rostedt (VMware)" <[email protected]>

Taking the text_mutex in ftrace_arch_code_modify_prepare() is to fix a race against module loading and live kernel patching that might try to change the text permissions while ftrace has it as read/write. This really needs to be documented in the code. Add a comment that does such.

Quoted 7 lines
Quoted 2 lines

Thanks!

-- Steve

maintainer Reviewed-by on v1 1/1
#3 lore raw
In reply to Steven Rostedt
Quoted 10 lines · Steven Rostedt

From: "Steven Rostedt (VMware)" <[email protected]>

Taking the text_mutex in ftrace_arch_code_modify_prepare() is to fix a race against module loading and live kernel patching that might try to change the text permissions while ftrace has it as read/write. This really needs to be documented in the code. Add a comment that does such.

Best Regards,
Petr