Skip to contentSkip to conversation

um: Fix kcov crash before kernel is started.

PATCH In review Thomas Meyer 2 participants 3 messages Oct 8, 2017

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 um: Fix kcov crash before kernel is started.

UMLs current_thread_info() unconditionally assumes that the top of the stack contains the thread_info structure. But on UML the __sanitizer_cov_trace_pc function is called for *all* functions! This results in an early crash:

Prevent kcov from using invalid curent_thread_info() data by checking the system_state.

---
 kernel/kcov.c | 6 ++++++
 1 file changed, 6 insertions(+)
kernel/kcov.c +6 -0
index 3f693a0f6f3e..d601c0e956f6 100644
@@ -56,6 +56,12 @@ void notrace __sanitizer_cov_trace_pc(void)
 	struct task_struct *t;
 	enum kcov_mode mode;
 
+#ifdef CONFIG_UML
+	if(!(system_state == SYSTEM_SCHEDULING ||
+	     system_state == SYSTEM_RUNNING))
+		return;
+#endif
+
 	t = current;
 	/*
 	 * We are interested in code coverage as a function of a syscall inputs,
Signature · 1 line
2.11.0
#1 lore raw

Am Sonntag, 8. Oktober 2017, 12:31:58 CEST schrieb Thomas Meyer:

Quoted 17 lines

UMLs current_thread_info() unconditionally assumes that the top of the stack contains the thread_info structure. But on UML the __sanitizer_cov_trace_pc function is called for *all* functions! This results in an early crash:

Prevent kcov from using invalid curent_thread_info() data by checking the system_state.

---
 kernel/kcov.c | 6 ++++++
 1 file changed, 6 insertions(+)
kernel/kcov.c +0 -0
index 3f693a0f6f3e..d601c0e956f6 100644

kernel/kcov.c void notrace __sanitizer_cov_trace_pc(void) · line 63

Quoted 8 lines
kernel/kcov.c +5 -0
@@ -56,6 +56,12 @@ void notrace __sanitizer_cov_trace_pc(void)
 	struct task_struct *t;
 	enum kcov_mode mode;
 
+#ifdef CONFIG_UML
+	if(!(system_state == SYSTEM_SCHEDULING ||
+	     system_state == SYSTEM_RUNNING))
+		return;
+#endif

Hmm, and why does it work on all other archs then?

Thanks,
//richard

#2 lore raw
Quoted 21 lines · Richard Weinberger

Am Sonntag, 8. Oktober 2017, 12:31:58 CEST schrieb Thomas Meyer:

Quoted 20 lines

UMLs current_thread_info() unconditionally assumes that the top of the stack contains the thread_info structure. But on UML the __sanitizer_cov_trace_pc function is called for *all* functions! This results in an early crash:

Prevent kcov from using invalid curent_thread_info() data by checking the system_state.

---
 kernel/kcov.c | 6 ++++++
 1 file changed, 6 insertions(+)
kernel/kcov.c +0 -0
index 3f693a0f6f3e..d601c0e956f6 100644
@@ -56,6 +56,12 @@ void notrace __sanitizer_cov_trace_pc(void)
 	struct task_struct *t;
 	enum kcov_mode mode;
 
Quoted 7 lines

kernel/kcov.c void notrace __sanitizer_cov_trace_pc(void) · line 63

Quoted 5 lines
kernel/kcov.c +5 -0
+#ifdef CONFIG_UML
+	if(!(system_state == SYSTEM_SCHEDULING ||
+	     system_state == SYSTEM_RUNNING))
+		return;
+#endif

Hmm, and why does it work on all other archs then?

Hi,

I guess UML is different then other archs! But to be honest I'm not sure why. I assume that __sanitizer_cov_trace_pc on other archs isn't called that early, or that curent_thread_info returns NULL on other archs when the first task isn't running yet.

But as I fail to use/setup the qemu gdb attachment to debug early x86_64 code I can't say exactly why.

Maybe someone how knows the inner workings of x86_64 and/or kcov can answer this question!

Quoted 4 lines

Thanks,
//richard