aboutsummaryrefslogtreecommitdiffstats
path: root/arch/x86_64/kernel/kprobes.c
diff options
context:
space:
mode:
Diffstat (limited to 'arch/x86_64/kernel/kprobes.c')
-rw-r--r--arch/x86_64/kernel/kprobes.c41
1 files changed, 23 insertions, 18 deletions
diff --git a/arch/x86_64/kernel/kprobes.c b/arch/x86_64/kernel/kprobes.c
index 5c6dc7051482..df08c43276a0 100644
--- a/arch/x86_64/kernel/kprobes.c
+++ b/arch/x86_64/kernel/kprobes.c
@@ -74,7 +74,7 @@ static inline int is_IF_modifier(kprobe_opcode_t *insn)
74 return 0; 74 return 0;
75} 75}
76 76
77int arch_prepare_kprobe(struct kprobe *p) 77int __kprobes arch_prepare_kprobe(struct kprobe *p)
78{ 78{
79 /* insn: must be on special executable page on x86_64. */ 79 /* insn: must be on special executable page on x86_64. */
80 up(&kprobe_mutex); 80 up(&kprobe_mutex);
@@ -189,7 +189,7 @@ static inline s32 *is_riprel(u8 *insn)
189 return NULL; 189 return NULL;
190} 190}
191 191
192void arch_copy_kprobe(struct kprobe *p) 192void __kprobes arch_copy_kprobe(struct kprobe *p)
193{ 193{
194 s32 *ripdisp; 194 s32 *ripdisp;
195 memcpy(p->ainsn.insn, p->addr, MAX_INSN_SIZE); 195 memcpy(p->ainsn.insn, p->addr, MAX_INSN_SIZE);
@@ -215,21 +215,21 @@ void arch_copy_kprobe(struct kprobe *p)
215 p->opcode = *p->addr; 215 p->opcode = *p->addr;
216} 216}
217 217
218void arch_arm_kprobe(struct kprobe *p) 218void __kprobes arch_arm_kprobe(struct kprobe *p)
219{ 219{
220 *p->addr = BREAKPOINT_INSTRUCTION; 220 *p->addr = BREAKPOINT_INSTRUCTION;
221 flush_icache_range((unsigned long) p->addr, 221 flush_icache_range((unsigned long) p->addr,
222 (unsigned long) p->addr + sizeof(kprobe_opcode_t)); 222 (unsigned long) p->addr + sizeof(kprobe_opcode_t));
223} 223}
224 224
225void arch_disarm_kprobe(struct kprobe *p) 225void __kprobes arch_disarm_kprobe(struct kprobe *p)
226{ 226{
227 *p->addr = p->opcode; 227 *p->addr = p->opcode;
228 flush_icache_range((unsigned long) p->addr, 228 flush_icache_range((unsigned long) p->addr,
229 (unsigned long) p->addr + sizeof(kprobe_opcode_t)); 229 (unsigned long) p->addr + sizeof(kprobe_opcode_t));
230} 230}
231 231
232void arch_remove_kprobe(struct kprobe *p) 232void __kprobes arch_remove_kprobe(struct kprobe *p)
233{ 233{
234 up(&kprobe_mutex); 234 up(&kprobe_mutex);
235 free_insn_slot(p->ainsn.insn); 235 free_insn_slot(p->ainsn.insn);
@@ -261,7 +261,7 @@ static inline void set_current_kprobe(struct kprobe *p, struct pt_regs *regs)
261 kprobe_saved_rflags &= ~IF_MASK; 261 kprobe_saved_rflags &= ~IF_MASK;
262} 262}
263 263
264static void prepare_singlestep(struct kprobe *p, struct pt_regs *regs) 264static void __kprobes prepare_singlestep(struct kprobe *p, struct pt_regs *regs)
265{ 265{
266 regs->eflags |= TF_MASK; 266 regs->eflags |= TF_MASK;
267 regs->eflags &= ~IF_MASK; 267 regs->eflags &= ~IF_MASK;
@@ -272,7 +272,8 @@ static void prepare_singlestep(struct kprobe *p, struct pt_regs *regs)
272 regs->rip = (unsigned long)p->ainsn.insn; 272 regs->rip = (unsigned long)p->ainsn.insn;
273} 273}
274 274
275void arch_prepare_kretprobe(struct kretprobe *rp, struct pt_regs *regs) 275void __kprobes arch_prepare_kretprobe(struct kretprobe *rp,
276 struct pt_regs *regs)
276{ 277{
277 unsigned long *sara = (unsigned long *)regs->rsp; 278 unsigned long *sara = (unsigned long *)regs->rsp;
278 struct kretprobe_instance *ri; 279 struct kretprobe_instance *ri;
@@ -295,7 +296,7 @@ void arch_prepare_kretprobe(struct kretprobe *rp, struct pt_regs *regs)
295 * Interrupts are disabled on entry as trap3 is an interrupt gate and they 296 * Interrupts are disabled on entry as trap3 is an interrupt gate and they
296 * remain disabled thorough out this function. 297 * remain disabled thorough out this function.
297 */ 298 */
298int kprobe_handler(struct pt_regs *regs) 299int __kprobes kprobe_handler(struct pt_regs *regs)
299{ 300{
300 struct kprobe *p; 301 struct kprobe *p;
301 int ret = 0; 302 int ret = 0;
@@ -310,7 +311,8 @@ int kprobe_handler(struct pt_regs *regs)
310 Disarm the probe we just hit, and ignore it. */ 311 Disarm the probe we just hit, and ignore it. */
311 p = get_kprobe(addr); 312 p = get_kprobe(addr);
312 if (p) { 313 if (p) {
313 if (kprobe_status == KPROBE_HIT_SS) { 314 if (kprobe_status == KPROBE_HIT_SS &&
315 *p->ainsn.insn == BREAKPOINT_INSTRUCTION) {
314 regs->eflags &= ~TF_MASK; 316 regs->eflags &= ~TF_MASK;
315 regs->eflags |= kprobe_saved_rflags; 317 regs->eflags |= kprobe_saved_rflags;
316 unlock_kprobes(); 318 unlock_kprobes();
@@ -360,7 +362,10 @@ int kprobe_handler(struct pt_regs *regs)
360 * either a probepoint or a debugger breakpoint 362 * either a probepoint or a debugger breakpoint
361 * at this address. In either case, no further 363 * at this address. In either case, no further
362 * handling of this interrupt is appropriate. 364 * handling of this interrupt is appropriate.
365 * Back up over the (now missing) int3 and run
366 * the original instruction.
363 */ 367 */
368 regs->rip = (unsigned long)addr;
364 ret = 1; 369 ret = 1;
365 } 370 }
366 /* Not one of ours: let kernel handle it */ 371 /* Not one of ours: let kernel handle it */
@@ -399,7 +404,7 @@ no_kprobe:
399/* 404/*
400 * Called when we hit the probe point at kretprobe_trampoline 405 * Called when we hit the probe point at kretprobe_trampoline
401 */ 406 */
402int trampoline_probe_handler(struct kprobe *p, struct pt_regs *regs) 407int __kprobes trampoline_probe_handler(struct kprobe *p, struct pt_regs *regs)
403{ 408{
404 struct kretprobe_instance *ri = NULL; 409 struct kretprobe_instance *ri = NULL;
405 struct hlist_head *head; 410 struct hlist_head *head;
@@ -478,7 +483,7 @@ int trampoline_probe_handler(struct kprobe *p, struct pt_regs *regs)
478 * that is atop the stack is the address following the copied instruction. 483 * that is atop the stack is the address following the copied instruction.
479 * We need to make it the address following the original instruction. 484 * We need to make it the address following the original instruction.
480 */ 485 */
481static void resume_execution(struct kprobe *p, struct pt_regs *regs) 486static void __kprobes resume_execution(struct kprobe *p, struct pt_regs *regs)
482{ 487{
483 unsigned long *tos = (unsigned long *)regs->rsp; 488 unsigned long *tos = (unsigned long *)regs->rsp;
484 unsigned long next_rip = 0; 489 unsigned long next_rip = 0;
@@ -536,7 +541,7 @@ static void resume_execution(struct kprobe *p, struct pt_regs *regs)
536 * Interrupts are disabled on entry as trap1 is an interrupt gate and they 541 * Interrupts are disabled on entry as trap1 is an interrupt gate and they
537 * remain disabled thoroughout this function. And we hold kprobe lock. 542 * remain disabled thoroughout this function. And we hold kprobe lock.
538 */ 543 */
539int post_kprobe_handler(struct pt_regs *regs) 544int __kprobes post_kprobe_handler(struct pt_regs *regs)
540{ 545{
541 if (!kprobe_running()) 546 if (!kprobe_running())
542 return 0; 547 return 0;
@@ -571,7 +576,7 @@ out:
571} 576}
572 577
573/* Interrupts disabled, kprobe_lock held. */ 578/* Interrupts disabled, kprobe_lock held. */
574int kprobe_fault_handler(struct pt_regs *regs, int trapnr) 579int __kprobes kprobe_fault_handler(struct pt_regs *regs, int trapnr)
575{ 580{
576 if (current_kprobe->fault_handler 581 if (current_kprobe->fault_handler
577 && current_kprobe->fault_handler(current_kprobe, regs, trapnr)) 582 && current_kprobe->fault_handler(current_kprobe, regs, trapnr))
@@ -590,8 +595,8 @@ int kprobe_fault_handler(struct pt_regs *regs, int trapnr)
590/* 595/*
591 * Wrapper routine for handling exceptions. 596 * Wrapper routine for handling exceptions.
592 */ 597 */
593int kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, 598int __kprobes kprobe_exceptions_notify(struct notifier_block *self,
594 void *data) 599 unsigned long val, void *data)
595{ 600{
596 struct die_args *args = (struct die_args *)data; 601 struct die_args *args = (struct die_args *)data;
597 switch (val) { 602 switch (val) {
@@ -619,7 +624,7 @@ int kprobe_exceptions_notify(struct notifier_block *self, unsigned long val,
619 return NOTIFY_DONE; 624 return NOTIFY_DONE;
620} 625}
621 626
622int setjmp_pre_handler(struct kprobe *p, struct pt_regs *regs) 627int __kprobes setjmp_pre_handler(struct kprobe *p, struct pt_regs *regs)
623{ 628{
624 struct jprobe *jp = container_of(p, struct jprobe, kp); 629 struct jprobe *jp = container_of(p, struct jprobe, kp);
625 unsigned long addr; 630 unsigned long addr;
@@ -640,7 +645,7 @@ int setjmp_pre_handler(struct kprobe *p, struct pt_regs *regs)
640 return 1; 645 return 1;
641} 646}
642 647
643void jprobe_return(void) 648void __kprobes jprobe_return(void)
644{ 649{
645 preempt_enable_no_resched(); 650 preempt_enable_no_resched();
646 asm volatile (" xchg %%rbx,%%rsp \n" 651 asm volatile (" xchg %%rbx,%%rsp \n"
@@ -651,7 +656,7 @@ void jprobe_return(void)
651 (jprobe_saved_rsp):"memory"); 656 (jprobe_saved_rsp):"memory");
652} 657}
653 658
654int longjmp_break_handler(struct kprobe *p, struct pt_regs *regs) 659int __kprobes longjmp_break_handler(struct kprobe *p, struct pt_regs *regs)
655{ 660{
656 u8 *addr = (u8 *) (regs->rip - 1); 661 u8 *addr = (u8 *) (regs->rip - 1);
657 unsigned long stack_addr = (unsigned long)jprobe_saved_rsp; 662 unsigned long stack_addr = (unsigned long)jprobe_saved_rsp;