3030#include <asm/sections.h>
3131#include <linux/module.h>
3232#include <linux/slab.h>
33+ #include <linux/hardirq.h>
3334
3435DEFINE_PER_CPU (struct kprobe * , current_kprobe ) = NULL ;
3536DEFINE_PER_CPU (struct kprobe_ctlblk , kprobe_ctlblk );
@@ -212,7 +213,7 @@ static void __kprobes prepare_singlestep(struct kprobe *p, struct pt_regs *regs)
212213 /* Set the PER control regs, turns on single step for this address */
213214 __ctl_load (kprobe_per_regs , 9 , 11 );
214215 regs -> psw .mask |= PSW_MASK_PER ;
215- regs -> psw .mask &= ~(PSW_MASK_IO | PSW_MASK_EXT | PSW_MASK_MCHECK );
216+ regs -> psw .mask &= ~(PSW_MASK_IO | PSW_MASK_EXT );
216217}
217218
218219static void __kprobes save_previous_kprobe (struct kprobe_ctlblk * kcb )
@@ -239,7 +240,7 @@ static void __kprobes set_current_kprobe(struct kprobe *p, struct pt_regs *regs,
239240 __get_cpu_var (current_kprobe ) = p ;
240241 /* Save the interrupt and per flags */
241242 kcb -> kprobe_saved_imask = regs -> psw .mask &
242- (PSW_MASK_PER | PSW_MASK_IO | PSW_MASK_EXT | PSW_MASK_MCHECK );
243+ (PSW_MASK_PER | PSW_MASK_IO | PSW_MASK_EXT );
243244 /* Save the control regs that govern PER */
244245 __ctl_store (kcb -> kprobe_saved_ctl , 9 , 11 );
245246}
@@ -316,8 +317,6 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
316317 return 1 ;
317318
318319ss_probe :
319- if (regs -> psw .mask & (PSW_MASK_PER | PSW_MASK_IO ))
320- local_irq_disable ();
321320 prepare_singlestep (p , regs );
322321 kcb -> kprobe_status = KPROBE_HIT_SS ;
323322 return 1 ;
@@ -350,6 +349,7 @@ static int __kprobes trampoline_probe_handler(struct kprobe *p,
350349 struct hlist_node * node , * tmp ;
351350 unsigned long flags , orig_ret_address = 0 ;
352351 unsigned long trampoline_address = (unsigned long )& kretprobe_trampoline ;
352+ kprobe_opcode_t * correct_ret_addr = NULL ;
353353
354354 INIT_HLIST_HEAD (& empty_rp );
355355 kretprobe_hash_lock (current , & head , & flags );
@@ -372,10 +372,32 @@ static int __kprobes trampoline_probe_handler(struct kprobe *p,
372372 /* another task is sharing our hash bucket */
373373 continue ;
374374
375- if (ri -> rp && ri -> rp -> handler )
376- ri -> rp -> handler (ri , regs );
375+ orig_ret_address = (unsigned long )ri -> ret_addr ;
376+
377+ if (orig_ret_address != trampoline_address )
378+ /*
379+ * This is the real return address. Any other
380+ * instances associated with this task are for
381+ * other calls deeper on the call stack
382+ */
383+ break ;
384+ }
385+
386+ kretprobe_assert (ri , orig_ret_address , trampoline_address );
387+
388+ correct_ret_addr = ri -> ret_addr ;
389+ hlist_for_each_entry_safe (ri , node , tmp , head , hlist ) {
390+ if (ri -> task != current )
391+ /* another task is sharing our hash bucket */
392+ continue ;
377393
378394 orig_ret_address = (unsigned long )ri -> ret_addr ;
395+
396+ if (ri -> rp && ri -> rp -> handler ) {
397+ ri -> ret_addr = correct_ret_addr ;
398+ ri -> rp -> handler (ri , regs );
399+ }
400+
379401 recycle_rp_inst (ri , & empty_rp );
380402
381403 if (orig_ret_address != trampoline_address ) {
@@ -387,7 +409,7 @@ static int __kprobes trampoline_probe_handler(struct kprobe *p,
387409 break ;
388410 }
389411 }
390- kretprobe_assert ( ri , orig_ret_address , trampoline_address );
412+
391413 regs -> psw .addr = orig_ret_address | PSW_ADDR_AMODE ;
392414
393415 reset_current_kprobe ();
@@ -465,8 +487,6 @@ static int __kprobes post_kprobe_handler(struct pt_regs *regs)
465487 goto out ;
466488 }
467489 reset_current_kprobe ();
468- if (regs -> psw .mask & (PSW_MASK_PER | PSW_MASK_IO ))
469- local_irq_enable ();
470490out :
471491 preempt_enable_no_resched ();
472492
@@ -482,7 +502,7 @@ static int __kprobes post_kprobe_handler(struct pt_regs *regs)
482502 return 1 ;
483503}
484504
485- int __kprobes kprobe_fault_handler (struct pt_regs * regs , int trapnr )
505+ static int __kprobes kprobe_trap_handler (struct pt_regs * regs , int trapnr )
486506{
487507 struct kprobe * cur = kprobe_running ();
488508 struct kprobe_ctlblk * kcb = get_kprobe_ctlblk ();
@@ -508,8 +528,6 @@ int __kprobes kprobe_fault_handler(struct pt_regs *regs, int trapnr)
508528 restore_previous_kprobe (kcb );
509529 else {
510530 reset_current_kprobe ();
511- if (regs -> psw .mask & (PSW_MASK_PER | PSW_MASK_IO ))
512- local_irq_enable ();
513531 }
514532 preempt_enable_no_resched ();
515533 break ;
@@ -553,15 +571,31 @@ int __kprobes kprobe_fault_handler(struct pt_regs *regs, int trapnr)
553571 return 0 ;
554572}
555573
574+ int __kprobes kprobe_fault_handler (struct pt_regs * regs , int trapnr )
575+ {
576+ int ret ;
577+
578+ if (regs -> psw .mask & (PSW_MASK_IO | PSW_MASK_EXT ))
579+ local_irq_disable ();
580+ ret = kprobe_trap_handler (regs , trapnr );
581+ if (regs -> psw .mask & (PSW_MASK_IO | PSW_MASK_EXT ))
582+ local_irq_restore (regs -> psw .mask & ~PSW_MASK_PER );
583+ return ret ;
584+ }
585+
556586/*
557587 * Wrapper routine to for handling exceptions.
558588 */
559589int __kprobes kprobe_exceptions_notify (struct notifier_block * self ,
560590 unsigned long val , void * data )
561591{
562592 struct die_args * args = (struct die_args * )data ;
593+ struct pt_regs * regs = args -> regs ;
563594 int ret = NOTIFY_DONE ;
564595
596+ if (regs -> psw .mask & (PSW_MASK_IO | PSW_MASK_EXT ))
597+ local_irq_disable ();
598+
565599 switch (val ) {
566600 case DIE_BPT :
567601 if (kprobe_handler (args -> regs ))
@@ -572,16 +606,17 @@ int __kprobes kprobe_exceptions_notify(struct notifier_block *self,
572606 ret = NOTIFY_STOP ;
573607 break ;
574608 case DIE_TRAP :
575- /* kprobe_running() needs smp_processor_id() */
576- preempt_disable ();
577- if (kprobe_running () &&
578- kprobe_fault_handler (args -> regs , args -> trapnr ))
609+ if (!preemptible () && kprobe_running () &&
610+ kprobe_trap_handler (args -> regs , args -> trapnr ))
579611 ret = NOTIFY_STOP ;
580- preempt_enable ();
581612 break ;
582613 default :
583614 break ;
584615 }
616+
617+ if (regs -> psw .mask & (PSW_MASK_IO | PSW_MASK_EXT ))
618+ local_irq_restore (regs -> psw .mask & ~PSW_MASK_PER );
619+
585620 return ret ;
586621}
587622
@@ -595,6 +630,7 @@ int __kprobes setjmp_pre_handler(struct kprobe *p, struct pt_regs *regs)
595630
596631 /* setup return addr to the jprobe handler routine */
597632 regs -> psw .addr = (unsigned long )(jp -> entry ) | PSW_ADDR_AMODE ;
633+ regs -> psw .mask &= ~(PSW_MASK_IO | PSW_MASK_EXT );
598634
599635 /* r14 is the function return address */
600636 kcb -> jprobe_saved_r14 = (unsigned long )regs -> gprs [14 ];
0 commit comments