aboutsummaryrefslogtreecommitdiffstats
path: root/arch
diff options
context:
space:
mode:
authorMichael Ellerman <michael@ellerman.id.au>2007-07-19 04:48:11 -0400
committerLinus Torvalds <torvalds@woody.linux-foundation.org>2007-07-19 13:04:44 -0400
commit3d7e33825d8799115dd2495c9944badd3272a623 (patch)
tree869eeefa9dd88c622db199f636cd1785c6099947 /arch
parent9e367d859297b9377d65574f538cf52730e9eda8 (diff)
jprobes: make jprobes a little safer for users
I realise jprobes are a razor-blades-included type of interface, but that doesn't mean we can't try and make them safer to use. This guy I know once wrote code like this: struct jprobe jp = { .kp.symbol_name = "foo", .entry = "jprobe_foo" }; And then his kernel exploded. Oops. This patch adds an arch hook, arch_deref_entry_point() (I don't like it either) which takes the void * in a struct jprobe, and gives back the text address that it represents. We can then use that in register_jprobe() to check that the entry point we're passed is actually in the kernel text, rather than just some random value. Signed-off-by: Michael Ellerman <michael@ellerman.id.au> Cc: Prasanna S Panchamukhi <prasanna@in.ibm.com> Acked-by: Ananth N Mavinakayanahalli <ananth@in.ibm.com> Cc: Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com> Cc: David S. Miller <davem@davemloft.net> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'arch')
-rw-r--r--arch/ia64/kernel/kprobes.c7
-rw-r--r--arch/powerpc/kernel/kprobes.c11
2 files changed, 14 insertions, 4 deletions
diff --git a/arch/ia64/kernel/kprobes.c b/arch/ia64/kernel/kprobes.c
index 5bc46f151344..5dc98b5abcfb 100644
--- a/arch/ia64/kernel/kprobes.c
+++ b/arch/ia64/kernel/kprobes.c
@@ -936,10 +936,15 @@ static void ia64_get_bsp_cfm(struct unw_frame_info *info, void *arg)
936 return; 936 return;
937} 937}
938 938
939unsigned long arch_deref_entry_point(void *entry)
940{
941 return ((struct fnptr *)entry)->ip;
942}
943
939int __kprobes setjmp_pre_handler(struct kprobe *p, struct pt_regs *regs) 944int __kprobes setjmp_pre_handler(struct kprobe *p, struct pt_regs *regs)
940{ 945{
941 struct jprobe *jp = container_of(p, struct jprobe, kp); 946 struct jprobe *jp = container_of(p, struct jprobe, kp);
942 unsigned long addr = ((struct fnptr *)(jp->entry))->ip; 947 unsigned long addr = arch_deref_entry_point(jp->entry);
943 struct kprobe_ctlblk *kcb = get_kprobe_ctlblk(); 948 struct kprobe_ctlblk *kcb = get_kprobe_ctlblk();
944 struct param_bsp_cfm pa; 949 struct param_bsp_cfm pa;
945 int bytes; 950 int bytes;
diff --git a/arch/powerpc/kernel/kprobes.c b/arch/powerpc/kernel/kprobes.c
index 0c96611f02f4..440f5a87271f 100644
--- a/arch/powerpc/kernel/kprobes.c
+++ b/arch/powerpc/kernel/kprobes.c
@@ -492,6 +492,13 @@ int __kprobes kprobe_exceptions_notify(struct notifier_block *self,
492 return ret; 492 return ret;
493} 493}
494 494
495#ifdef CONFIG_PPC64
496unsigned long arch_deref_entry_point(void *entry)
497{
498 return (unsigned long)(((func_descr_t *)entry)->entry);
499}
500#endif
501
495int __kprobes setjmp_pre_handler(struct kprobe *p, struct pt_regs *regs) 502int __kprobes setjmp_pre_handler(struct kprobe *p, struct pt_regs *regs)
496{ 503{
497 struct jprobe *jp = container_of(p, struct jprobe, kp); 504 struct jprobe *jp = container_of(p, struct jprobe, kp);
@@ -500,11 +507,9 @@ int __kprobes setjmp_pre_handler(struct kprobe *p, struct pt_regs *regs)
500 memcpy(&kcb->jprobe_saved_regs, regs, sizeof(struct pt_regs)); 507 memcpy(&kcb->jprobe_saved_regs, regs, sizeof(struct pt_regs));
501 508
502 /* setup return addr to the jprobe handler routine */ 509 /* setup return addr to the jprobe handler routine */
510 regs->nip = arch_deref_entry_point(jp->entry);
503#ifdef CONFIG_PPC64 511#ifdef CONFIG_PPC64
504 regs->nip = (unsigned long)(((func_descr_t *)jp->entry)->entry);
505 regs->gpr[2] = (unsigned long)(((func_descr_t *)jp->entry)->toc); 512 regs->gpr[2] = (unsigned long)(((func_descr_t *)jp->entry)->toc);
506#else
507 regs->nip = (unsigned long)jp->entry;
508#endif 513#endif
509 514
510 return 1; 515 return 1;