kprobes: fix to use text_mutex around arm/disarm kprobe

Fix kprobes to lock text_mutex around some arch_arm/disarm_kprobe() which
are newly added by commit de5bd88d5a5cce3cacea904d3503e5ebdb3852a2.

Signed-off-by: Masami Hiramatsu <mhiramat@redhat.com>
Acked-by: Ananth N Mavinakayanahalli <ananth@in.ibm.com>
Cc: Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
Cc: Jim Keniston <jkenisto@us.ibm.com>
Cc: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by Masami Hiramatsu and committed by Linus Torvalds 201517a7 d7a59269

+22 -9
+22 -9
kernel/kprobes.c
··· 319 319 return NULL; 320 320 } 321 321 322 + /* Arm a kprobe with text_mutex */ 323 + static void __kprobes arm_kprobe(struct kprobe *kp) 324 + { 325 + mutex_lock(&text_mutex); 326 + arch_arm_kprobe(kp); 327 + mutex_unlock(&text_mutex); 328 + } 329 + 330 + /* Disarm a kprobe with text_mutex */ 331 + static void __kprobes disarm_kprobe(struct kprobe *kp) 332 + { 333 + mutex_lock(&text_mutex); 334 + arch_disarm_kprobe(kp); 335 + mutex_unlock(&text_mutex); 336 + } 337 + 322 338 /* 323 339 * Aggregate handlers for multiple kprobes support - these handlers 324 340 * take care of invoking the individual kprobe handlers on p->list ··· 554 538 ap->flags &= ~KPROBE_FLAG_DISABLED; 555 539 if (!kprobes_all_disarmed) 556 540 /* Arm the breakpoint again. */ 557 - arch_arm_kprobe(ap); 541 + arm_kprobe(ap); 558 542 } 559 543 return 0; 560 544 } ··· 805 789 * enabled and not gone - otherwise, the breakpoint would 806 790 * already have been removed. We save on flushing icache. 807 791 */ 808 - if (!kprobes_all_disarmed && !kprobe_disabled(old_p)) { 809 - mutex_lock(&text_mutex); 810 - arch_disarm_kprobe(p); 811 - mutex_unlock(&text_mutex); 812 - } 792 + if (!kprobes_all_disarmed && !kprobe_disabled(old_p)) 793 + disarm_kprobe(p); 813 794 hlist_del_rcu(&old_p->hlist); 814 795 } else { 815 796 if (p->break_handler && !kprobe_gone(p)) ··· 823 810 if (!kprobe_disabled(old_p)) { 824 811 try_to_disable_aggr_kprobe(old_p); 825 812 if (!kprobes_all_disarmed && kprobe_disabled(old_p)) 826 - arch_disarm_kprobe(old_p); 813 + disarm_kprobe(old_p); 827 814 } 828 815 } 829 816 return 0; ··· 1377 1364 try_to_disable_aggr_kprobe(p); 1378 1365 1379 1366 if (!kprobes_all_disarmed && kprobe_disabled(p)) 1380 - arch_disarm_kprobe(p); 1367 + disarm_kprobe(p); 1381 1368 out: 1382 1369 mutex_unlock(&kprobe_mutex); 1383 1370 return ret; ··· 1406 1393 } 1407 1394 1408 1395 if (!kprobes_all_disarmed && kprobe_disabled(p)) 1409 - arch_arm_kprobe(p); 1396 + arm_kprobe(p); 1410 1397 1411 1398 p->flags &= ~KPROBE_FLAG_DISABLED; 1412 1399 if (p != kp)