Commit | Line | Data |
---|---|---|
1a59d1b8 | 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
1da177e4 LT |
2 | #ifndef _LINUX_KPROBES_H |
3 | #define _LINUX_KPROBES_H | |
4 | /* | |
5 | * Kernel Probes (KProbes) | |
1da177e4 | 6 | * |
1da177e4 LT |
7 | * Copyright (C) IBM Corporation, 2002, 2004 |
8 | * | |
9 | * 2002-Oct Created by Vamsi Krishna S <vamsi_krishna@in.ibm.com> Kernel | |
10 | * Probes initial implementation ( includes suggestions from | |
11 | * Rusty Russell). | |
12 | * 2004-July Suparna Bhattacharya <suparna@in.ibm.com> added jumper probes | |
13 | * interface to access function arguments. | |
b94cce92 HN |
14 | * 2005-May Hien Nguyen <hien@us.ibm.com> and Jim Keniston |
15 | * <jkenisto@us.ibm.com> and Prasanna S Panchamukhi | |
16 | * <prasanna@in.ibm.com> added function-return probes. | |
1da177e4 | 17 | */ |
7d134b2c | 18 | #include <linux/compiler.h> |
36dcd67a | 19 | #include <linux/linkage.h> |
1da177e4 LT |
20 | #include <linux/list.h> |
21 | #include <linux/notifier.h> | |
22 | #include <linux/smp.h> | |
187f1882 | 23 | #include <linux/bug.h> |
e6584523 | 24 | #include <linux/percpu.h> |
3516a460 AM |
25 | #include <linux/spinlock.h> |
26 | #include <linux/rcupdate.h> | |
7a7d1cf9 | 27 | #include <linux/mutex.h> |
ae6aa16f | 28 | #include <linux/ftrace.h> |
d741bf41 | 29 | #include <linux/refcount.h> |
6e426e0f | 30 | #include <linux/freelist.h> |
73f9b911 | 31 | #include <linux/rethook.h> |
7d134b2c | 32 | #include <asm/kprobes.h> |
b94cce92 | 33 | |
00d7c05a | 34 | #ifdef CONFIG_KPROBES |
1da177e4 | 35 | |
ea32c65c PP |
36 | /* kprobe_status settings */ |
37 | #define KPROBE_HIT_ACTIVE 0x00000001 | |
38 | #define KPROBE_HIT_SS 0x00000002 | |
39 | #define KPROBE_REENTER 0x00000004 | |
40 | #define KPROBE_HIT_SSDONE 0x00000008 | |
41 | ||
223a76b2 | 42 | #else /* !CONFIG_KPROBES */ |
7d134b2c | 43 | #include <asm-generic/kprobes.h> |
dc19835d MH |
44 | typedef int kprobe_opcode_t; |
45 | struct arch_specific_insn { | |
46 | int dummy; | |
47 | }; | |
dc19835d | 48 | #endif /* CONFIG_KPROBES */ |
d0aaff97 | 49 | |
1da177e4 LT |
50 | struct kprobe; |
51 | struct pt_regs; | |
b94cce92 HN |
52 | struct kretprobe; |
53 | struct kretprobe_instance; | |
1da177e4 | 54 | typedef int (*kprobe_pre_handler_t) (struct kprobe *, struct pt_regs *); |
1da177e4 LT |
55 | typedef void (*kprobe_post_handler_t) (struct kprobe *, struct pt_regs *, |
56 | unsigned long flags); | |
b94cce92 HN |
57 | typedef int (*kretprobe_handler_t) (struct kretprobe_instance *, |
58 | struct pt_regs *); | |
59 | ||
1da177e4 LT |
60 | struct kprobe { |
61 | struct hlist_node hlist; | |
62 | ||
64f562c6 AM |
63 | /* list of kprobes for multi-handler support */ |
64 | struct list_head list; | |
65 | ||
ea32c65c PP |
66 | /*count the number of times this probe was temporarily disarmed */ |
67 | unsigned long nmissed; | |
68 | ||
1da177e4 LT |
69 | /* location of the probe point */ |
70 | kprobe_opcode_t *addr; | |
71 | ||
3a872d89 | 72 | /* Allow user to indicate symbol name of the probe point */ |
9b3af29b | 73 | const char *symbol_name; |
3a872d89 AM |
74 | |
75 | /* Offset into the symbol */ | |
76 | unsigned int offset; | |
77 | ||
1da177e4 LT |
78 | /* Called before addr is executed. */ |
79 | kprobe_pre_handler_t pre_handler; | |
80 | ||
81 | /* Called after addr is executed, unless... */ | |
82 | kprobe_post_handler_t post_handler; | |
83 | ||
1da177e4 LT |
84 | /* Saved opcode (which has been replaced with breakpoint) */ |
85 | kprobe_opcode_t opcode; | |
86 | ||
87 | /* copy of the original instruction */ | |
88 | struct arch_specific_insn ainsn; | |
e8386a0c | 89 | |
de5bd88d MH |
90 | /* |
91 | * Indicates various status flags. | |
92 | * Protected by kprobe_mutex after this kprobe is registered. | |
93 | */ | |
e8386a0c | 94 | u32 flags; |
1da177e4 LT |
95 | }; |
96 | ||
e8386a0c MH |
97 | /* Kprobe status flags */ |
98 | #define KPROBE_FLAG_GONE 1 /* breakpoint has already gone */ | |
de5bd88d | 99 | #define KPROBE_FLAG_DISABLED 2 /* probe is temporarily disabled */ |
afd66255 MH |
100 | #define KPROBE_FLAG_OPTIMIZED 4 /* |
101 | * probe is really optimized. | |
102 | * NOTE: | |
103 | * this flag is only for optimized_kprobe. | |
104 | */ | |
ae6aa16f | 105 | #define KPROBE_FLAG_FTRACE 8 /* probe is using ftrace */ |
bf7a87f1 | 106 | #define KPROBE_FLAG_ON_FUNC_ENTRY 16 /* probe is on the function entry */ |
e8386a0c | 107 | |
de5bd88d | 108 | /* Has this kprobe gone ? */ |
29e8077a | 109 | static inline bool kprobe_gone(struct kprobe *p) |
e8386a0c MH |
110 | { |
111 | return p->flags & KPROBE_FLAG_GONE; | |
112 | } | |
113 | ||
de5bd88d | 114 | /* Is this kprobe disabled ? */ |
29e8077a | 115 | static inline bool kprobe_disabled(struct kprobe *p) |
de5bd88d MH |
116 | { |
117 | return p->flags & (KPROBE_FLAG_DISABLED | KPROBE_FLAG_GONE); | |
118 | } | |
afd66255 MH |
119 | |
120 | /* Is this kprobe really running optimized path ? */ | |
29e8077a | 121 | static inline bool kprobe_optimized(struct kprobe *p) |
afd66255 MH |
122 | { |
123 | return p->flags & KPROBE_FLAG_OPTIMIZED; | |
124 | } | |
ae6aa16f MH |
125 | |
126 | /* Is this kprobe uses ftrace ? */ | |
29e8077a | 127 | static inline bool kprobe_ftrace(struct kprobe *p) |
ae6aa16f MH |
128 | { |
129 | return p->flags & KPROBE_FLAG_FTRACE; | |
130 | } | |
131 | ||
b94cce92 HN |
132 | /* |
133 | * Function-return probe - | |
134 | * Note: | |
135 | * User needs to provide a handler function, and initialize maxactive. | |
136 | * maxactive - The maximum number of instances of the probed function that | |
137 | * can be active concurrently. | |
138 | * nmissed - tracks the number of times the probed function's return was | |
139 | * ignored, due to maxactive being too low. | |
140 | * | |
141 | */ | |
d741bf41 PZ |
142 | struct kretprobe_holder { |
143 | struct kretprobe *rp; | |
144 | refcount_t ref; | |
145 | }; | |
146 | ||
b94cce92 HN |
147 | struct kretprobe { |
148 | struct kprobe kp; | |
149 | kretprobe_handler_t handler; | |
f47cd9b5 | 150 | kretprobe_handler_t entry_handler; |
b94cce92 HN |
151 | int maxactive; |
152 | int nmissed; | |
f47cd9b5 | 153 | size_t data_size; |
73f9b911 MH |
154 | #ifdef CONFIG_KRETPROBE_ON_RETHOOK |
155 | struct rethook *rh; | |
156 | #else | |
6e426e0f | 157 | struct freelist_head freelist; |
d741bf41 | 158 | struct kretprobe_holder *rph; |
73f9b911 | 159 | #endif |
b94cce92 HN |
160 | }; |
161 | ||
6bbfa441 MH |
162 | #define KRETPROBE_MAX_DATA_SIZE 4096 |
163 | ||
b94cce92 | 164 | struct kretprobe_instance { |
73f9b911 MH |
165 | #ifdef CONFIG_KRETPROBE_ON_RETHOOK |
166 | struct rethook_node node; | |
167 | #else | |
b3388178 | 168 | union { |
6e426e0f | 169 | struct freelist_node freelist; |
b3388178 MH |
170 | struct rcu_head rcu; |
171 | }; | |
6e426e0f | 172 | struct llist_node llist; |
d741bf41 | 173 | struct kretprobe_holder *rph; |
802eae7c | 174 | kprobe_opcode_t *ret_addr; |
3ff9c075 | 175 | void *fp; |
73f9b911 | 176 | #endif |
67a862a9 | 177 | char data[]; |
b94cce92 HN |
178 | }; |
179 | ||
f438d914 MH |
180 | struct kretprobe_blackpoint { |
181 | const char *name; | |
182 | void *addr; | |
183 | }; | |
3d8d996e | 184 | |
376e2424 MH |
185 | struct kprobe_blacklist_entry { |
186 | struct list_head list; | |
3d8d996e | 187 | unsigned long start_addr; |
376e2424 | 188 | unsigned long end_addr; |
3d8d996e SD |
189 | }; |
190 | ||
dc19835d MH |
191 | #ifdef CONFIG_KPROBES |
192 | DECLARE_PER_CPU(struct kprobe *, current_kprobe); | |
193 | DECLARE_PER_CPU(struct kprobe_ctlblk, kprobe_ctlblk); | |
194 | ||
66ada2cc MH |
195 | extern void kprobe_busy_begin(void); |
196 | extern void kprobe_busy_end(void); | |
197 | ||
dc19835d | 198 | #ifdef CONFIG_KRETPROBES |
73f9b911 | 199 | /* Check whether @p is used for implementing a trampoline. */ |
dc19835d | 200 | extern int arch_trampoline_kprobe(struct kprobe *p); |
66ada2cc | 201 | |
73f9b911 MH |
202 | #ifdef CONFIG_KRETPROBE_ON_RETHOOK |
203 | static nokprobe_inline struct kretprobe *get_kretprobe(struct kretprobe_instance *ri) | |
204 | { | |
205 | RCU_LOCKDEP_WARN(!rcu_read_lock_any_held(), | |
206 | "Kretprobe is accessed from instance under preemptive context"); | |
207 | ||
208 | return (struct kretprobe *)READ_ONCE(ri->node.rethook->data); | |
209 | } | |
210 | static nokprobe_inline unsigned long get_kretprobe_retaddr(struct kretprobe_instance *ri) | |
211 | { | |
212 | return ri->node.ret_addr; | |
213 | } | |
214 | #else | |
215 | extern void arch_prepare_kretprobe(struct kretprobe_instance *ri, | |
216 | struct pt_regs *regs); | |
bf094cff MH |
217 | void arch_kretprobe_fixup_return(struct pt_regs *regs, |
218 | kprobe_opcode_t *correct_ret_addr); | |
219 | ||
adf8a61a | 220 | void __kretprobe_trampoline(void); |
96fed8ac MH |
221 | /* |
222 | * Since some architecture uses structured function pointer, | |
223 | * use dereference_function_descriptor() to get real function address. | |
224 | */ | |
225 | static nokprobe_inline void *kretprobe_trampoline_addr(void) | |
226 | { | |
adf8a61a | 227 | return dereference_kernel_function_descriptor(__kretprobe_trampoline); |
96fed8ac MH |
228 | } |
229 | ||
66ada2cc MH |
230 | /* If the trampoline handler called from a kprobe, use this version */ |
231 | unsigned long __kretprobe_trampoline_handler(struct pt_regs *regs, | |
96fed8ac | 232 | void *frame_pointer); |
66ada2cc MH |
233 | |
234 | static nokprobe_inline | |
235 | unsigned long kretprobe_trampoline_handler(struct pt_regs *regs, | |
96fed8ac | 236 | void *frame_pointer) |
66ada2cc MH |
237 | { |
238 | unsigned long ret; | |
239 | /* | |
240 | * Set a dummy kprobe for avoiding kretprobe recursion. | |
241 | * Since kretprobe never runs in kprobe handler, no kprobe must | |
242 | * be running at this point. | |
243 | */ | |
244 | kprobe_busy_begin(); | |
96fed8ac | 245 | ret = __kretprobe_trampoline_handler(regs, frame_pointer); |
66ada2cc MH |
246 | kprobe_busy_end(); |
247 | ||
248 | return ret; | |
249 | } | |
250 | ||
d741bf41 PZ |
251 | static nokprobe_inline struct kretprobe *get_kretprobe(struct kretprobe_instance *ri) |
252 | { | |
253 | RCU_LOCKDEP_WARN(!rcu_read_lock_any_held(), | |
254 | "Kretprobe is accessed from instance under preemptive context"); | |
255 | ||
256 | return READ_ONCE(ri->rph->rp); | |
257 | } | |
258 | ||
73f9b911 MH |
259 | static nokprobe_inline unsigned long get_kretprobe_retaddr(struct kretprobe_instance *ri) |
260 | { | |
261 | return (unsigned long)ri->ret_addr; | |
262 | } | |
263 | #endif /* CONFIG_KRETPROBE_ON_RETHOOK */ | |
264 | ||
223a76b2 | 265 | #else /* !CONFIG_KRETPROBES */ |
dc19835d MH |
266 | static inline void arch_prepare_kretprobe(struct kretprobe *rp, |
267 | struct pt_regs *regs) | |
268 | { | |
269 | } | |
270 | static inline int arch_trampoline_kprobe(struct kprobe *p) | |
271 | { | |
272 | return 0; | |
273 | } | |
274 | #endif /* CONFIG_KRETPROBES */ | |
275 | ||
223a76b2 MH |
276 | /* Markers of '_kprobe_blacklist' section */ |
277 | extern unsigned long __start_kprobe_blacklist[]; | |
278 | extern unsigned long __stop_kprobe_blacklist[]; | |
279 | ||
f438d914 MH |
280 | extern struct kretprobe_blackpoint kretprobe_blacklist[]; |
281 | ||
8c1c9356 AM |
282 | #ifdef CONFIG_KPROBES_SANITY_TEST |
283 | extern int init_test_probes(void); | |
223a76b2 | 284 | #else /* !CONFIG_KPROBES_SANITY_TEST */ |
8c1c9356 AM |
285 | static inline int init_test_probes(void) |
286 | { | |
287 | return 0; | |
288 | } | |
289 | #endif /* CONFIG_KPROBES_SANITY_TEST */ | |
290 | ||
1da177e4 | 291 | extern int arch_prepare_kprobe(struct kprobe *p); |
7e1048b1 RL |
292 | extern void arch_arm_kprobe(struct kprobe *p); |
293 | extern void arch_disarm_kprobe(struct kprobe *p); | |
6772926b | 294 | extern int arch_init_kprobes(void); |
bf8d5c52 | 295 | extern void kprobes_inc_nmissed_count(struct kprobe *p); |
be8f2743 | 296 | extern bool arch_within_kprobe_blacklist(unsigned long addr); |
fb1a59fa | 297 | extern int arch_populate_kprobe_blacklist(void); |
97c753e6 | 298 | extern int kprobe_on_func_entry(kprobe_opcode_t *addr, const char *sym, unsigned long offset); |
1da177e4 | 299 | |
e5779e8e | 300 | extern bool within_kprobe_blacklist(unsigned long addr); |
fb1a59fa MH |
301 | extern int kprobe_add_ksym_blacklist(unsigned long entry); |
302 | extern int kprobe_add_area_blacklist(unsigned long start, unsigned long end); | |
e5779e8e | 303 | |
c802d64a HC |
304 | struct kprobe_insn_cache { |
305 | struct mutex mutex; | |
af96397d HC |
306 | void *(*alloc)(void); /* allocate insn page */ |
307 | void (*free)(void *); /* free insn page */ | |
d002b8bc | 308 | const char *sym; /* symbol for insn pages */ |
c802d64a HC |
309 | struct list_head pages; /* list of kprobe_insn_page */ |
310 | size_t insn_size; /* size of instruction slot */ | |
311 | int nr_garbage; | |
312 | }; | |
313 | ||
5b485629 | 314 | #ifdef __ARCH_WANT_KPROBES_INSN_SLOT |
c802d64a HC |
315 | extern kprobe_opcode_t *__get_insn_slot(struct kprobe_insn_cache *c); |
316 | extern void __free_insn_slot(struct kprobe_insn_cache *c, | |
317 | kprobe_opcode_t *slot, int dirty); | |
5b485629 MH |
318 | /* sleep-less address checking routine */ |
319 | extern bool __is_insn_slot_addr(struct kprobe_insn_cache *c, | |
320 | unsigned long addr); | |
c802d64a HC |
321 | |
322 | #define DEFINE_INSN_CACHE_OPS(__name) \ | |
323 | extern struct kprobe_insn_cache kprobe_##__name##_slots; \ | |
324 | \ | |
325 | static inline kprobe_opcode_t *get_##__name##_slot(void) \ | |
326 | { \ | |
327 | return __get_insn_slot(&kprobe_##__name##_slots); \ | |
328 | } \ | |
329 | \ | |
330 | static inline void free_##__name##_slot(kprobe_opcode_t *slot, int dirty)\ | |
331 | { \ | |
332 | __free_insn_slot(&kprobe_##__name##_slots, slot, dirty); \ | |
333 | } \ | |
5b485629 MH |
334 | \ |
335 | static inline bool is_kprobe_##__name##_slot(unsigned long addr) \ | |
336 | { \ | |
337 | return __is_insn_slot_addr(&kprobe_##__name##_slots, addr); \ | |
338 | } | |
d002b8bc AH |
339 | #define KPROBE_INSN_PAGE_SYM "kprobe_insn_page" |
340 | #define KPROBE_OPTINSN_PAGE_SYM "kprobe_optinsn_page" | |
341 | int kprobe_cache_get_kallsym(struct kprobe_insn_cache *c, unsigned int *symnum, | |
342 | unsigned long *value, char *type, char *sym); | |
223a76b2 | 343 | #else /* !__ARCH_WANT_KPROBES_INSN_SLOT */ |
5b485629 MH |
344 | #define DEFINE_INSN_CACHE_OPS(__name) \ |
345 | static inline bool is_kprobe_##__name##_slot(unsigned long addr) \ | |
346 | { \ | |
347 | return 0; \ | |
348 | } | |
349 | #endif | |
c802d64a HC |
350 | |
351 | DEFINE_INSN_CACHE_OPS(insn); | |
352 | ||
afd66255 MH |
353 | #ifdef CONFIG_OPTPROBES |
354 | /* | |
355 | * Internal structure for direct jump optimized probe | |
356 | */ | |
357 | struct optimized_kprobe { | |
358 | struct kprobe kp; | |
359 | struct list_head list; /* list for optimizing queue */ | |
360 | struct arch_optimized_insn optinsn; | |
361 | }; | |
362 | ||
363 | /* Architecture dependent functions for direct jump optimization */ | |
364 | extern int arch_prepared_optinsn(struct arch_optimized_insn *optinsn); | |
365 | extern int arch_check_optimized_kprobe(struct optimized_kprobe *op); | |
cbf6ab52 MH |
366 | extern int arch_prepare_optimized_kprobe(struct optimized_kprobe *op, |
367 | struct kprobe *orig); | |
afd66255 | 368 | extern void arch_remove_optimized_kprobe(struct optimized_kprobe *op); |
cd7ebe22 | 369 | extern void arch_optimize_kprobes(struct list_head *oplist); |
f984ba4e MH |
370 | extern void arch_unoptimize_kprobes(struct list_head *oplist, |
371 | struct list_head *done_list); | |
afd66255 | 372 | extern void arch_unoptimize_kprobe(struct optimized_kprobe *op); |
afd66255 | 373 | extern int arch_within_optimized_kprobe(struct optimized_kprobe *op, |
c42421e2 | 374 | kprobe_opcode_t *addr); |
afd66255 MH |
375 | |
376 | extern void opt_pre_handler(struct kprobe *p, struct pt_regs *regs); | |
b2be84df | 377 | |
c802d64a HC |
378 | DEFINE_INSN_CACHE_OPS(optinsn); |
379 | ||
30e7d894 | 380 | extern void wait_for_kprobe_optimizer(void); |
868a6fc0 | 381 | bool optprobe_queued_unopt(struct optimized_kprobe *op); |
f1c97a1b | 382 | bool kprobe_disarmed(struct kprobe *p); |
223a76b2 | 383 | #else /* !CONFIG_OPTPROBES */ |
30e7d894 | 384 | static inline void wait_for_kprobe_optimizer(void) { } |
afd66255 | 385 | #endif /* CONFIG_OPTPROBES */ |
223a76b2 | 386 | |
e7dbfe34 | 387 | #ifdef CONFIG_KPROBES_ON_FTRACE |
ae6aa16f | 388 | extern void kprobe_ftrace_handler(unsigned long ip, unsigned long parent_ip, |
d19ad077 | 389 | struct ftrace_ops *ops, struct ftrace_regs *fregs); |
ae6aa16f | 390 | extern int arch_prepare_kprobe_ftrace(struct kprobe *p); |
02afb8d6 PA |
391 | #else |
392 | static inline int arch_prepare_kprobe_ftrace(struct kprobe *p) | |
393 | { | |
394 | return -EINVAL; | |
395 | } | |
223a76b2 | 396 | #endif /* CONFIG_KPROBES_ON_FTRACE */ |
ae6aa16f | 397 | |
d217d545 | 398 | /* Get the kprobe at this addr (if any) - called with preemption disabled */ |
1da177e4 LT |
399 | struct kprobe *get_kprobe(void *addr); |
400 | ||
e6584523 AM |
401 | /* kprobe_running() will just return the current_kprobe on this CPU */ |
402 | static inline struct kprobe *kprobe_running(void) | |
403 | { | |
223a76b2 | 404 | return __this_cpu_read(current_kprobe); |
e6584523 AM |
405 | } |
406 | ||
407 | static inline void reset_current_kprobe(void) | |
408 | { | |
b76834bc | 409 | __this_cpu_write(current_kprobe, NULL); |
e6584523 AM |
410 | } |
411 | ||
412 | static inline struct kprobe_ctlblk *get_kprobe_ctlblk(void) | |
413 | { | |
bdffd893 | 414 | return this_cpu_ptr(&kprobe_ctlblk); |
e6584523 AM |
415 | } |
416 | ||
290e3070 | 417 | kprobe_opcode_t *kprobe_lookup_name(const char *name, unsigned int offset); |
cc66bb91 PZ |
418 | kprobe_opcode_t *arch_adjust_kprobe_addr(unsigned long addr, unsigned long offset, bool *on_func_entry); |
419 | ||
1da177e4 LT |
420 | int register_kprobe(struct kprobe *p); |
421 | void unregister_kprobe(struct kprobe *p); | |
9861668f MH |
422 | int register_kprobes(struct kprobe **kps, int num); |
423 | void unregister_kprobes(struct kprobe **kps, int num); | |
1da177e4 | 424 | |
b94cce92 HN |
425 | int register_kretprobe(struct kretprobe *rp); |
426 | void unregister_kretprobe(struct kretprobe *rp); | |
4a296e07 MH |
427 | int register_kretprobes(struct kretprobe **rps, int num); |
428 | void unregister_kretprobes(struct kretprobe **rps, int num); | |
b94cce92 | 429 | |
43994049 | 430 | #if defined(CONFIG_KRETPROBE_ON_RETHOOK) || !defined(CONFIG_KRETPROBES) |
73f9b911 MH |
431 | #define kprobe_flush_task(tk) do {} while (0) |
432 | #else | |
b94cce92 | 433 | void kprobe_flush_task(struct task_struct *tk); |
73f9b911 | 434 | #endif |
8c1c9356 | 435 | |
82d083ab MH |
436 | void kprobe_free_init_mem(void); |
437 | ||
de5bd88d MH |
438 | int disable_kprobe(struct kprobe *kp); |
439 | int enable_kprobe(struct kprobe *kp); | |
440 | ||
24851d24 FW |
441 | void dump_kprobe(struct kprobe *kp); |
442 | ||
ad3bc25a | 443 | void *alloc_insn_page(void); |
ad3bc25a | 444 | |
7ee3e97e CL |
445 | void *alloc_optinsn_page(void); |
446 | void free_optinsn_page(void *page); | |
447 | ||
d002b8bc AH |
448 | int kprobe_get_kallsym(unsigned int symnum, unsigned long *value, char *type, |
449 | char *sym); | |
450 | ||
451 | int arch_kprobe_get_kallsym(unsigned int *symnum, unsigned long *value, | |
452 | char *type, char *sym); | |
b1801812 | 453 | #else /* !CONFIG_KPROBES: */ |
00d7c05a | 454 | |
b1801812 IM |
455 | static inline int kprobe_fault_handler(struct pt_regs *regs, int trapnr) |
456 | { | |
457 | return 0; | |
458 | } | |
785656a4 AS |
459 | static inline struct kprobe *get_kprobe(void *addr) |
460 | { | |
461 | return NULL; | |
462 | } | |
e6584523 | 463 | static inline struct kprobe *kprobe_running(void) |
1da177e4 | 464 | { |
e6584523 | 465 | return NULL; |
1da177e4 | 466 | } |
ab51e15d MH |
467 | #define kprobe_busy_begin() do {} while (0) |
468 | #define kprobe_busy_end() do {} while (0) | |
469 | ||
1da177e4 LT |
470 | static inline int register_kprobe(struct kprobe *p) |
471 | { | |
223a76b2 | 472 | return -EOPNOTSUPP; |
1da177e4 | 473 | } |
9861668f MH |
474 | static inline int register_kprobes(struct kprobe **kps, int num) |
475 | { | |
223a76b2 | 476 | return -EOPNOTSUPP; |
9861668f | 477 | } |
1da177e4 LT |
478 | static inline void unregister_kprobe(struct kprobe *p) |
479 | { | |
480 | } | |
9861668f MH |
481 | static inline void unregister_kprobes(struct kprobe **kps, int num) |
482 | { | |
483 | } | |
b94cce92 HN |
484 | static inline int register_kretprobe(struct kretprobe *rp) |
485 | { | |
223a76b2 | 486 | return -EOPNOTSUPP; |
b94cce92 | 487 | } |
4a296e07 MH |
488 | static inline int register_kretprobes(struct kretprobe **rps, int num) |
489 | { | |
223a76b2 | 490 | return -EOPNOTSUPP; |
4a296e07 | 491 | } |
b94cce92 HN |
492 | static inline void unregister_kretprobe(struct kretprobe *rp) |
493 | { | |
494 | } | |
4a296e07 MH |
495 | static inline void unregister_kretprobes(struct kretprobe **rps, int num) |
496 | { | |
497 | } | |
b94cce92 HN |
498 | static inline void kprobe_flush_task(struct task_struct *tk) |
499 | { | |
500 | } | |
82d083ab MH |
501 | static inline void kprobe_free_init_mem(void) |
502 | { | |
503 | } | |
de5bd88d MH |
504 | static inline int disable_kprobe(struct kprobe *kp) |
505 | { | |
223a76b2 | 506 | return -EOPNOTSUPP; |
de5bd88d MH |
507 | } |
508 | static inline int enable_kprobe(struct kprobe *kp) | |
509 | { | |
223a76b2 | 510 | return -EOPNOTSUPP; |
de5bd88d | 511 | } |
fab94075 BP |
512 | |
513 | static inline bool within_kprobe_blacklist(unsigned long addr) | |
514 | { | |
515 | return true; | |
516 | } | |
d002b8bc AH |
517 | static inline int kprobe_get_kallsym(unsigned int symnum, unsigned long *value, |
518 | char *type, char *sym) | |
519 | { | |
520 | return -ERANGE; | |
521 | } | |
b1801812 | 522 | #endif /* CONFIG_KPROBES */ |
223a76b2 | 523 | |
8f9b1528 MH |
524 | static inline int disable_kretprobe(struct kretprobe *rp) |
525 | { | |
526 | return disable_kprobe(&rp->kp); | |
527 | } | |
528 | static inline int enable_kretprobe(struct kretprobe *rp) | |
529 | { | |
530 | return enable_kprobe(&rp->kp); | |
531 | } | |
8f9b1528 | 532 | |
5b485629 MH |
533 | #ifndef CONFIG_KPROBES |
534 | static inline bool is_kprobe_insn_slot(unsigned long addr) | |
535 | { | |
536 | return false; | |
537 | } | |
223a76b2 MH |
538 | #endif /* !CONFIG_KPROBES */ |
539 | ||
5b485629 MH |
540 | #ifndef CONFIG_OPTPROBES |
541 | static inline bool is_kprobe_optinsn_slot(unsigned long addr) | |
542 | { | |
543 | return false; | |
544 | } | |
223a76b2 | 545 | #endif /* !CONFIG_OPTPROBES */ |
5b485629 | 546 | |
03bac0df | 547 | #ifdef CONFIG_KRETPROBES |
73f9b911 MH |
548 | #ifdef CONFIG_KRETPROBE_ON_RETHOOK |
549 | static nokprobe_inline bool is_kretprobe_trampoline(unsigned long addr) | |
550 | { | |
551 | return is_rethook_trampoline(addr); | |
552 | } | |
553 | ||
554 | static nokprobe_inline | |
555 | unsigned long kretprobe_find_ret_addr(struct task_struct *tsk, void *fp, | |
556 | struct llist_node **cur) | |
557 | { | |
558 | return rethook_find_ret_addr(tsk, (unsigned long)fp, cur); | |
559 | } | |
560 | #else | |
03bac0df MH |
561 | static nokprobe_inline bool is_kretprobe_trampoline(unsigned long addr) |
562 | { | |
563 | return (void *)addr == kretprobe_trampoline_addr(); | |
564 | } | |
565 | ||
566 | unsigned long kretprobe_find_ret_addr(struct task_struct *tsk, void *fp, | |
567 | struct llist_node **cur); | |
73f9b911 | 568 | #endif |
03bac0df MH |
569 | #else |
570 | static nokprobe_inline bool is_kretprobe_trampoline(unsigned long addr) | |
571 | { | |
572 | return false; | |
573 | } | |
574 | ||
575 | static nokprobe_inline | |
576 | unsigned long kretprobe_find_ret_addr(struct task_struct *tsk, void *fp, | |
577 | struct llist_node **cur) | |
578 | { | |
579 | return 0; | |
580 | } | |
581 | #endif | |
582 | ||
b98cca44 AK |
583 | /* Returns true if kprobes handled the fault */ |
584 | static nokprobe_inline bool kprobe_page_fault(struct pt_regs *regs, | |
585 | unsigned int trap) | |
586 | { | |
dfc05b55 | 587 | if (!IS_ENABLED(CONFIG_KPROBES)) |
b98cca44 AK |
588 | return false; |
589 | if (user_mode(regs)) | |
590 | return false; | |
591 | /* | |
592 | * To be potentially processing a kprobe fault and to be allowed | |
593 | * to call kprobe_running(), we have to be non-preemptible. | |
594 | */ | |
595 | if (preemptible()) | |
596 | return false; | |
597 | if (!kprobe_running()) | |
598 | return false; | |
599 | return kprobe_fault_handler(regs, trap); | |
600 | } | |
601 | ||
b1801812 | 602 | #endif /* _LINUX_KPROBES_H */ |