Re: [PATCH] kprobes for 2.5.47

Rusty Lynch (rusty@linux.co.intel.com)
Tue, 12 Nov 2002 20:15:20 -0800


Actually I'm not verifying the address correctly because I need to verify
a kernel mapped address is valid, not a user space address.

Anyone know how to verify a kernel space address is valid?

-rustyl

----- Original Message -----
From: "Randy.Dunlap" <rddunlap@osdl.org>
To: "Rusty Lynch" <rusty@linux.co.intel.com>
Cc: <vamsi@in.ibm.com>; <rusty@rustcorp.com.au>; "lkml"
<linux-kernel@vger.kernel.org>
Sent: Tuesday, November 12, 2002 7:08 PM
Subject: Re: [PATCH] kprobes for 2.5.47

> On Tue, 12 Nov 2002, Rusty Lynch wrote:
>
> | When register_kprobe() is called with a bad addr, we crash the kernel.
> | Should it be the reponsibility of the caller, or the kernel to make sure
the
> | addr is ok?
> |
> | The kernel could check by adding a
> |
> | +unsigned short tmp;
> | ....
> | +if(__get_user(tmp, (unsigned short *)p->addr)) {
> | + ret = -EINVAL;
> | + goto out;
> | +}
> |
> | to register_kprobe()
>
> This looks good to me. Kernel should check user addresses.
>
> | > +int register_kprobe(struct kprobe *p)
> | > +{
> | > + int ret = 0;
> | > +
> | > + spin_lock_irq(&kprobe_lock);
> | > + if (get_kprobe(p->addr)) {
> | > + ret = -EEXIST;
> | > + goto out;
> | > + }
> | > + list_add(&p->list, &kprobe_table[hash_ptr(p->addr,
KPROBE_HASH_BITS)]);
> | > +
> | > + p->opcode = *p->addr;
> | > + *p->addr = BREAKPOINT_INSTRUCTION;
> | > + flush_icache_range(p->addr, p->addr + sizeof(kprobe_opcode_t));
> | > + out:
> | > + spin_unlock_irq(&kprobe_lock);
> | > + return ret;
> | > +}
> |
> | BTW, I have a stupid little sample char driver that reads in
address/message
> | pairs and then adds a probe that printk's the message at the address.
This
> | was just my way of learning how to use kprobes. Should I post it? I
would
> | love to get feedback on what I did wrong, but I hate to spam the list.
>
> I'd like to see it, but from a learning POV instead of telling
> you what you did wrong with it.
>
> Thanks.
> --
> ~Randy
> "I read part of it all the way through." -- Samuel Goldwyn

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/