diff options
| -rw-r--r-- | arch/i386/kernel/kprobes.c | 3 | ||||
| -rw-r--r-- | arch/ia64/kernel/kprobes.c | 22 | ||||
| -rw-r--r-- | arch/ppc64/kernel/kprobes.c | 11 | ||||
| -rw-r--r-- | arch/x86_64/kernel/kprobes.c | 3 | ||||
| -rw-r--r-- | include/asm-ia64/kprobes.h | 1 | ||||
| -rw-r--r-- | include/asm-ppc64/kprobes.h | 3 | ||||
| -rw-r--r-- | kernel/kprobes.c | 22 |
7 files changed, 55 insertions, 10 deletions
diff --git a/arch/i386/kernel/kprobes.c b/arch/i386/kernel/kprobes.c index e5cec32018a5..6345b430b105 100644 --- a/arch/i386/kernel/kprobes.c +++ b/arch/i386/kernel/kprobes.c | |||
| @@ -177,7 +177,8 @@ static int __kprobes kprobe_handler(struct pt_regs *regs) | |||
| 177 | Disarm the probe we just hit, and ignore it. */ | 177 | Disarm the probe we just hit, and ignore it. */ |
| 178 | p = get_kprobe(addr); | 178 | p = get_kprobe(addr); |
| 179 | if (p) { | 179 | if (p) { |
| 180 | if (kprobe_status == KPROBE_HIT_SS) { | 180 | if (kprobe_status == KPROBE_HIT_SS && |
| 181 | *p->ainsn.insn == BREAKPOINT_INSTRUCTION) { | ||
| 181 | regs->eflags &= ~TF_MASK; | 182 | regs->eflags &= ~TF_MASK; |
| 182 | regs->eflags |= kprobe_saved_eflags; | 183 | regs->eflags |= kprobe_saved_eflags; |
| 183 | unlock_kprobes(); | 184 | unlock_kprobes(); |
diff --git a/arch/ia64/kernel/kprobes.c b/arch/ia64/kernel/kprobes.c index 4b1bd539ec47..471086b808a4 100644 --- a/arch/ia64/kernel/kprobes.c +++ b/arch/ia64/kernel/kprobes.c | |||
| @@ -95,6 +95,17 @@ static void __kprobes update_kprobe_inst_flag(uint template, uint slot, | |||
| 95 | p->ainsn.inst_flag = 0; | 95 | p->ainsn.inst_flag = 0; |
| 96 | p->ainsn.target_br_reg = 0; | 96 | p->ainsn.target_br_reg = 0; |
| 97 | 97 | ||
| 98 | /* Check for Break instruction | ||
| 99 | * Bits 37:40 Major opcode to be zero | ||
| 100 | * Bits 27:32 X6 to be zero | ||
| 101 | * Bits 32:35 X3 to be zero | ||
| 102 | */ | ||
| 103 | if ((!major_opcode) && (!((kprobe_inst >> 27) & 0x1FF)) ) { | ||
| 104 | /* is a break instruction */ | ||
| 105 | p->ainsn.inst_flag |= INST_FLAG_BREAK_INST; | ||
| 106 | return; | ||
| 107 | } | ||
| 108 | |||
| 98 | if (bundle_encoding[template][slot] == B) { | 109 | if (bundle_encoding[template][slot] == B) { |
| 99 | switch (major_opcode) { | 110 | switch (major_opcode) { |
| 100 | case INDIRECT_CALL_OPCODE: | 111 | case INDIRECT_CALL_OPCODE: |
| @@ -542,8 +553,11 @@ static void __kprobes prepare_ss(struct kprobe *p, struct pt_regs *regs) | |||
| 542 | unsigned long bundle_addr = (unsigned long) &p->opcode.bundle; | 553 | unsigned long bundle_addr = (unsigned long) &p->opcode.bundle; |
| 543 | unsigned long slot = (unsigned long)p->addr & 0xf; | 554 | unsigned long slot = (unsigned long)p->addr & 0xf; |
| 544 | 555 | ||
| 545 | /* Update instruction pointer (IIP) and slot number (IPSR.ri) */ | 556 | /* single step inline if break instruction */ |
| 546 | regs->cr_iip = bundle_addr & ~0xFULL; | 557 | if (p->ainsn.inst_flag == INST_FLAG_BREAK_INST) |
| 558 | regs->cr_iip = (unsigned long)p->addr & ~0xFULL; | ||
| 559 | else | ||
| 560 | regs->cr_iip = bundle_addr & ~0xFULL; | ||
| 547 | 561 | ||
| 548 | if (slot > 2) | 562 | if (slot > 2) |
| 549 | slot = 0; | 563 | slot = 0; |
| @@ -599,7 +613,9 @@ static int __kprobes pre_kprobes_handler(struct die_args *args) | |||
| 599 | if (kprobe_running()) { | 613 | if (kprobe_running()) { |
| 600 | p = get_kprobe(addr); | 614 | p = get_kprobe(addr); |
| 601 | if (p) { | 615 | if (p) { |
| 602 | if (kprobe_status == KPROBE_HIT_SS) { | 616 | if ( (kprobe_status == KPROBE_HIT_SS) && |
| 617 | (p->ainsn.inst_flag == INST_FLAG_BREAK_INST)) { | ||
| 618 | ia64_psr(regs)->ss = 0; | ||
| 603 | unlock_kprobes(); | 619 | unlock_kprobes(); |
| 604 | goto no_kprobe; | 620 | goto no_kprobe; |
| 605 | } | 621 | } |
diff --git a/arch/ppc64/kernel/kprobes.c b/arch/ppc64/kernel/kprobes.c index 591e4b67b5a5..7e80d49c589a 100644 --- a/arch/ppc64/kernel/kprobes.c +++ b/arch/ppc64/kernel/kprobes.c | |||
| @@ -102,7 +102,7 @@ static inline void prepare_singlestep(struct kprobe *p, struct pt_regs *regs) | |||
| 102 | regs->msr |= MSR_SE; | 102 | regs->msr |= MSR_SE; |
| 103 | 103 | ||
| 104 | /* single step inline if it is a trap variant */ | 104 | /* single step inline if it is a trap variant */ |
| 105 | if (IS_TW(insn) || IS_TD(insn) || IS_TWI(insn) || IS_TDI(insn)) | 105 | if (is_trap(insn)) |
| 106 | regs->nip = (unsigned long)p->addr; | 106 | regs->nip = (unsigned long)p->addr; |
| 107 | else | 107 | else |
| 108 | regs->nip = (unsigned long)p->ainsn.insn; | 108 | regs->nip = (unsigned long)p->ainsn.insn; |
| @@ -152,7 +152,9 @@ static inline int kprobe_handler(struct pt_regs *regs) | |||
| 152 | Disarm the probe we just hit, and ignore it. */ | 152 | Disarm the probe we just hit, and ignore it. */ |
| 153 | p = get_kprobe(addr); | 153 | p = get_kprobe(addr); |
| 154 | if (p) { | 154 | if (p) { |
| 155 | if (kprobe_status == KPROBE_HIT_SS) { | 155 | kprobe_opcode_t insn = *p->ainsn.insn; |
| 156 | if (kprobe_status == KPROBE_HIT_SS && | ||
| 157 | is_trap(insn)) { | ||
| 156 | regs->msr &= ~MSR_SE; | 158 | regs->msr &= ~MSR_SE; |
| 157 | regs->msr |= kprobe_saved_msr; | 159 | regs->msr |= kprobe_saved_msr; |
| 158 | unlock_kprobes(); | 160 | unlock_kprobes(); |
| @@ -192,8 +194,7 @@ static inline int kprobe_handler(struct pt_regs *regs) | |||
| 192 | * trap variant, it could belong to someone else | 194 | * trap variant, it could belong to someone else |
| 193 | */ | 195 | */ |
| 194 | kprobe_opcode_t cur_insn = *addr; | 196 | kprobe_opcode_t cur_insn = *addr; |
| 195 | if (IS_TW(cur_insn) || IS_TD(cur_insn) || | 197 | if (is_trap(cur_insn)) |
| 196 | IS_TWI(cur_insn) || IS_TDI(cur_insn)) | ||
| 197 | goto no_kprobe; | 198 | goto no_kprobe; |
| 198 | /* | 199 | /* |
| 199 | * The breakpoint instruction was removed right | 200 | * The breakpoint instruction was removed right |
| @@ -403,7 +404,7 @@ int __kprobes kprobe_exceptions_notify(struct notifier_block *self, | |||
| 403 | default: | 404 | default: |
| 404 | break; | 405 | break; |
| 405 | } | 406 | } |
| 406 | preempt_enable(); | 407 | preempt_enable_no_resched(); |
| 407 | return ret; | 408 | return ret; |
| 408 | } | 409 | } |
| 409 | 410 | ||
diff --git a/arch/x86_64/kernel/kprobes.c b/arch/x86_64/kernel/kprobes.c index 2d7658fbbb28..df08c43276a0 100644 --- a/arch/x86_64/kernel/kprobes.c +++ b/arch/x86_64/kernel/kprobes.c | |||
| @@ -311,7 +311,8 @@ int __kprobes kprobe_handler(struct pt_regs *regs) | |||
| 311 | Disarm the probe we just hit, and ignore it. */ | 311 | Disarm the probe we just hit, and ignore it. */ |
| 312 | p = get_kprobe(addr); | 312 | p = get_kprobe(addr); |
| 313 | if (p) { | 313 | if (p) { |
| 314 | if (kprobe_status == KPROBE_HIT_SS) { | 314 | if (kprobe_status == KPROBE_HIT_SS && |
| 315 | *p->ainsn.insn == BREAKPOINT_INSTRUCTION) { | ||
| 315 | regs->eflags &= ~TF_MASK; | 316 | regs->eflags &= ~TF_MASK; |
| 316 | regs->eflags |= kprobe_saved_rflags; | 317 | regs->eflags |= kprobe_saved_rflags; |
| 317 | unlock_kprobes(); | 318 | unlock_kprobes(); |
diff --git a/include/asm-ia64/kprobes.h b/include/asm-ia64/kprobes.h index bf36a32e37e4..573a3574a24f 100644 --- a/include/asm-ia64/kprobes.h +++ b/include/asm-ia64/kprobes.h | |||
| @@ -92,6 +92,7 @@ struct arch_specific_insn { | |||
| 92 | kprobe_opcode_t insn; | 92 | kprobe_opcode_t insn; |
| 93 | #define INST_FLAG_FIX_RELATIVE_IP_ADDR 1 | 93 | #define INST_FLAG_FIX_RELATIVE_IP_ADDR 1 |
| 94 | #define INST_FLAG_FIX_BRANCH_REG 2 | 94 | #define INST_FLAG_FIX_BRANCH_REG 2 |
| 95 | #define INST_FLAG_BREAK_INST 4 | ||
| 95 | unsigned long inst_flag; | 96 | unsigned long inst_flag; |
| 96 | unsigned short target_br_reg; | 97 | unsigned short target_br_reg; |
| 97 | }; | 98 | }; |
diff --git a/include/asm-ppc64/kprobes.h b/include/asm-ppc64/kprobes.h index 0802919c3235..d9129d2b038e 100644 --- a/include/asm-ppc64/kprobes.h +++ b/include/asm-ppc64/kprobes.h | |||
| @@ -42,6 +42,9 @@ typedef unsigned int kprobe_opcode_t; | |||
| 42 | 42 | ||
| 43 | #define JPROBE_ENTRY(pentry) (kprobe_opcode_t *)((func_descr_t *)pentry) | 43 | #define JPROBE_ENTRY(pentry) (kprobe_opcode_t *)((func_descr_t *)pentry) |
| 44 | 44 | ||
| 45 | #define is_trap(instr) (IS_TW(instr) || IS_TD(instr) || \ | ||
| 46 | IS_TWI(instr) || IS_TDI(instr)) | ||
| 47 | |||
| 45 | #define ARCH_SUPPORTS_KRETPROBES | 48 | #define ARCH_SUPPORTS_KRETPROBES |
| 46 | void kretprobe_trampoline(void); | 49 | void kretprobe_trampoline(void); |
| 47 | 50 | ||
diff --git a/kernel/kprobes.c b/kernel/kprobes.c index 3b7653f2e7ae..f3ea492ab44d 100644 --- a/kernel/kprobes.c +++ b/kernel/kprobes.c | |||
| @@ -155,14 +155,36 @@ void __kprobes free_insn_slot(kprobe_opcode_t *slot) | |||
| 155 | /* Locks kprobe: irqs must be disabled */ | 155 | /* Locks kprobe: irqs must be disabled */ |
| 156 | void __kprobes lock_kprobes(void) | 156 | void __kprobes lock_kprobes(void) |
| 157 | { | 157 | { |
| 158 | unsigned long flags = 0; | ||
| 159 | |||
| 160 | /* Avoiding local interrupts to happen right after we take the kprobe_lock | ||
| 161 | * and before we get a chance to update kprobe_cpu, this to prevent | ||
| 162 | * deadlock when we have a kprobe on ISR routine and a kprobe on task | ||
| 163 | * routine | ||
| 164 | */ | ||
| 165 | local_irq_save(flags); | ||
| 166 | |||
| 158 | spin_lock(&kprobe_lock); | 167 | spin_lock(&kprobe_lock); |
| 159 | kprobe_cpu = smp_processor_id(); | 168 | kprobe_cpu = smp_processor_id(); |
| 169 | |||
| 170 | local_irq_restore(flags); | ||
| 160 | } | 171 | } |
| 161 | 172 | ||
| 162 | void __kprobes unlock_kprobes(void) | 173 | void __kprobes unlock_kprobes(void) |
| 163 | { | 174 | { |
| 175 | unsigned long flags = 0; | ||
| 176 | |||
| 177 | /* Avoiding local interrupts to happen right after we update | ||
| 178 | * kprobe_cpu and before we get a a chance to release kprobe_lock, | ||
| 179 | * this to prevent deadlock when we have a kprobe on ISR routine and | ||
| 180 | * a kprobe on task routine | ||
| 181 | */ | ||
| 182 | local_irq_save(flags); | ||
| 183 | |||
| 164 | kprobe_cpu = NR_CPUS; | 184 | kprobe_cpu = NR_CPUS; |
| 165 | spin_unlock(&kprobe_lock); | 185 | spin_unlock(&kprobe_lock); |
| 186 | |||
| 187 | local_irq_restore(flags); | ||
| 166 | } | 188 | } |
| 167 | 189 | ||
| 168 | /* You have to be holding the kprobe_lock */ | 190 | /* You have to be holding the kprobe_lock */ |
