diff options
Diffstat (limited to 'kernel/kprobes.c')
-rw-r--r-- | kernel/kprobes.c | 281 |
1 files changed, 201 insertions, 80 deletions
diff --git a/kernel/kprobes.c b/kernel/kprobes.c index 5016bfb682b9..a5e74ddee0e2 100644 --- a/kernel/kprobes.c +++ b/kernel/kprobes.c | |||
@@ -68,7 +68,7 @@ static struct hlist_head kprobe_table[KPROBE_TABLE_SIZE]; | |||
68 | static struct hlist_head kretprobe_inst_table[KPROBE_TABLE_SIZE]; | 68 | static struct hlist_head kretprobe_inst_table[KPROBE_TABLE_SIZE]; |
69 | 69 | ||
70 | /* NOTE: change this value only with kprobe_mutex held */ | 70 | /* NOTE: change this value only with kprobe_mutex held */ |
71 | static bool kprobe_enabled; | 71 | static bool kprobes_all_disarmed; |
72 | 72 | ||
73 | static DEFINE_MUTEX(kprobe_mutex); /* Protects kprobe_table */ | 73 | static DEFINE_MUTEX(kprobe_mutex); /* Protects kprobe_table */ |
74 | static DEFINE_PER_CPU(struct kprobe *, kprobe_instance) = NULL; | 74 | static DEFINE_PER_CPU(struct kprobe *, kprobe_instance) = NULL; |
@@ -328,7 +328,7 @@ static int __kprobes aggr_pre_handler(struct kprobe *p, struct pt_regs *regs) | |||
328 | struct kprobe *kp; | 328 | struct kprobe *kp; |
329 | 329 | ||
330 | list_for_each_entry_rcu(kp, &p->list, list) { | 330 | list_for_each_entry_rcu(kp, &p->list, list) { |
331 | if (kp->pre_handler && !kprobe_gone(kp)) { | 331 | if (kp->pre_handler && likely(!kprobe_disabled(kp))) { |
332 | set_kprobe_instance(kp); | 332 | set_kprobe_instance(kp); |
333 | if (kp->pre_handler(kp, regs)) | 333 | if (kp->pre_handler(kp, regs)) |
334 | return 1; | 334 | return 1; |
@@ -344,7 +344,7 @@ static void __kprobes aggr_post_handler(struct kprobe *p, struct pt_regs *regs, | |||
344 | struct kprobe *kp; | 344 | struct kprobe *kp; |
345 | 345 | ||
346 | list_for_each_entry_rcu(kp, &p->list, list) { | 346 | list_for_each_entry_rcu(kp, &p->list, list) { |
347 | if (kp->post_handler && !kprobe_gone(kp)) { | 347 | if (kp->post_handler && likely(!kprobe_disabled(kp))) { |
348 | set_kprobe_instance(kp); | 348 | set_kprobe_instance(kp); |
349 | kp->post_handler(kp, regs, flags); | 349 | kp->post_handler(kp, regs, flags); |
350 | reset_kprobe_instance(); | 350 | reset_kprobe_instance(); |
@@ -518,20 +518,28 @@ static inline void copy_kprobe(struct kprobe *old_p, struct kprobe *p) | |||
518 | } | 518 | } |
519 | 519 | ||
520 | /* | 520 | /* |
521 | * Add the new probe to old_p->list. Fail if this is the | 521 | * Add the new probe to ap->list. Fail if this is the |
522 | * second jprobe at the address - two jprobes can't coexist | 522 | * second jprobe at the address - two jprobes can't coexist |
523 | */ | 523 | */ |
524 | static int __kprobes add_new_kprobe(struct kprobe *old_p, struct kprobe *p) | 524 | static int __kprobes add_new_kprobe(struct kprobe *ap, struct kprobe *p) |
525 | { | 525 | { |
526 | BUG_ON(kprobe_gone(ap) || kprobe_gone(p)); | ||
526 | if (p->break_handler) { | 527 | if (p->break_handler) { |
527 | if (old_p->break_handler) | 528 | if (ap->break_handler) |
528 | return -EEXIST; | 529 | return -EEXIST; |
529 | list_add_tail_rcu(&p->list, &old_p->list); | 530 | list_add_tail_rcu(&p->list, &ap->list); |
530 | old_p->break_handler = aggr_break_handler; | 531 | ap->break_handler = aggr_break_handler; |
531 | } else | 532 | } else |
532 | list_add_rcu(&p->list, &old_p->list); | 533 | list_add_rcu(&p->list, &ap->list); |
533 | if (p->post_handler && !old_p->post_handler) | 534 | if (p->post_handler && !ap->post_handler) |
534 | old_p->post_handler = aggr_post_handler; | 535 | ap->post_handler = aggr_post_handler; |
536 | |||
537 | if (kprobe_disabled(ap) && !kprobe_disabled(p)) { | ||
538 | ap->flags &= ~KPROBE_FLAG_DISABLED; | ||
539 | if (!kprobes_all_disarmed) | ||
540 | /* Arm the breakpoint again. */ | ||
541 | arch_arm_kprobe(ap); | ||
542 | } | ||
535 | return 0; | 543 | return 0; |
536 | } | 544 | } |
537 | 545 | ||
@@ -544,6 +552,7 @@ static inline void add_aggr_kprobe(struct kprobe *ap, struct kprobe *p) | |||
544 | copy_kprobe(p, ap); | 552 | copy_kprobe(p, ap); |
545 | flush_insn_slot(ap); | 553 | flush_insn_slot(ap); |
546 | ap->addr = p->addr; | 554 | ap->addr = p->addr; |
555 | ap->flags = p->flags; | ||
547 | ap->pre_handler = aggr_pre_handler; | 556 | ap->pre_handler = aggr_pre_handler; |
548 | ap->fault_handler = aggr_fault_handler; | 557 | ap->fault_handler = aggr_fault_handler; |
549 | /* We don't care the kprobe which has gone. */ | 558 | /* We don't care the kprobe which has gone. */ |
@@ -566,44 +575,59 @@ static int __kprobes register_aggr_kprobe(struct kprobe *old_p, | |||
566 | struct kprobe *p) | 575 | struct kprobe *p) |
567 | { | 576 | { |
568 | int ret = 0; | 577 | int ret = 0; |
569 | struct kprobe *ap; | 578 | struct kprobe *ap = old_p; |
570 | 579 | ||
571 | if (kprobe_gone(old_p)) { | 580 | if (old_p->pre_handler != aggr_pre_handler) { |
581 | /* If old_p is not an aggr_probe, create new aggr_kprobe. */ | ||
582 | ap = kzalloc(sizeof(struct kprobe), GFP_KERNEL); | ||
583 | if (!ap) | ||
584 | return -ENOMEM; | ||
585 | add_aggr_kprobe(ap, old_p); | ||
586 | } | ||
587 | |||
588 | if (kprobe_gone(ap)) { | ||
572 | /* | 589 | /* |
573 | * Attempting to insert new probe at the same location that | 590 | * Attempting to insert new probe at the same location that |
574 | * had a probe in the module vaddr area which already | 591 | * had a probe in the module vaddr area which already |
575 | * freed. So, the instruction slot has already been | 592 | * freed. So, the instruction slot has already been |
576 | * released. We need a new slot for the new probe. | 593 | * released. We need a new slot for the new probe. |
577 | */ | 594 | */ |
578 | ret = arch_prepare_kprobe(old_p); | 595 | ret = arch_prepare_kprobe(ap); |
579 | if (ret) | 596 | if (ret) |
597 | /* | ||
598 | * Even if fail to allocate new slot, don't need to | ||
599 | * free aggr_probe. It will be used next time, or | ||
600 | * freed by unregister_kprobe. | ||
601 | */ | ||
580 | return ret; | 602 | return ret; |
581 | } | 603 | |
582 | if (old_p->pre_handler == aggr_pre_handler) { | ||
583 | copy_kprobe(old_p, p); | ||
584 | ret = add_new_kprobe(old_p, p); | ||
585 | ap = old_p; | ||
586 | } else { | ||
587 | ap = kzalloc(sizeof(struct kprobe), GFP_KERNEL); | ||
588 | if (!ap) { | ||
589 | if (kprobe_gone(old_p)) | ||
590 | arch_remove_kprobe(old_p); | ||
591 | return -ENOMEM; | ||
592 | } | ||
593 | add_aggr_kprobe(ap, old_p); | ||
594 | copy_kprobe(ap, p); | ||
595 | ret = add_new_kprobe(ap, p); | ||
596 | } | ||
597 | if (kprobe_gone(old_p)) { | ||
598 | /* | 604 | /* |
599 | * If the old_p has gone, its breakpoint has been disarmed. | 605 | * Clear gone flag to prevent allocating new slot again, and |
600 | * We have to arm it again after preparing real kprobes. | 606 | * set disabled flag because it is not armed yet. |
601 | */ | 607 | */ |
602 | ap->flags &= ~KPROBE_FLAG_GONE; | 608 | ap->flags = (ap->flags & ~KPROBE_FLAG_GONE) |
603 | if (kprobe_enabled) | 609 | | KPROBE_FLAG_DISABLED; |
604 | arch_arm_kprobe(ap); | ||
605 | } | 610 | } |
606 | return ret; | 611 | |
612 | copy_kprobe(ap, p); | ||
613 | return add_new_kprobe(ap, p); | ||
614 | } | ||
615 | |||
616 | /* Try to disable aggr_kprobe, and return 1 if succeeded.*/ | ||
617 | static int __kprobes try_to_disable_aggr_kprobe(struct kprobe *p) | ||
618 | { | ||
619 | struct kprobe *kp; | ||
620 | |||
621 | list_for_each_entry_rcu(kp, &p->list, list) { | ||
622 | if (!kprobe_disabled(kp)) | ||
623 | /* | ||
624 | * There is an active probe on the list. | ||
625 | * We can't disable aggr_kprobe. | ||
626 | */ | ||
627 | return 0; | ||
628 | } | ||
629 | p->flags |= KPROBE_FLAG_DISABLED; | ||
630 | return 1; | ||
607 | } | 631 | } |
608 | 632 | ||
609 | static int __kprobes in_kprobes_functions(unsigned long addr) | 633 | static int __kprobes in_kprobes_functions(unsigned long addr) |
@@ -664,7 +688,9 @@ int __kprobes register_kprobe(struct kprobe *p) | |||
664 | return -EINVAL; | 688 | return -EINVAL; |
665 | } | 689 | } |
666 | 690 | ||
667 | p->flags = 0; | 691 | /* User can pass only KPROBE_FLAG_DISABLED to register_kprobe */ |
692 | p->flags &= KPROBE_FLAG_DISABLED; | ||
693 | |||
668 | /* | 694 | /* |
669 | * Check if are we probing a module. | 695 | * Check if are we probing a module. |
670 | */ | 696 | */ |
@@ -709,7 +735,7 @@ int __kprobes register_kprobe(struct kprobe *p) | |||
709 | hlist_add_head_rcu(&p->hlist, | 735 | hlist_add_head_rcu(&p->hlist, |
710 | &kprobe_table[hash_ptr(p->addr, KPROBE_HASH_BITS)]); | 736 | &kprobe_table[hash_ptr(p->addr, KPROBE_HASH_BITS)]); |
711 | 737 | ||
712 | if (kprobe_enabled) | 738 | if (!kprobes_all_disarmed && !kprobe_disabled(p)) |
713 | arch_arm_kprobe(p); | 739 | arch_arm_kprobe(p); |
714 | 740 | ||
715 | out_unlock_text: | 741 | out_unlock_text: |
@@ -722,26 +748,39 @@ out: | |||
722 | 748 | ||
723 | return ret; | 749 | return ret; |
724 | } | 750 | } |
751 | EXPORT_SYMBOL_GPL(register_kprobe); | ||
725 | 752 | ||
726 | /* | 753 | /* Check passed kprobe is valid and return kprobe in kprobe_table. */ |
727 | * Unregister a kprobe without a scheduler synchronization. | 754 | static struct kprobe * __kprobes __get_valid_kprobe(struct kprobe *p) |
728 | */ | ||
729 | static int __kprobes __unregister_kprobe_top(struct kprobe *p) | ||
730 | { | 755 | { |
731 | struct kprobe *old_p, *list_p; | 756 | struct kprobe *old_p, *list_p; |
732 | 757 | ||
733 | old_p = get_kprobe(p->addr); | 758 | old_p = get_kprobe(p->addr); |
734 | if (unlikely(!old_p)) | 759 | if (unlikely(!old_p)) |
735 | return -EINVAL; | 760 | return NULL; |
736 | 761 | ||
737 | if (p != old_p) { | 762 | if (p != old_p) { |
738 | list_for_each_entry_rcu(list_p, &old_p->list, list) | 763 | list_for_each_entry_rcu(list_p, &old_p->list, list) |
739 | if (list_p == p) | 764 | if (list_p == p) |
740 | /* kprobe p is a valid probe */ | 765 | /* kprobe p is a valid probe */ |
741 | goto valid_p; | 766 | goto valid; |
742 | return -EINVAL; | 767 | return NULL; |
743 | } | 768 | } |
744 | valid_p: | 769 | valid: |
770 | return old_p; | ||
771 | } | ||
772 | |||
773 | /* | ||
774 | * Unregister a kprobe without a scheduler synchronization. | ||
775 | */ | ||
776 | static int __kprobes __unregister_kprobe_top(struct kprobe *p) | ||
777 | { | ||
778 | struct kprobe *old_p, *list_p; | ||
779 | |||
780 | old_p = __get_valid_kprobe(p); | ||
781 | if (old_p == NULL) | ||
782 | return -EINVAL; | ||
783 | |||
745 | if (old_p == p || | 784 | if (old_p == p || |
746 | (old_p->pre_handler == aggr_pre_handler && | 785 | (old_p->pre_handler == aggr_pre_handler && |
747 | list_is_singular(&old_p->list))) { | 786 | list_is_singular(&old_p->list))) { |
@@ -750,7 +789,7 @@ valid_p: | |||
750 | * enabled and not gone - otherwise, the breakpoint would | 789 | * enabled and not gone - otherwise, the breakpoint would |
751 | * already have been removed. We save on flushing icache. | 790 | * already have been removed. We save on flushing icache. |
752 | */ | 791 | */ |
753 | if (kprobe_enabled && !kprobe_gone(old_p)) { | 792 | if (!kprobes_all_disarmed && !kprobe_disabled(old_p)) { |
754 | mutex_lock(&text_mutex); | 793 | mutex_lock(&text_mutex); |
755 | arch_disarm_kprobe(p); | 794 | arch_disarm_kprobe(p); |
756 | mutex_unlock(&text_mutex); | 795 | mutex_unlock(&text_mutex); |
@@ -768,6 +807,11 @@ valid_p: | |||
768 | } | 807 | } |
769 | noclean: | 808 | noclean: |
770 | list_del_rcu(&p->list); | 809 | list_del_rcu(&p->list); |
810 | if (!kprobe_disabled(old_p)) { | ||
811 | try_to_disable_aggr_kprobe(old_p); | ||
812 | if (!kprobes_all_disarmed && kprobe_disabled(old_p)) | ||
813 | arch_disarm_kprobe(old_p); | ||
814 | } | ||
771 | } | 815 | } |
772 | return 0; | 816 | return 0; |
773 | } | 817 | } |
@@ -803,11 +847,13 @@ int __kprobes register_kprobes(struct kprobe **kps, int num) | |||
803 | } | 847 | } |
804 | return ret; | 848 | return ret; |
805 | } | 849 | } |
850 | EXPORT_SYMBOL_GPL(register_kprobes); | ||
806 | 851 | ||
807 | void __kprobes unregister_kprobe(struct kprobe *p) | 852 | void __kprobes unregister_kprobe(struct kprobe *p) |
808 | { | 853 | { |
809 | unregister_kprobes(&p, 1); | 854 | unregister_kprobes(&p, 1); |
810 | } | 855 | } |
856 | EXPORT_SYMBOL_GPL(unregister_kprobe); | ||
811 | 857 | ||
812 | void __kprobes unregister_kprobes(struct kprobe **kps, int num) | 858 | void __kprobes unregister_kprobes(struct kprobe **kps, int num) |
813 | { | 859 | { |
@@ -826,6 +872,7 @@ void __kprobes unregister_kprobes(struct kprobe **kps, int num) | |||
826 | if (kps[i]->addr) | 872 | if (kps[i]->addr) |
827 | __unregister_kprobe_bottom(kps[i]); | 873 | __unregister_kprobe_bottom(kps[i]); |
828 | } | 874 | } |
875 | EXPORT_SYMBOL_GPL(unregister_kprobes); | ||
829 | 876 | ||
830 | static struct notifier_block kprobe_exceptions_nb = { | 877 | static struct notifier_block kprobe_exceptions_nb = { |
831 | .notifier_call = kprobe_exceptions_notify, | 878 | .notifier_call = kprobe_exceptions_notify, |
@@ -865,16 +912,19 @@ int __kprobes register_jprobes(struct jprobe **jps, int num) | |||
865 | } | 912 | } |
866 | return ret; | 913 | return ret; |
867 | } | 914 | } |
915 | EXPORT_SYMBOL_GPL(register_jprobes); | ||
868 | 916 | ||
869 | int __kprobes register_jprobe(struct jprobe *jp) | 917 | int __kprobes register_jprobe(struct jprobe *jp) |
870 | { | 918 | { |
871 | return register_jprobes(&jp, 1); | 919 | return register_jprobes(&jp, 1); |
872 | } | 920 | } |
921 | EXPORT_SYMBOL_GPL(register_jprobe); | ||
873 | 922 | ||
874 | void __kprobes unregister_jprobe(struct jprobe *jp) | 923 | void __kprobes unregister_jprobe(struct jprobe *jp) |
875 | { | 924 | { |
876 | unregister_jprobes(&jp, 1); | 925 | unregister_jprobes(&jp, 1); |
877 | } | 926 | } |
927 | EXPORT_SYMBOL_GPL(unregister_jprobe); | ||
878 | 928 | ||
879 | void __kprobes unregister_jprobes(struct jprobe **jps, int num) | 929 | void __kprobes unregister_jprobes(struct jprobe **jps, int num) |
880 | { | 930 | { |
@@ -894,6 +944,7 @@ void __kprobes unregister_jprobes(struct jprobe **jps, int num) | |||
894 | __unregister_kprobe_bottom(&jps[i]->kp); | 944 | __unregister_kprobe_bottom(&jps[i]->kp); |
895 | } | 945 | } |
896 | } | 946 | } |
947 | EXPORT_SYMBOL_GPL(unregister_jprobes); | ||
897 | 948 | ||
898 | #ifdef CONFIG_KRETPROBES | 949 | #ifdef CONFIG_KRETPROBES |
899 | /* | 950 | /* |
@@ -987,6 +1038,7 @@ int __kprobes register_kretprobe(struct kretprobe *rp) | |||
987 | free_rp_inst(rp); | 1038 | free_rp_inst(rp); |
988 | return ret; | 1039 | return ret; |
989 | } | 1040 | } |
1041 | EXPORT_SYMBOL_GPL(register_kretprobe); | ||
990 | 1042 | ||
991 | int __kprobes register_kretprobes(struct kretprobe **rps, int num) | 1043 | int __kprobes register_kretprobes(struct kretprobe **rps, int num) |
992 | { | 1044 | { |
@@ -1004,11 +1056,13 @@ int __kprobes register_kretprobes(struct kretprobe **rps, int num) | |||
1004 | } | 1056 | } |
1005 | return ret; | 1057 | return ret; |
1006 | } | 1058 | } |
1059 | EXPORT_SYMBOL_GPL(register_kretprobes); | ||
1007 | 1060 | ||
1008 | void __kprobes unregister_kretprobe(struct kretprobe *rp) | 1061 | void __kprobes unregister_kretprobe(struct kretprobe *rp) |
1009 | { | 1062 | { |
1010 | unregister_kretprobes(&rp, 1); | 1063 | unregister_kretprobes(&rp, 1); |
1011 | } | 1064 | } |
1065 | EXPORT_SYMBOL_GPL(unregister_kretprobe); | ||
1012 | 1066 | ||
1013 | void __kprobes unregister_kretprobes(struct kretprobe **rps, int num) | 1067 | void __kprobes unregister_kretprobes(struct kretprobe **rps, int num) |
1014 | { | 1068 | { |
@@ -1030,24 +1084,30 @@ void __kprobes unregister_kretprobes(struct kretprobe **rps, int num) | |||
1030 | } | 1084 | } |
1031 | } | 1085 | } |
1032 | } | 1086 | } |
1087 | EXPORT_SYMBOL_GPL(unregister_kretprobes); | ||
1033 | 1088 | ||
1034 | #else /* CONFIG_KRETPROBES */ | 1089 | #else /* CONFIG_KRETPROBES */ |
1035 | int __kprobes register_kretprobe(struct kretprobe *rp) | 1090 | int __kprobes register_kretprobe(struct kretprobe *rp) |
1036 | { | 1091 | { |
1037 | return -ENOSYS; | 1092 | return -ENOSYS; |
1038 | } | 1093 | } |
1094 | EXPORT_SYMBOL_GPL(register_kretprobe); | ||
1039 | 1095 | ||
1040 | int __kprobes register_kretprobes(struct kretprobe **rps, int num) | 1096 | int __kprobes register_kretprobes(struct kretprobe **rps, int num) |
1041 | { | 1097 | { |
1042 | return -ENOSYS; | 1098 | return -ENOSYS; |
1043 | } | 1099 | } |
1100 | EXPORT_SYMBOL_GPL(register_kretprobes); | ||
1101 | |||
1044 | void __kprobes unregister_kretprobe(struct kretprobe *rp) | 1102 | void __kprobes unregister_kretprobe(struct kretprobe *rp) |
1045 | { | 1103 | { |
1046 | } | 1104 | } |
1105 | EXPORT_SYMBOL_GPL(unregister_kretprobe); | ||
1047 | 1106 | ||
1048 | void __kprobes unregister_kretprobes(struct kretprobe **rps, int num) | 1107 | void __kprobes unregister_kretprobes(struct kretprobe **rps, int num) |
1049 | { | 1108 | { |
1050 | } | 1109 | } |
1110 | EXPORT_SYMBOL_GPL(unregister_kretprobes); | ||
1051 | 1111 | ||
1052 | static int __kprobes pre_handler_kretprobe(struct kprobe *p, | 1112 | static int __kprobes pre_handler_kretprobe(struct kprobe *p, |
1053 | struct pt_regs *regs) | 1113 | struct pt_regs *regs) |
@@ -1061,6 +1121,7 @@ static int __kprobes pre_handler_kretprobe(struct kprobe *p, | |||
1061 | static void __kprobes kill_kprobe(struct kprobe *p) | 1121 | static void __kprobes kill_kprobe(struct kprobe *p) |
1062 | { | 1122 | { |
1063 | struct kprobe *kp; | 1123 | struct kprobe *kp; |
1124 | |||
1064 | p->flags |= KPROBE_FLAG_GONE; | 1125 | p->flags |= KPROBE_FLAG_GONE; |
1065 | if (p->pre_handler == aggr_pre_handler) { | 1126 | if (p->pre_handler == aggr_pre_handler) { |
1066 | /* | 1127 | /* |
@@ -1173,8 +1234,8 @@ static int __init init_kprobes(void) | |||
1173 | } | 1234 | } |
1174 | } | 1235 | } |
1175 | 1236 | ||
1176 | /* By default, kprobes are enabled */ | 1237 | /* By default, kprobes are armed */ |
1177 | kprobe_enabled = true; | 1238 | kprobes_all_disarmed = false; |
1178 | 1239 | ||
1179 | err = arch_init_kprobes(); | 1240 | err = arch_init_kprobes(); |
1180 | if (!err) | 1241 | if (!err) |
@@ -1202,12 +1263,18 @@ static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p, | |||
1202 | else | 1263 | else |
1203 | kprobe_type = "k"; | 1264 | kprobe_type = "k"; |
1204 | if (sym) | 1265 | if (sym) |
1205 | seq_printf(pi, "%p %s %s+0x%x %s %s\n", p->addr, kprobe_type, | 1266 | seq_printf(pi, "%p %s %s+0x%x %s %s%s\n", |
1206 | sym, offset, (modname ? modname : " "), | 1267 | p->addr, kprobe_type, sym, offset, |
1207 | (kprobe_gone(p) ? "[GONE]" : "")); | 1268 | (modname ? modname : " "), |
1269 | (kprobe_gone(p) ? "[GONE]" : ""), | ||
1270 | ((kprobe_disabled(p) && !kprobe_gone(p)) ? | ||
1271 | "[DISABLED]" : "")); | ||
1208 | else | 1272 | else |
1209 | seq_printf(pi, "%p %s %p %s\n", p->addr, kprobe_type, p->addr, | 1273 | seq_printf(pi, "%p %s %p %s%s\n", |
1210 | (kprobe_gone(p) ? "[GONE]" : "")); | 1274 | p->addr, kprobe_type, p->addr, |
1275 | (kprobe_gone(p) ? "[GONE]" : ""), | ||
1276 | ((kprobe_disabled(p) && !kprobe_gone(p)) ? | ||
1277 | "[DISABLED]" : "")); | ||
1211 | } | 1278 | } |
1212 | 1279 | ||
1213 | static void __kprobes *kprobe_seq_start(struct seq_file *f, loff_t *pos) | 1280 | static void __kprobes *kprobe_seq_start(struct seq_file *f, loff_t *pos) |
@@ -1272,7 +1339,72 @@ static struct file_operations debugfs_kprobes_operations = { | |||
1272 | .release = seq_release, | 1339 | .release = seq_release, |
1273 | }; | 1340 | }; |
1274 | 1341 | ||
1275 | static void __kprobes enable_all_kprobes(void) | 1342 | /* Disable one kprobe */ |
1343 | int __kprobes disable_kprobe(struct kprobe *kp) | ||
1344 | { | ||
1345 | int ret = 0; | ||
1346 | struct kprobe *p; | ||
1347 | |||
1348 | mutex_lock(&kprobe_mutex); | ||
1349 | |||
1350 | /* Check whether specified probe is valid. */ | ||
1351 | p = __get_valid_kprobe(kp); | ||
1352 | if (unlikely(p == NULL)) { | ||
1353 | ret = -EINVAL; | ||
1354 | goto out; | ||
1355 | } | ||
1356 | |||
1357 | /* If the probe is already disabled (or gone), just return */ | ||
1358 | if (kprobe_disabled(kp)) | ||
1359 | goto out; | ||
1360 | |||
1361 | kp->flags |= KPROBE_FLAG_DISABLED; | ||
1362 | if (p != kp) | ||
1363 | /* When kp != p, p is always enabled. */ | ||
1364 | try_to_disable_aggr_kprobe(p); | ||
1365 | |||
1366 | if (!kprobes_all_disarmed && kprobe_disabled(p)) | ||
1367 | arch_disarm_kprobe(p); | ||
1368 | out: | ||
1369 | mutex_unlock(&kprobe_mutex); | ||
1370 | return ret; | ||
1371 | } | ||
1372 | EXPORT_SYMBOL_GPL(disable_kprobe); | ||
1373 | |||
1374 | /* Enable one kprobe */ | ||
1375 | int __kprobes enable_kprobe(struct kprobe *kp) | ||
1376 | { | ||
1377 | int ret = 0; | ||
1378 | struct kprobe *p; | ||
1379 | |||
1380 | mutex_lock(&kprobe_mutex); | ||
1381 | |||
1382 | /* Check whether specified probe is valid. */ | ||
1383 | p = __get_valid_kprobe(kp); | ||
1384 | if (unlikely(p == NULL)) { | ||
1385 | ret = -EINVAL; | ||
1386 | goto out; | ||
1387 | } | ||
1388 | |||
1389 | if (kprobe_gone(kp)) { | ||
1390 | /* This kprobe has gone, we couldn't enable it. */ | ||
1391 | ret = -EINVAL; | ||
1392 | goto out; | ||
1393 | } | ||
1394 | |||
1395 | if (!kprobes_all_disarmed && kprobe_disabled(p)) | ||
1396 | arch_arm_kprobe(p); | ||
1397 | |||
1398 | p->flags &= ~KPROBE_FLAG_DISABLED; | ||
1399 | if (p != kp) | ||
1400 | kp->flags &= ~KPROBE_FLAG_DISABLED; | ||
1401 | out: | ||
1402 | mutex_unlock(&kprobe_mutex); | ||
1403 | return ret; | ||
1404 | } | ||
1405 | EXPORT_SYMBOL_GPL(enable_kprobe); | ||
1406 | |||
1407 | static void __kprobes arm_all_kprobes(void) | ||
1276 | { | 1408 | { |
1277 | struct hlist_head *head; | 1409 | struct hlist_head *head; |
1278 | struct hlist_node *node; | 1410 | struct hlist_node *node; |
@@ -1281,20 +1413,20 @@ static void __kprobes enable_all_kprobes(void) | |||
1281 | 1413 | ||
1282 | mutex_lock(&kprobe_mutex); | 1414 | mutex_lock(&kprobe_mutex); |
1283 | 1415 | ||
1284 | /* If kprobes are already enabled, just return */ | 1416 | /* If kprobes are armed, just return */ |
1285 | if (kprobe_enabled) | 1417 | if (!kprobes_all_disarmed) |
1286 | goto already_enabled; | 1418 | goto already_enabled; |
1287 | 1419 | ||
1288 | mutex_lock(&text_mutex); | 1420 | mutex_lock(&text_mutex); |
1289 | for (i = 0; i < KPROBE_TABLE_SIZE; i++) { | 1421 | for (i = 0; i < KPROBE_TABLE_SIZE; i++) { |
1290 | head = &kprobe_table[i]; | 1422 | head = &kprobe_table[i]; |
1291 | hlist_for_each_entry_rcu(p, node, head, hlist) | 1423 | hlist_for_each_entry_rcu(p, node, head, hlist) |
1292 | if (!kprobe_gone(p)) | 1424 | if (!kprobe_disabled(p)) |
1293 | arch_arm_kprobe(p); | 1425 | arch_arm_kprobe(p); |
1294 | } | 1426 | } |
1295 | mutex_unlock(&text_mutex); | 1427 | mutex_unlock(&text_mutex); |
1296 | 1428 | ||
1297 | kprobe_enabled = true; | 1429 | kprobes_all_disarmed = false; |
1298 | printk(KERN_INFO "Kprobes globally enabled\n"); | 1430 | printk(KERN_INFO "Kprobes globally enabled\n"); |
1299 | 1431 | ||
1300 | already_enabled: | 1432 | already_enabled: |
@@ -1302,7 +1434,7 @@ already_enabled: | |||
1302 | return; | 1434 | return; |
1303 | } | 1435 | } |
1304 | 1436 | ||
1305 | static void __kprobes disable_all_kprobes(void) | 1437 | static void __kprobes disarm_all_kprobes(void) |
1306 | { | 1438 | { |
1307 | struct hlist_head *head; | 1439 | struct hlist_head *head; |
1308 | struct hlist_node *node; | 1440 | struct hlist_node *node; |
@@ -1311,17 +1443,17 @@ static void __kprobes disable_all_kprobes(void) | |||
1311 | 1443 | ||
1312 | mutex_lock(&kprobe_mutex); | 1444 | mutex_lock(&kprobe_mutex); |
1313 | 1445 | ||
1314 | /* If kprobes are already disabled, just return */ | 1446 | /* If kprobes are already disarmed, just return */ |
1315 | if (!kprobe_enabled) | 1447 | if (kprobes_all_disarmed) |
1316 | goto already_disabled; | 1448 | goto already_disabled; |
1317 | 1449 | ||
1318 | kprobe_enabled = false; | 1450 | kprobes_all_disarmed = true; |
1319 | printk(KERN_INFO "Kprobes globally disabled\n"); | 1451 | printk(KERN_INFO "Kprobes globally disabled\n"); |
1320 | mutex_lock(&text_mutex); | 1452 | mutex_lock(&text_mutex); |
1321 | for (i = 0; i < KPROBE_TABLE_SIZE; i++) { | 1453 | for (i = 0; i < KPROBE_TABLE_SIZE; i++) { |
1322 | head = &kprobe_table[i]; | 1454 | head = &kprobe_table[i]; |
1323 | hlist_for_each_entry_rcu(p, node, head, hlist) { | 1455 | hlist_for_each_entry_rcu(p, node, head, hlist) { |
1324 | if (!arch_trampoline_kprobe(p) && !kprobe_gone(p)) | 1456 | if (!arch_trampoline_kprobe(p) && !kprobe_disabled(p)) |
1325 | arch_disarm_kprobe(p); | 1457 | arch_disarm_kprobe(p); |
1326 | } | 1458 | } |
1327 | } | 1459 | } |
@@ -1347,7 +1479,7 @@ static ssize_t read_enabled_file_bool(struct file *file, | |||
1347 | { | 1479 | { |
1348 | char buf[3]; | 1480 | char buf[3]; |
1349 | 1481 | ||
1350 | if (kprobe_enabled) | 1482 | if (!kprobes_all_disarmed) |
1351 | buf[0] = '1'; | 1483 | buf[0] = '1'; |
1352 | else | 1484 | else |
1353 | buf[0] = '0'; | 1485 | buf[0] = '0'; |
@@ -1370,12 +1502,12 @@ static ssize_t write_enabled_file_bool(struct file *file, | |||
1370 | case 'y': | 1502 | case 'y': |
1371 | case 'Y': | 1503 | case 'Y': |
1372 | case '1': | 1504 | case '1': |
1373 | enable_all_kprobes(); | 1505 | arm_all_kprobes(); |
1374 | break; | 1506 | break; |
1375 | case 'n': | 1507 | case 'n': |
1376 | case 'N': | 1508 | case 'N': |
1377 | case '0': | 1509 | case '0': |
1378 | disable_all_kprobes(); | 1510 | disarm_all_kprobes(); |
1379 | break; | 1511 | break; |
1380 | } | 1512 | } |
1381 | 1513 | ||
@@ -1418,16 +1550,5 @@ late_initcall(debugfs_kprobe_init); | |||
1418 | 1550 | ||
1419 | module_init(init_kprobes); | 1551 | module_init(init_kprobes); |
1420 | 1552 | ||
1421 | EXPORT_SYMBOL_GPL(register_kprobe); | 1553 | /* defined in arch/.../kernel/kprobes.c */ |
1422 | EXPORT_SYMBOL_GPL(unregister_kprobe); | ||
1423 | EXPORT_SYMBOL_GPL(register_kprobes); | ||
1424 | EXPORT_SYMBOL_GPL(unregister_kprobes); | ||
1425 | EXPORT_SYMBOL_GPL(register_jprobe); | ||
1426 | EXPORT_SYMBOL_GPL(unregister_jprobe); | ||
1427 | EXPORT_SYMBOL_GPL(register_jprobes); | ||
1428 | EXPORT_SYMBOL_GPL(unregister_jprobes); | ||
1429 | EXPORT_SYMBOL_GPL(jprobe_return); | 1554 | EXPORT_SYMBOL_GPL(jprobe_return); |
1430 | EXPORT_SYMBOL_GPL(register_kretprobe); | ||
1431 | EXPORT_SYMBOL_GPL(unregister_kretprobe); | ||
1432 | EXPORT_SYMBOL_GPL(register_kretprobes); | ||
1433 | EXPORT_SYMBOL_GPL(unregister_kretprobes); | ||