From: Masami Hiramatsu <mhira...@kernel.org>

commit 1a0aa991a6274161c95a844c58cfb801d681eb59 upstream.

In kprobe_optimizer() kick_kprobe_optimizer() is called
without kprobe_mutex, but this can race with other caller
which is protected by kprobe_mutex.

To fix that, expand kprobe_mutex protected area to protect
kick_kprobe_optimizer() call.

Link: 
http://lkml.kernel.org/r/158927057586.27680.5036330063955940456.stgit@devnote2

Fixes: cd7ebe2298ff ("kprobes: Use text_poke_smp_batch for optimizing")
Cc: Ingo Molnar <mi...@kernel.org>
Cc: "Gustavo A . R . Silva" <gustavo...@kernel.org>
Cc: Anders Roxell <anders.rox...@linaro.org>
Cc: "Naveen N . Rao" <naveen.n....@linux.ibm.com>
Cc: Anil S Keshavamurthy <anil.s.keshavamur...@intel.com>
Cc: David Miller <da...@davemloft.net>
Cc: Ingo Molnar <mi...@elte.hu>
Cc: Peter Zijlstra <pet...@infradead.org>
Cc: Ziqian SUN <z...@redhat.com>
Cc: sta...@vger.kernel.org
Signed-off-by: Masami Hiramatsu <mhira...@kernel.org>
Signed-off-by: Steven Rostedt (VMware) <rost...@goodmis.org>
Signed-off-by: Greg Kroah-Hartman <gre...@linuxfoundation.org>

---
 kernel/kprobes.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

--- a/kernel/kprobes.c
+++ b/kernel/kprobes.c
@@ -586,11 +586,12 @@ static void kprobe_optimizer(struct work
        mutex_unlock(&module_mutex);
        mutex_unlock(&text_mutex);
        cpus_read_unlock();
-       mutex_unlock(&kprobe_mutex);
 
        /* Step 5: Kick optimizer again if needed */
        if (!list_empty(&optimizing_list) || !list_empty(&unoptimizing_list))
                kick_kprobe_optimizer();
+
+       mutex_unlock(&kprobe_mutex);
 }
 
 /* Wait for completing optimization and unoptimization */


Reply via email to