Skip to content

Commit 6384f78

Browse files
KAGA-KOKOgregkh
authored andcommitted
tracing/kprobes: Enforce kprobes teardown after testing
commit 30e7d894c1478c88d50ce94ddcdbd7f9763d9cdd upstream. Enabling the tracer selftest triggers occasionally the warning in text_poke(), which warns when the to be modified page is not marked reserved. The reason is that the tracer selftest installs kprobes on functions marked __init for testing. These probes are removed after the tests, but that removal schedules the delayed kprobes_optimizer work, which will do the actual text poke. If the work is executed after the init text is freed, then the warning triggers. The bug can be reproduced reliably when the work delay is increased. Flush the optimizer work and wait for the optimizing/unoptimizing lists to become empty before returning from the kprobes tracer selftest. That ensures that all operations which were queued due to the probes removal have completed. Link: http://lkml.kernel.org/r/20170516094802.76a468bb@gandalf.local.home Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Acked-by: Masami Hiramatsu <mhiramat@kernel.org> Fixes: 6274de4 ("kprobes: Support delayed unoptimizing") Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent d5fb96b commit 6384f78

3 files changed

Lines changed: 9 additions & 2 deletions

File tree

include/linux/kprobes.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,9 @@ extern int proc_kprobes_optimization_handler(struct ctl_table *table,
330330
int write, void __user *buffer,
331331
size_t *length, loff_t *ppos);
332332
#endif
333-
333+
extern void wait_for_kprobe_optimizer(void);
334+
#else
335+
static inline void wait_for_kprobe_optimizer(void) { }
334336
#endif /* CONFIG_OPTPROBES */
335337
#ifdef CONFIG_KPROBES_ON_FTRACE
336338
extern void kprobe_ftrace_handler(unsigned long ip, unsigned long parent_ip,

kernel/kprobes.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ static void kprobe_optimizer(struct work_struct *work)
563563
}
564564

565565
/* Wait for completing optimization and unoptimization */
566-
static void wait_for_kprobe_optimizer(void)
566+
void wait_for_kprobe_optimizer(void)
567567
{
568568
mutex_lock(&kprobe_mutex);
569569

kernel/trace/trace_kprobe.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1471,6 +1471,11 @@ static __init int kprobe_trace_self_tests_init(void)
14711471

14721472
end:
14731473
release_all_trace_kprobes();
1474+
/*
1475+
* Wait for the optimizer work to finish. Otherwise it might fiddle
1476+
* with probes in already freed __init text.
1477+
*/
1478+
wait_for_kprobe_optimizer();
14741479
if (warn)
14751480
pr_cont("NG: Some tests are failed. Please check them.\n");
14761481
else

0 commit comments

Comments
 (0)