um: Fix kcov crash before kernel is started.
Subsystems (2)
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
@@ -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
Richard Weinberger
maintainerAm 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 thethread_infostructure. But on UML the__sanitizer_cov_trace_pcfunction is called for *all* functions! This results in an early crash:Prevent kcov from using invalid
curent_thread_info()data by checking thesystem_state.Signed-off-by Thomas Meyer <[email protected]>--- kernel/kcov.c | 6 ++++++ 1 file changed, 6 insertions(+)kernel/kcov.c +0
-0
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
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 thethread_infostructure. But on UML the__sanitizer_cov_trace_pcfunction is called for *all* functions! This results in an early crash:Prevent kcov from using invalid
curent_thread_info()data by checking thesystem_state.Signed-off-by Thomas Meyer <[email protected]>--- kernel/kcov.c | 6 ++++++ 1 file changed, 6 insertions(+)kernel/kcov.c +0
-0@@ -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