[PATCH] kprobe handler: discard user space trap
Currently kprobe handler traps only happen in kernel space, so function kprobe_exceptions_notify should skip traps which happen in user space. This patch modifies this, and it is based on 2.6.16-rc4. Signed-off-by: bibo mao <bibo.mao@intel.com> Cc: Ananth N Mavinakayanahalli <ananth@in.ibm.com> Cc: "Keshavamurthy, Anil S" <anil.s.keshavamurthy@intel.com> Cc: <hiramatu@sdl.hitachi.co.jp> Signed-off-by: Prasanna S Panchamukhi <prasanna@in.ibm.com> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
This commit is contained in:
@@ -203,13 +203,14 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
|
|||||||
{
|
{
|
||||||
struct kprobe *p;
|
struct kprobe *p;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
kprobe_opcode_t *addr = NULL;
|
kprobe_opcode_t *addr;
|
||||||
unsigned long *lp;
|
|
||||||
struct kprobe_ctlblk *kcb;
|
struct kprobe_ctlblk *kcb;
|
||||||
#ifdef CONFIG_PREEMPT
|
#ifdef CONFIG_PREEMPT
|
||||||
unsigned pre_preempt_count = preempt_count();
|
unsigned pre_preempt_count = preempt_count();
|
||||||
#endif /* CONFIG_PREEMPT */
|
#endif /* CONFIG_PREEMPT */
|
||||||
|
|
||||||
|
addr = (kprobe_opcode_t *)(regs->eip - sizeof(kprobe_opcode_t));
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* We don't want to be preempted for the entire
|
* We don't want to be preempted for the entire
|
||||||
* duration of kprobe processing
|
* duration of kprobe processing
|
||||||
@@ -217,17 +218,6 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
|
|||||||
preempt_disable();
|
preempt_disable();
|
||||||
kcb = get_kprobe_ctlblk();
|
kcb = get_kprobe_ctlblk();
|
||||||
|
|
||||||
/* Check if the application is using LDT entry for its code segment and
|
|
||||||
* calculate the address by reading the base address from the LDT entry.
|
|
||||||
*/
|
|
||||||
if ((regs->xcs & 4) && (current->mm)) {
|
|
||||||
lp = (unsigned long *) ((unsigned long)((regs->xcs >> 3) * 8)
|
|
||||||
+ (char *) current->mm->context.ldt);
|
|
||||||
addr = (kprobe_opcode_t *) (get_desc_base(lp) + regs->eip -
|
|
||||||
sizeof(kprobe_opcode_t));
|
|
||||||
} else {
|
|
||||||
addr = (kprobe_opcode_t *)(regs->eip - sizeof(kprobe_opcode_t));
|
|
||||||
}
|
|
||||||
/* Check we're not actually recursing */
|
/* Check we're not actually recursing */
|
||||||
if (kprobe_running()) {
|
if (kprobe_running()) {
|
||||||
p = get_kprobe(addr);
|
p = get_kprobe(addr);
|
||||||
@@ -579,6 +569,9 @@ int __kprobes kprobe_exceptions_notify(struct notifier_block *self,
|
|||||||
struct die_args *args = (struct die_args *)data;
|
struct die_args *args = (struct die_args *)data;
|
||||||
int ret = NOTIFY_DONE;
|
int ret = NOTIFY_DONE;
|
||||||
|
|
||||||
|
if (args->regs && user_mode(args->regs))
|
||||||
|
return ret;
|
||||||
|
|
||||||
switch (val) {
|
switch (val) {
|
||||||
case DIE_INT3:
|
case DIE_INT3:
|
||||||
if (kprobe_handler(args->regs))
|
if (kprobe_handler(args->regs))
|
||||||
|
@@ -740,6 +740,9 @@ int __kprobes kprobe_exceptions_notify(struct notifier_block *self,
|
|||||||
struct die_args *args = (struct die_args *)data;
|
struct die_args *args = (struct die_args *)data;
|
||||||
int ret = NOTIFY_DONE;
|
int ret = NOTIFY_DONE;
|
||||||
|
|
||||||
|
if (args->regs && user_mode(args->regs))
|
||||||
|
return ret;
|
||||||
|
|
||||||
switch(val) {
|
switch(val) {
|
||||||
case DIE_BREAK:
|
case DIE_BREAK:
|
||||||
/* err is break number from ia64_bad_break() */
|
/* err is break number from ia64_bad_break() */
|
||||||
|
@@ -396,6 +396,9 @@ int __kprobes kprobe_exceptions_notify(struct notifier_block *self,
|
|||||||
struct die_args *args = (struct die_args *)data;
|
struct die_args *args = (struct die_args *)data;
|
||||||
int ret = NOTIFY_DONE;
|
int ret = NOTIFY_DONE;
|
||||||
|
|
||||||
|
if (args->regs && user_mode(args->regs))
|
||||||
|
return ret;
|
||||||
|
|
||||||
switch (val) {
|
switch (val) {
|
||||||
case DIE_BPT:
|
case DIE_BPT:
|
||||||
if (kprobe_handler(args->regs))
|
if (kprobe_handler(args->regs))
|
||||||
|
@@ -324,6 +324,9 @@ int __kprobes kprobe_exceptions_notify(struct notifier_block *self,
|
|||||||
struct die_args *args = (struct die_args *)data;
|
struct die_args *args = (struct die_args *)data;
|
||||||
int ret = NOTIFY_DONE;
|
int ret = NOTIFY_DONE;
|
||||||
|
|
||||||
|
if (args->regs && user_mode(args->regs))
|
||||||
|
return ret;
|
||||||
|
|
||||||
switch (val) {
|
switch (val) {
|
||||||
case DIE_DEBUG:
|
case DIE_DEBUG:
|
||||||
if (kprobe_handler(args->regs))
|
if (kprobe_handler(args->regs))
|
||||||
|
@@ -601,6 +601,9 @@ int __kprobes kprobe_exceptions_notify(struct notifier_block *self,
|
|||||||
struct die_args *args = (struct die_args *)data;
|
struct die_args *args = (struct die_args *)data;
|
||||||
int ret = NOTIFY_DONE;
|
int ret = NOTIFY_DONE;
|
||||||
|
|
||||||
|
if (args->regs && user_mode(args->regs))
|
||||||
|
return ret;
|
||||||
|
|
||||||
switch (val) {
|
switch (val) {
|
||||||
case DIE_INT3:
|
case DIE_INT3:
|
||||||
if (kprobe_handler(args->regs))
|
if (kprobe_handler(args->regs))
|
||||||
|
Reference in New Issue
Block a user