kprobe_handler should check pre_handler function
On Mon, Mar 28, 2005 at 04:10:32PM -0500, William Cohen wrote:
Hi Will,
Quoted 10 lines
I found kprobes expects there to be a
pre_handlerfunction in the structure. I was writing a probe that only needed apost_handlerfunction, nopre_handlerfunction. The probe was tracking the destinations of indirect calls and jumps, the probe needs to fire after the instruction single steps to get the target address. The probe crashed the machine because arch/i386/kernel/kprobe.c:kprobe_handler() blindly callsp->pre_handler(). There should be a check to verify that the pointer is non-null. There are cases where thepre_handleris not needed and it would make sense to set it to NULL. Thus, a check should be done forpre_handlerlikepost_handlerandfault_handler.
You are right. The check for pre_handler is needed and here is a patch against 2.6.12-rc1-mm3 that does this.
Thanks,
Ananth
arch/i386/kernel/kprobes.c renamed from linux-2.6.12-rc1/arch/i386/kernel/kprobes.c +3 -4
@@ -159,17 +159,16 @@ static int kprobe_handler(struct pt_regsif (is_IF_modifier (p->opcode)) kprobe_saved_eflags &= ~IF_MASK ; -if (p->pre_handler (p, regs)) { +if (p->pre_handler && p->pre_handler (p, regs))/* handler has already set things up, so skip ss setup */ return 1 ; - } - ss_probe: +ss_probe:prepare_singlestep (p, regs); kprobe_status =KPROBE_HIT_SS ;return 1 ; - no_kprobe: +no_kprobe:preempt_enable_no_resched ();return ret; }
arch/ppc64/kernel/kprobes.c renamed from linux-2.6.12-rc1/arch/ppc64/kernel/kprobes.c +1 -2
@@ -128,10 +128,9 @@ static inline int kprobe_handler(struct kprobe_status =KPROBE_HIT_ACTIVE ; current_kprobe = p; kprobe_saved_msr = regs->msr; -if (p->pre_handler (p, regs)) { +if (p->pre_handler && p->pre_handler (p, regs))/* handler has already set things up, so skip ss setup */ return 1 ; - } ss_probe:prepare_singlestep (p, regs);
arch/sparc64/kernel/kprobes.c renamed from linux-2.6.12-rc1/arch/sparc64/kernel/kprobes.c +1 -1
@@ -128,7 +128,7 @@ static int kprobe_handler(struct pt_regs kprobe_status =KPROBE_HIT_ACTIVE ; current_kprobe = p; -if (p->pre_handler (p, regs)) +if (p->pre_handler && p->pre_handler (p, regs))return 1 ; ss_probe:
arch/x86_64/kernel/kprobes.c renamed from linux-2.6.12-rc1/arch/x86_64/kernel/kprobes.c +3 -4
@@ -293,17 +293,16 @@ int kprobe_handler(struct pt_regs *regs)if (is_IF_modifier (p->ainsn.insn)) kprobe_saved_rflags &= ~IF_MASK ; -if (p->pre_handler (p, regs)) { +if (p->pre_handler && p->pre_handler (p, regs))/* handler has already set things up, so skip ss setup */ return 1 ; - } - ss_probe: +ss_probe:prepare_singlestep (p, regs); kprobe_status =KPROBE_HIT_SS ;return 1 ; - no_kprobe: +no_kprobe:preempt_enable_no_resched ();return ret; }
Quoted 2 lines · On Mon, 28 Mar 2005 21:34:08 -0500 Ananth N Mavinakayanahalli…
You are right. The check for
pre_handleris needed and here is a patch against 2.6.12-rc1-mm3 that does this.
The sparc64 part looks just fine.
Quoted 5 lines · Ananth N Mavinakayanahalli
On Mon, Mar 28, 2005 at 04:10:32PM -0500, William Cohen wrote:
Hi Will,
Quoted 8 lines
Quoted 1 line
I found kprobes expects there to be a
pre_handlerfunction in the structure. I was writing a probe that only needed apost_handlerfunction, nopre_handlerfunction. The probe was tracking the destinations of indirect calls and jumps, the probe needs to fire after the instruction single steps to get the target address. The probe crashed the machine because arch/i386/kernel/kprobe.c:kprobe_handler() blindly callsp->pre_handler(). There should be a check to verify that the pointer is non-null. There are cases where thepre_handleris not needed and it would make sense to set it to NULL. Thus, a check should be done forpre_handlerlikepost_handlerandfault_handler.You are right. The check for
pre_handleris needed and here is a patch against 2.6.12-rc1-mm3 that does this.Thanks,
Ananth
Ananth,
Thanks. It looks like it addresses the problem. Could you see about getting this patch in the upstream kernel?
-Will
Quoted 21 lines · William Cohen
Quoted 20 lines · Ananth N Mavinakayanahalli
On Mon, Mar 28, 2005 at 04:10:32PM -0500, William Cohen wrote:
Hi Will,
Quoted 10 lines
I found kprobes expects there to be a
pre_handlerfunction in the structure. I was writing a probe that only needed apost_handlerfunction, nopre_handlerfunction. The probe was tracking the destinations of indirect calls and jumps, the probe needs to fire after the instruction single steps to get the target address. The probe crashed the machine because arch/i386/kernel/kprobe.c:kprobe_handler() blindly callsp->pre_handler(). There should be a check to verify that the pointer is non-null. There are cases where thepre_handleris not needed and it would make sense to set it to NULL. Thus, a check should be done forpre_handlerlikepost_handlerandfault_handler.You are right. The check for
pre_handleris needed and here is a patch against 2.6.12-rc1-mm3 that does this.
Quoted 7 lines
Quoted 2 lines
Thanks,
AnanthAnanth,
Thanks. It looks like it addresses the problem. Could you see about getting this patch in the upstream kernel?
Will,
I think Andrew now has this in his patchset. It will probably be in the next -mm.
Thanks,
Ananth