Commit 49ad2fd7 authored by Masami Hiramatsu's avatar Masami Hiramatsu Committed by Linus Torvalds

kprobes: remove called_from argument

Remove called_from argument from kprobes which had been used for
preventing self-refering of kernel module.  However, since we don't keep
module's refcount after registering kprobe any more, there is no reason to
check that.

This patch also simplifies registering/unregistering functions because we
don't need to use __builtin_return_address(0) which was passed to
called_from.

[ananth@in.ibm.com: build fix]
Signed-off-by: default avatarMasami Hiramatsu <mhiramat@redhat.com>
Acked-by: default avatarAnanth N Mavinakayanahalli <ananth@in.ibm.com>
Cc: Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com>
Signed-off-by: default avatarAnanth N Mavinakayanahalli <ananth@in.ibm.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent e8386a0c
...@@ -644,8 +644,7 @@ static kprobe_opcode_t __kprobes *kprobe_addr(struct kprobe *p) ...@@ -644,8 +644,7 @@ static kprobe_opcode_t __kprobes *kprobe_addr(struct kprobe *p)
return (kprobe_opcode_t *)(((char *)addr) + p->offset); return (kprobe_opcode_t *)(((char *)addr) + p->offset);
} }
static int __kprobes __register_kprobe(struct kprobe *p, int __kprobes register_kprobe(struct kprobe *p)
unsigned long called_from)
{ {
int ret = 0; int ret = 0;
struct kprobe *old_p; struct kprobe *old_p;
...@@ -670,19 +669,14 @@ static int __kprobes __register_kprobe(struct kprobe *p, ...@@ -670,19 +669,14 @@ static int __kprobes __register_kprobe(struct kprobe *p,
*/ */
probed_mod = __module_text_address((unsigned long) p->addr); probed_mod = __module_text_address((unsigned long) p->addr);
if (probed_mod) { if (probed_mod) {
struct module *calling_mod;
calling_mod = __module_text_address(called_from);
/* /*
* We must hold a refcount of the probed module while updating * We must hold a refcount of the probed module while updating
* its code to prohibit unexpected unloading. * its code to prohibit unexpected unloading.
*/ */
if (calling_mod != probed_mod) { if (unlikely(!try_module_get(probed_mod))) {
if (unlikely(!try_module_get(probed_mod))) { preempt_enable();
preempt_enable(); return -EINVAL;
return -EINVAL; }
}
} else
probed_mod = NULL;
} }
preempt_enable(); preempt_enable();
...@@ -776,15 +770,14 @@ static void __kprobes __unregister_kprobe_bottom(struct kprobe *p) ...@@ -776,15 +770,14 @@ static void __kprobes __unregister_kprobe_bottom(struct kprobe *p)
} }
} }
static int __kprobes __register_kprobes(struct kprobe **kps, int num, int __kprobes register_kprobes(struct kprobe **kps, int num)
unsigned long called_from)
{ {
int i, ret = 0; int i, ret = 0;
if (num <= 0) if (num <= 0)
return -EINVAL; return -EINVAL;
for (i = 0; i < num; i++) { for (i = 0; i < num; i++) {
ret = __register_kprobe(kps[i], called_from); ret = register_kprobe(kps[i]);
if (ret < 0) { if (ret < 0) {
if (i > 0) if (i > 0)
unregister_kprobes(kps, i); unregister_kprobes(kps, i);
...@@ -794,26 +787,11 @@ static int __kprobes __register_kprobes(struct kprobe **kps, int num, ...@@ -794,26 +787,11 @@ static int __kprobes __register_kprobes(struct kprobe **kps, int num,
return ret; return ret;
} }
/*
* Registration and unregistration functions for kprobe.
*/
int __kprobes register_kprobe(struct kprobe *p)
{
return __register_kprobes(&p, 1,
(unsigned long)__builtin_return_address(0));
}
void __kprobes unregister_kprobe(struct kprobe *p) void __kprobes unregister_kprobe(struct kprobe *p)
{ {
unregister_kprobes(&p, 1); unregister_kprobes(&p, 1);
} }
int __kprobes register_kprobes(struct kprobe **kps, int num)
{
return __register_kprobes(kps, num,
(unsigned long)__builtin_return_address(0));
}
void __kprobes unregister_kprobes(struct kprobe **kps, int num) void __kprobes unregister_kprobes(struct kprobe **kps, int num)
{ {
int i; int i;
...@@ -842,8 +820,7 @@ unsigned long __weak arch_deref_entry_point(void *entry) ...@@ -842,8 +820,7 @@ unsigned long __weak arch_deref_entry_point(void *entry)
return (unsigned long)entry; return (unsigned long)entry;
} }
static int __kprobes __register_jprobes(struct jprobe **jps, int num, int __kprobes register_jprobes(struct jprobe **jps, int num)
unsigned long called_from)
{ {
struct jprobe *jp; struct jprobe *jp;
int ret = 0, i; int ret = 0, i;
...@@ -861,7 +838,7 @@ static int __kprobes __register_jprobes(struct jprobe **jps, int num, ...@@ -861,7 +838,7 @@ static int __kprobes __register_jprobes(struct jprobe **jps, int num,
/* Todo: Verify probepoint is a function entry point */ /* Todo: Verify probepoint is a function entry point */
jp->kp.pre_handler = setjmp_pre_handler; jp->kp.pre_handler = setjmp_pre_handler;
jp->kp.break_handler = longjmp_break_handler; jp->kp.break_handler = longjmp_break_handler;
ret = __register_kprobe(&jp->kp, called_from); ret = register_kprobe(&jp->kp);
} }
if (ret < 0) { if (ret < 0) {
if (i > 0) if (i > 0)
...@@ -874,8 +851,7 @@ static int __kprobes __register_jprobes(struct jprobe **jps, int num, ...@@ -874,8 +851,7 @@ static int __kprobes __register_jprobes(struct jprobe **jps, int num,
int __kprobes register_jprobe(struct jprobe *jp) int __kprobes register_jprobe(struct jprobe *jp)
{ {
return __register_jprobes(&jp, 1, return register_jprobes(&jp, 1);
(unsigned long)__builtin_return_address(0));
} }
void __kprobes unregister_jprobe(struct jprobe *jp) void __kprobes unregister_jprobe(struct jprobe *jp)
...@@ -883,12 +859,6 @@ void __kprobes unregister_jprobe(struct jprobe *jp) ...@@ -883,12 +859,6 @@ void __kprobes unregister_jprobe(struct jprobe *jp)
unregister_jprobes(&jp, 1); unregister_jprobes(&jp, 1);
} }
int __kprobes register_jprobes(struct jprobe **jps, int num)
{
return __register_jprobes(jps, num,
(unsigned long)__builtin_return_address(0));
}
void __kprobes unregister_jprobes(struct jprobe **jps, int num) void __kprobes unregister_jprobes(struct jprobe **jps, int num)
{ {
int i; int i;
...@@ -951,8 +921,7 @@ static int __kprobes pre_handler_kretprobe(struct kprobe *p, ...@@ -951,8 +921,7 @@ static int __kprobes pre_handler_kretprobe(struct kprobe *p,
return 0; return 0;
} }
static int __kprobes __register_kretprobe(struct kretprobe *rp, int __kprobes register_kretprobe(struct kretprobe *rp)
unsigned long called_from)
{ {
int ret = 0; int ret = 0;
struct kretprobe_instance *inst; struct kretprobe_instance *inst;
...@@ -998,21 +967,20 @@ static int __kprobes __register_kretprobe(struct kretprobe *rp, ...@@ -998,21 +967,20 @@ static int __kprobes __register_kretprobe(struct kretprobe *rp,
rp->nmissed = 0; rp->nmissed = 0;
/* Establish function entry probe point */ /* Establish function entry probe point */
ret = __register_kprobe(&rp->kp, called_from); ret = register_kprobe(&rp->kp);
if (ret != 0) if (ret != 0)
free_rp_inst(rp); free_rp_inst(rp);
return ret; return ret;
} }
static int __kprobes __register_kretprobes(struct kretprobe **rps, int num, int __kprobes register_kretprobes(struct kretprobe **rps, int num)
unsigned long called_from)
{ {
int ret = 0, i; int ret = 0, i;
if (num <= 0) if (num <= 0)
return -EINVAL; return -EINVAL;
for (i = 0; i < num; i++) { for (i = 0; i < num; i++) {
ret = __register_kretprobe(rps[i], called_from); ret = register_kretprobe(rps[i]);
if (ret < 0) { if (ret < 0) {
if (i > 0) if (i > 0)
unregister_kretprobes(rps, i); unregister_kretprobes(rps, i);
...@@ -1022,23 +990,11 @@ static int __kprobes __register_kretprobes(struct kretprobe **rps, int num, ...@@ -1022,23 +990,11 @@ static int __kprobes __register_kretprobes(struct kretprobe **rps, int num,
return ret; return ret;
} }
int __kprobes register_kretprobe(struct kretprobe *rp)
{
return __register_kretprobes(&rp, 1,
(unsigned long)__builtin_return_address(0));
}
void __kprobes unregister_kretprobe(struct kretprobe *rp) void __kprobes unregister_kretprobe(struct kretprobe *rp)
{ {
unregister_kretprobes(&rp, 1); unregister_kretprobes(&rp, 1);
} }
int __kprobes register_kretprobes(struct kretprobe **rps, int num)
{
return __register_kretprobes(rps, num,
(unsigned long)__builtin_return_address(0));
}
void __kprobes unregister_kretprobes(struct kretprobe **rps, int num) void __kprobes unregister_kretprobes(struct kretprobe **rps, int num)
{ {
int i; int i;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment