diff options
author | Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com> | 2014-04-17 04:18:21 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@kernel.org> | 2014-04-24 04:26:38 -0400 |
commit | 820aede0209a51549e8a014c8030e29229920e4e (patch) | |
tree | d0401dce67c9e70d10bd866427411b17531cd5b1 /kernel/kprobes.c | |
parent | 9326638cbee2d36b051ed2a69f3e4e107e5f86bd (diff) |
kprobes: Use NOKPROBE_SYMBOL macro instead of __kprobes
Use NOKPROBE_SYMBOL macro to protect functions from
kprobes instead of __kprobes annotation.
Signed-off-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Reviewed-by: Steven Rostedt <rostedt@goodmis.org>
Cc: Ananth N Mavinakayanahalli <ananth@in.ibm.com>
Cc: Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com>
Cc: David S. Miller <davem@davemloft.net>
Link: http://lkml.kernel.org/r/20140417081821.26341.40362.stgit@ltc230.yrl.intra.hitachi.co.jp
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Diffstat (limited to 'kernel/kprobes.c')
-rw-r--r-- | kernel/kprobes.c | 67 |
1 files changed, 41 insertions, 26 deletions
diff --git a/kernel/kprobes.c b/kernel/kprobes.c index 4db2cc616f50..a21b4e67fd97 100644 --- a/kernel/kprobes.c +++ b/kernel/kprobes.c | |||
@@ -301,7 +301,7 @@ static inline void reset_kprobe_instance(void) | |||
301 | * OR | 301 | * OR |
302 | * - with preemption disabled - from arch/xxx/kernel/kprobes.c | 302 | * - with preemption disabled - from arch/xxx/kernel/kprobes.c |
303 | */ | 303 | */ |
304 | struct kprobe __kprobes *get_kprobe(void *addr) | 304 | struct kprobe *get_kprobe(void *addr) |
305 | { | 305 | { |
306 | struct hlist_head *head; | 306 | struct hlist_head *head; |
307 | struct kprobe *p; | 307 | struct kprobe *p; |
@@ -314,8 +314,9 @@ struct kprobe __kprobes *get_kprobe(void *addr) | |||
314 | 314 | ||
315 | return NULL; | 315 | return NULL; |
316 | } | 316 | } |
317 | NOKPROBE_SYMBOL(get_kprobe); | ||
317 | 318 | ||
318 | static int __kprobes aggr_pre_handler(struct kprobe *p, struct pt_regs *regs); | 319 | static int aggr_pre_handler(struct kprobe *p, struct pt_regs *regs); |
319 | 320 | ||
320 | /* Return true if the kprobe is an aggregator */ | 321 | /* Return true if the kprobe is an aggregator */ |
321 | static inline int kprobe_aggrprobe(struct kprobe *p) | 322 | static inline int kprobe_aggrprobe(struct kprobe *p) |
@@ -347,7 +348,7 @@ static bool kprobes_allow_optimization; | |||
347 | * Call all pre_handler on the list, but ignores its return value. | 348 | * Call all pre_handler on the list, but ignores its return value. |
348 | * This must be called from arch-dep optimized caller. | 349 | * This must be called from arch-dep optimized caller. |
349 | */ | 350 | */ |
350 | void __kprobes opt_pre_handler(struct kprobe *p, struct pt_regs *regs) | 351 | void opt_pre_handler(struct kprobe *p, struct pt_regs *regs) |
351 | { | 352 | { |
352 | struct kprobe *kp; | 353 | struct kprobe *kp; |
353 | 354 | ||
@@ -359,6 +360,7 @@ void __kprobes opt_pre_handler(struct kprobe *p, struct pt_regs *regs) | |||
359 | reset_kprobe_instance(); | 360 | reset_kprobe_instance(); |
360 | } | 361 | } |
361 | } | 362 | } |
363 | NOKPROBE_SYMBOL(opt_pre_handler); | ||
362 | 364 | ||
363 | /* Free optimized instructions and optimized_kprobe */ | 365 | /* Free optimized instructions and optimized_kprobe */ |
364 | static void free_aggr_kprobe(struct kprobe *p) | 366 | static void free_aggr_kprobe(struct kprobe *p) |
@@ -995,7 +997,7 @@ static void disarm_kprobe(struct kprobe *kp, bool reopt) | |||
995 | * Aggregate handlers for multiple kprobes support - these handlers | 997 | * Aggregate handlers for multiple kprobes support - these handlers |
996 | * take care of invoking the individual kprobe handlers on p->list | 998 | * take care of invoking the individual kprobe handlers on p->list |
997 | */ | 999 | */ |
998 | static int __kprobes aggr_pre_handler(struct kprobe *p, struct pt_regs *regs) | 1000 | static int aggr_pre_handler(struct kprobe *p, struct pt_regs *regs) |
999 | { | 1001 | { |
1000 | struct kprobe *kp; | 1002 | struct kprobe *kp; |
1001 | 1003 | ||
@@ -1009,9 +1011,10 @@ static int __kprobes aggr_pre_handler(struct kprobe *p, struct pt_regs *regs) | |||
1009 | } | 1011 | } |
1010 | return 0; | 1012 | return 0; |
1011 | } | 1013 | } |
1014 | NOKPROBE_SYMBOL(aggr_pre_handler); | ||
1012 | 1015 | ||
1013 | static void __kprobes aggr_post_handler(struct kprobe *p, struct pt_regs *regs, | 1016 | static void aggr_post_handler(struct kprobe *p, struct pt_regs *regs, |
1014 | unsigned long flags) | 1017 | unsigned long flags) |
1015 | { | 1018 | { |
1016 | struct kprobe *kp; | 1019 | struct kprobe *kp; |
1017 | 1020 | ||
@@ -1023,9 +1026,10 @@ static void __kprobes aggr_post_handler(struct kprobe *p, struct pt_regs *regs, | |||
1023 | } | 1026 | } |
1024 | } | 1027 | } |
1025 | } | 1028 | } |
1029 | NOKPROBE_SYMBOL(aggr_post_handler); | ||
1026 | 1030 | ||
1027 | static int __kprobes aggr_fault_handler(struct kprobe *p, struct pt_regs *regs, | 1031 | static int aggr_fault_handler(struct kprobe *p, struct pt_regs *regs, |
1028 | int trapnr) | 1032 | int trapnr) |
1029 | { | 1033 | { |
1030 | struct kprobe *cur = __this_cpu_read(kprobe_instance); | 1034 | struct kprobe *cur = __this_cpu_read(kprobe_instance); |
1031 | 1035 | ||
@@ -1039,8 +1043,9 @@ static int __kprobes aggr_fault_handler(struct kprobe *p, struct pt_regs *regs, | |||
1039 | } | 1043 | } |
1040 | return 0; | 1044 | return 0; |
1041 | } | 1045 | } |
1046 | NOKPROBE_SYMBOL(aggr_fault_handler); | ||
1042 | 1047 | ||
1043 | static int __kprobes aggr_break_handler(struct kprobe *p, struct pt_regs *regs) | 1048 | static int aggr_break_handler(struct kprobe *p, struct pt_regs *regs) |
1044 | { | 1049 | { |
1045 | struct kprobe *cur = __this_cpu_read(kprobe_instance); | 1050 | struct kprobe *cur = __this_cpu_read(kprobe_instance); |
1046 | int ret = 0; | 1051 | int ret = 0; |
@@ -1052,9 +1057,10 @@ static int __kprobes aggr_break_handler(struct kprobe *p, struct pt_regs *regs) | |||
1052 | reset_kprobe_instance(); | 1057 | reset_kprobe_instance(); |
1053 | return ret; | 1058 | return ret; |
1054 | } | 1059 | } |
1060 | NOKPROBE_SYMBOL(aggr_break_handler); | ||
1055 | 1061 | ||
1056 | /* Walks the list and increments nmissed count for multiprobe case */ | 1062 | /* Walks the list and increments nmissed count for multiprobe case */ |
1057 | void __kprobes kprobes_inc_nmissed_count(struct kprobe *p) | 1063 | void kprobes_inc_nmissed_count(struct kprobe *p) |
1058 | { | 1064 | { |
1059 | struct kprobe *kp; | 1065 | struct kprobe *kp; |
1060 | if (!kprobe_aggrprobe(p)) { | 1066 | if (!kprobe_aggrprobe(p)) { |
@@ -1065,9 +1071,10 @@ void __kprobes kprobes_inc_nmissed_count(struct kprobe *p) | |||
1065 | } | 1071 | } |
1066 | return; | 1072 | return; |
1067 | } | 1073 | } |
1074 | NOKPROBE_SYMBOL(kprobes_inc_nmissed_count); | ||
1068 | 1075 | ||
1069 | void __kprobes recycle_rp_inst(struct kretprobe_instance *ri, | 1076 | void recycle_rp_inst(struct kretprobe_instance *ri, |
1070 | struct hlist_head *head) | 1077 | struct hlist_head *head) |
1071 | { | 1078 | { |
1072 | struct kretprobe *rp = ri->rp; | 1079 | struct kretprobe *rp = ri->rp; |
1073 | 1080 | ||
@@ -1082,8 +1089,9 @@ void __kprobes recycle_rp_inst(struct kretprobe_instance *ri, | |||
1082 | /* Unregistering */ | 1089 | /* Unregistering */ |
1083 | hlist_add_head(&ri->hlist, head); | 1090 | hlist_add_head(&ri->hlist, head); |
1084 | } | 1091 | } |
1092 | NOKPROBE_SYMBOL(recycle_rp_inst); | ||
1085 | 1093 | ||
1086 | void __kprobes kretprobe_hash_lock(struct task_struct *tsk, | 1094 | void kretprobe_hash_lock(struct task_struct *tsk, |
1087 | struct hlist_head **head, unsigned long *flags) | 1095 | struct hlist_head **head, unsigned long *flags) |
1088 | __acquires(hlist_lock) | 1096 | __acquires(hlist_lock) |
1089 | { | 1097 | { |
@@ -1094,17 +1102,19 @@ __acquires(hlist_lock) | |||
1094 | hlist_lock = kretprobe_table_lock_ptr(hash); | 1102 | hlist_lock = kretprobe_table_lock_ptr(hash); |
1095 | raw_spin_lock_irqsave(hlist_lock, *flags); | 1103 | raw_spin_lock_irqsave(hlist_lock, *flags); |
1096 | } | 1104 | } |
1105 | NOKPROBE_SYMBOL(kretprobe_hash_lock); | ||
1097 | 1106 | ||
1098 | static void __kprobes kretprobe_table_lock(unsigned long hash, | 1107 | static void kretprobe_table_lock(unsigned long hash, |
1099 | unsigned long *flags) | 1108 | unsigned long *flags) |
1100 | __acquires(hlist_lock) | 1109 | __acquires(hlist_lock) |
1101 | { | 1110 | { |
1102 | raw_spinlock_t *hlist_lock = kretprobe_table_lock_ptr(hash); | 1111 | raw_spinlock_t *hlist_lock = kretprobe_table_lock_ptr(hash); |
1103 | raw_spin_lock_irqsave(hlist_lock, *flags); | 1112 | raw_spin_lock_irqsave(hlist_lock, *flags); |
1104 | } | 1113 | } |
1114 | NOKPROBE_SYMBOL(kretprobe_table_lock); | ||
1105 | 1115 | ||
1106 | void __kprobes kretprobe_hash_unlock(struct task_struct *tsk, | 1116 | void kretprobe_hash_unlock(struct task_struct *tsk, |
1107 | unsigned long *flags) | 1117 | unsigned long *flags) |
1108 | __releases(hlist_lock) | 1118 | __releases(hlist_lock) |
1109 | { | 1119 | { |
1110 | unsigned long hash = hash_ptr(tsk, KPROBE_HASH_BITS); | 1120 | unsigned long hash = hash_ptr(tsk, KPROBE_HASH_BITS); |
@@ -1113,14 +1123,16 @@ __releases(hlist_lock) | |||
1113 | hlist_lock = kretprobe_table_lock_ptr(hash); | 1123 | hlist_lock = kretprobe_table_lock_ptr(hash); |
1114 | raw_spin_unlock_irqrestore(hlist_lock, *flags); | 1124 | raw_spin_unlock_irqrestore(hlist_lock, *flags); |
1115 | } | 1125 | } |
1126 | NOKPROBE_SYMBOL(kretprobe_hash_unlock); | ||
1116 | 1127 | ||
1117 | static void __kprobes kretprobe_table_unlock(unsigned long hash, | 1128 | static void kretprobe_table_unlock(unsigned long hash, |
1118 | unsigned long *flags) | 1129 | unsigned long *flags) |
1119 | __releases(hlist_lock) | 1130 | __releases(hlist_lock) |
1120 | { | 1131 | { |
1121 | raw_spinlock_t *hlist_lock = kretprobe_table_lock_ptr(hash); | 1132 | raw_spinlock_t *hlist_lock = kretprobe_table_lock_ptr(hash); |
1122 | raw_spin_unlock_irqrestore(hlist_lock, *flags); | 1133 | raw_spin_unlock_irqrestore(hlist_lock, *flags); |
1123 | } | 1134 | } |
1135 | NOKPROBE_SYMBOL(kretprobe_table_unlock); | ||
1124 | 1136 | ||
1125 | /* | 1137 | /* |
1126 | * This function is called from finish_task_switch when task tk becomes dead, | 1138 | * This function is called from finish_task_switch when task tk becomes dead, |
@@ -1128,7 +1140,7 @@ __releases(hlist_lock) | |||
1128 | * with this task. These left over instances represent probed functions | 1140 | * with this task. These left over instances represent probed functions |
1129 | * that have been called but will never return. | 1141 | * that have been called but will never return. |
1130 | */ | 1142 | */ |
1131 | void __kprobes kprobe_flush_task(struct task_struct *tk) | 1143 | void kprobe_flush_task(struct task_struct *tk) |
1132 | { | 1144 | { |
1133 | struct kretprobe_instance *ri; | 1145 | struct kretprobe_instance *ri; |
1134 | struct hlist_head *head, empty_rp; | 1146 | struct hlist_head *head, empty_rp; |
@@ -1153,6 +1165,7 @@ void __kprobes kprobe_flush_task(struct task_struct *tk) | |||
1153 | kfree(ri); | 1165 | kfree(ri); |
1154 | } | 1166 | } |
1155 | } | 1167 | } |
1168 | NOKPROBE_SYMBOL(kprobe_flush_task); | ||
1156 | 1169 | ||
1157 | static inline void free_rp_inst(struct kretprobe *rp) | 1170 | static inline void free_rp_inst(struct kretprobe *rp) |
1158 | { | 1171 | { |
@@ -1165,7 +1178,7 @@ static inline void free_rp_inst(struct kretprobe *rp) | |||
1165 | } | 1178 | } |
1166 | } | 1179 | } |
1167 | 1180 | ||
1168 | static void __kprobes cleanup_rp_inst(struct kretprobe *rp) | 1181 | static void cleanup_rp_inst(struct kretprobe *rp) |
1169 | { | 1182 | { |
1170 | unsigned long flags, hash; | 1183 | unsigned long flags, hash; |
1171 | struct kretprobe_instance *ri; | 1184 | struct kretprobe_instance *ri; |
@@ -1184,6 +1197,7 @@ static void __kprobes cleanup_rp_inst(struct kretprobe *rp) | |||
1184 | } | 1197 | } |
1185 | free_rp_inst(rp); | 1198 | free_rp_inst(rp); |
1186 | } | 1199 | } |
1200 | NOKPROBE_SYMBOL(cleanup_rp_inst); | ||
1187 | 1201 | ||
1188 | /* | 1202 | /* |
1189 | * Add the new probe to ap->list. Fail if this is the | 1203 | * Add the new probe to ap->list. Fail if this is the |
@@ -1758,8 +1772,7 @@ EXPORT_SYMBOL_GPL(unregister_jprobes); | |||
1758 | * This kprobe pre_handler is registered with every kretprobe. When probe | 1772 | * This kprobe pre_handler is registered with every kretprobe. When probe |
1759 | * hits it will set up the return probe. | 1773 | * hits it will set up the return probe. |
1760 | */ | 1774 | */ |
1761 | static int __kprobes pre_handler_kretprobe(struct kprobe *p, | 1775 | static int pre_handler_kretprobe(struct kprobe *p, struct pt_regs *regs) |
1762 | struct pt_regs *regs) | ||
1763 | { | 1776 | { |
1764 | struct kretprobe *rp = container_of(p, struct kretprobe, kp); | 1777 | struct kretprobe *rp = container_of(p, struct kretprobe, kp); |
1765 | unsigned long hash, flags = 0; | 1778 | unsigned long hash, flags = 0; |
@@ -1797,6 +1810,7 @@ static int __kprobes pre_handler_kretprobe(struct kprobe *p, | |||
1797 | } | 1810 | } |
1798 | return 0; | 1811 | return 0; |
1799 | } | 1812 | } |
1813 | NOKPROBE_SYMBOL(pre_handler_kretprobe); | ||
1800 | 1814 | ||
1801 | int register_kretprobe(struct kretprobe *rp) | 1815 | int register_kretprobe(struct kretprobe *rp) |
1802 | { | 1816 | { |
@@ -1920,11 +1934,11 @@ void unregister_kretprobes(struct kretprobe **rps, int num) | |||
1920 | } | 1934 | } |
1921 | EXPORT_SYMBOL_GPL(unregister_kretprobes); | 1935 | EXPORT_SYMBOL_GPL(unregister_kretprobes); |
1922 | 1936 | ||
1923 | static int __kprobes pre_handler_kretprobe(struct kprobe *p, | 1937 | static int pre_handler_kretprobe(struct kprobe *p, struct pt_regs *regs) |
1924 | struct pt_regs *regs) | ||
1925 | { | 1938 | { |
1926 | return 0; | 1939 | return 0; |
1927 | } | 1940 | } |
1941 | NOKPROBE_SYMBOL(pre_handler_kretprobe); | ||
1928 | 1942 | ||
1929 | #endif /* CONFIG_KRETPROBES */ | 1943 | #endif /* CONFIG_KRETPROBES */ |
1930 | 1944 | ||
@@ -2002,12 +2016,13 @@ out: | |||
2002 | } | 2016 | } |
2003 | EXPORT_SYMBOL_GPL(enable_kprobe); | 2017 | EXPORT_SYMBOL_GPL(enable_kprobe); |
2004 | 2018 | ||
2005 | void __kprobes dump_kprobe(struct kprobe *kp) | 2019 | void dump_kprobe(struct kprobe *kp) |
2006 | { | 2020 | { |
2007 | printk(KERN_WARNING "Dumping kprobe:\n"); | 2021 | printk(KERN_WARNING "Dumping kprobe:\n"); |
2008 | printk(KERN_WARNING "Name: %s\nAddress: %p\nOffset: %x\n", | 2022 | printk(KERN_WARNING "Name: %s\nAddress: %p\nOffset: %x\n", |
2009 | kp->symbol_name, kp->addr, kp->offset); | 2023 | kp->symbol_name, kp->addr, kp->offset); |
2010 | } | 2024 | } |
2025 | NOKPROBE_SYMBOL(dump_kprobe); | ||
2011 | 2026 | ||
2012 | /* | 2027 | /* |
2013 | * Lookup and populate the kprobe_blacklist. | 2028 | * Lookup and populate the kprobe_blacklist. |