* [PATCH] Kprobes: Verify probepoint in register_jprobe()
@ 2005-06-29 15:24 Luca Falavigna
2005-06-29 18:31 ` Andrew Morton
2005-06-30 14:13 ` Paulo Marques
0 siblings, 2 replies; 3+ messages in thread
From: Luca Falavigna @ 2005-06-29 15:24 UTC (permalink / raw)
To: prasanna; +Cc: Linux Kernel Mailing List
This patch, built against version 2.6.12, checks if probepoint address is a
function entry point using an offset value, obtained from kallsyms_lookup().
If offset is zero, we register jprobe, otherwise we return -EINVAL.
Signed-off-by: Luca Falavigna <dktrkranz@gmail.com>
--- ./kernel/kprobes.c.orig 2005-06-29 00:17:43.000000000 +0000
+++ ./kernel/kprobes.c 2005-06-29 11:08:02.000000000 +0000
@@ -33,6 +33,7 @@
#include <linux/hash.h>
#include <linux/init.h>
#include <linux/module.h>
+#include <linux/kallsyms.h>
#include <asm/cacheflush.h>
#include <asm/errno.h>
#include <asm/kdebug.h>
@@ -245,7 +246,15 @@ static struct notifier_block kprobe_exce
int register_jprobe(struct jprobe *jp)
{
- /* Todo: Verify probepoint is a function entry point */
+ unsigned long size, offset;
+ char *modname, namebuf[KSYM_NAME_LEN+1];
+
+ kallsyms_lookup((unsigned long)jp->kp.addr, &size,
+ &offset, &modname, namebuf);
+
+ if(unlikely(offset))
+ return -EINVAL;
+
jp->kp.pre_handler = setjmp_pre_handler;
jp->kp.break_handler = longjmp_break_handler;
Regards,
--
Luca
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] Kprobes: Verify probepoint in register_jprobe()
2005-06-29 15:24 [PATCH] Kprobes: Verify probepoint in register_jprobe() Luca Falavigna
@ 2005-06-29 18:31 ` Andrew Morton
2005-06-30 14:13 ` Paulo Marques
1 sibling, 0 replies; 3+ messages in thread
From: Andrew Morton @ 2005-06-29 18:31 UTC (permalink / raw)
To: Luca Falavigna; +Cc: prasanna, linux-kernel
Luca Falavigna <dktrkranz@gmail.com> wrote:
>
> This patch, built against version 2.6.12, checks if probepoint address is a
> function entry point using an offset value, obtained from kallsyms_lookup().
> If offset is zero, we register jprobe, otherwise we return -EINVAL.
>
a) kallsyms holds symbols other than just function names.
b) This won't work with CONFIG_KALLSYMS=n
>
> --- ./kernel/kprobes.c.orig 2005-06-29 00:17:43.000000000 +0000
> +++ ./kernel/kprobes.c 2005-06-29 11:08:02.000000000 +0000
> @@ -33,6 +33,7 @@
> #include <linux/hash.h>
> #include <linux/init.h>
> #include <linux/module.h>
> +#include <linux/kallsyms.h>
> #include <asm/cacheflush.h>
> #include <asm/errno.h>
> #include <asm/kdebug.h>
> @@ -245,7 +246,15 @@ static struct notifier_block kprobe_exce
>
> int register_jprobe(struct jprobe *jp)
> {
> - /* Todo: Verify probepoint is a function entry point */
> + unsigned long size, offset;
> + char *modname, namebuf[KSYM_NAME_LEN+1];
> +
> + kallsyms_lookup((unsigned long)jp->kp.addr, &size,
> + &offset, &modname, namebuf);
> +
> + if(unlikely(offset))
> + return -EINVAL;
> +
> jp->kp.pre_handler = setjmp_pre_handler;
> jp->kp.break_handler = longjmp_break_handler;
>
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] Kprobes: Verify probepoint in register_jprobe()
2005-06-29 15:24 [PATCH] Kprobes: Verify probepoint in register_jprobe() Luca Falavigna
2005-06-29 18:31 ` Andrew Morton
@ 2005-06-30 14:13 ` Paulo Marques
1 sibling, 0 replies; 3+ messages in thread
From: Paulo Marques @ 2005-06-30 14:13 UTC (permalink / raw)
To: Luca Falavigna; +Cc: prasanna, Linux Kernel Mailing List
Luca Falavigna wrote:
> [...]
> int register_jprobe(struct jprobe *jp)
> {
> - /* Todo: Verify probepoint is a function entry point */
> + unsigned long size, offset;
> + char *modname, namebuf[KSYM_NAME_LEN+1];
> +
> + kallsyms_lookup((unsigned long)jp->kp.addr, &size,
> + &offset, &modname, namebuf);
> +
> + if(unlikely(offset))
> + return -EINVAL;
Hmmm, kallsyms_lookup might return NULL if either the address is not
found or CONFIG_KALLSYMS is not set, and in this case "offset" is not
initialized at all before this test.
We should either fail in this case, or accept the address as valid
without confirmation. I don't have sufficient knowledge about kprobes to
advise either way, but a test should be made nevertheless (or we could
just initialize "offset" to 0, if we want to accept the address without
confirmation).
--
Paulo Marques - www.grupopie.com
It is a mistake to think you can solve any major problems
just with potatoes.
Douglas Adams
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2005-06-30 14:14 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-06-29 15:24 [PATCH] Kprobes: Verify probepoint in register_jprobe() Luca Falavigna
2005-06-29 18:31 ` Andrew Morton
2005-06-30 14:13 ` Paulo Marques
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox