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