Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 169430
b: refs/heads/master
c: 1f0ab40
h: refs/heads/master
v: v3
  • Loading branch information
Ananth N Mavinakayanahalli authored and Frederic Weisbecker committed Sep 17, 2009
1 parent d47d28b commit f30fedb
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 21 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 5a0d9050db4d1147722b42afef9011251b2651ee
refs/heads/master: 1f0ab40976460bc4673fa204ce917a725185d8f2
58 changes: 38 additions & 20 deletions trunk/kernel/kprobes.c
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,40 @@ static kprobe_opcode_t __kprobes *kprobe_addr(struct kprobe *p)
return (kprobe_opcode_t *)(((char *)addr) + p->offset);
}

/* Check passed kprobe is valid and return kprobe in kprobe_table. */
static struct kprobe * __kprobes __get_valid_kprobe(struct kprobe *p)
{
struct kprobe *old_p, *list_p;

old_p = get_kprobe(p->addr);
if (unlikely(!old_p))
return NULL;

if (p != old_p) {
list_for_each_entry_rcu(list_p, &old_p->list, list)
if (list_p == p)
/* kprobe p is a valid probe */
goto valid;
return NULL;
}
valid:
return old_p;
}

/* Return error if the kprobe is being re-registered */
static inline int check_kprobe_rereg(struct kprobe *p)
{
int ret = 0;
struct kprobe *old_p;

mutex_lock(&kprobe_mutex);
old_p = __get_valid_kprobe(p);
if (old_p)
ret = -EINVAL;
mutex_unlock(&kprobe_mutex);
return ret;
}

int __kprobes register_kprobe(struct kprobe *p)
{
int ret = 0;
Expand All @@ -688,6 +722,10 @@ int __kprobes register_kprobe(struct kprobe *p)
return -EINVAL;
p->addr = addr;

ret = check_kprobe_rereg(p);
if (ret)
return ret;

preempt_disable();
if (!kernel_text_address((unsigned long) p->addr) ||
in_kprobes_functions((unsigned long) p->addr)) {
Expand Down Expand Up @@ -757,26 +795,6 @@ int __kprobes register_kprobe(struct kprobe *p)
}
EXPORT_SYMBOL_GPL(register_kprobe);

/* Check passed kprobe is valid and return kprobe in kprobe_table. */
static struct kprobe * __kprobes __get_valid_kprobe(struct kprobe *p)
{
struct kprobe *old_p, *list_p;

old_p = get_kprobe(p->addr);
if (unlikely(!old_p))
return NULL;

if (p != old_p) {
list_for_each_entry_rcu(list_p, &old_p->list, list)
if (list_p == p)
/* kprobe p is a valid probe */
goto valid;
return NULL;
}
valid:
return old_p;
}

/*
* Unregister a kprobe without a scheduler synchronization.
*/
Expand Down

0 comments on commit f30fedb

Please sign in to comment.