kprobes: bugfix: try_module_get even if calling_mod is NULL
authorMasami Hiramatsu <[email protected]>
Tue, 6 Jan 2009 22:41:46 +0000 (14:41 -0800)
committerLinus Torvalds <[email protected]>
Tue, 6 Jan 2009 23:59:20 +0000 (15:59 -0800)
When someone called register_*probe() from kernel-core code(not from
module) and that probes a kernel module, users can remove the probed
module because kprobe doesn't increment reference counter of the module.
(on the other hand, if the kernel-module calls register_*probe, kprobe
increments refcount of the probed module.)

Currently, we have no register_*probe() calling from kernel-core(except
smoke-test, but the smoke-test doesn't probe module), so there is no real
bugs.  But the logic is wrong(or not fair) and it can causes a problem
when someone might want to probe module from kernel.

After this patch is applied, even if someone put register_*probe() call in
the kernel-core code, it increments the reference counter of the probed
module, and it prevents user to remove the module until stopping probing
it.

Signed-off-by: Masami Hiramatsu <[email protected]>
Cc: Lai Jiangshan <[email protected]>
Cc: Ananth N Mavinakayanahalli <[email protected]>
Cc: Hiroshi Shimamoto <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
kernel/kprobes.c

index 9f8a3f25259a9da4c8535bab07014b07da79a643..3afd354c46f1ebac4e6a86cf5912c763a03725d3 100644 (file)
@@ -634,7 +634,7 @@ static int __kprobes __register_kprobe(struct kprobe *p,
                 * avoid incrementing the module refcount, so as to allow
                 * unloading of self probing modules.
                 */
-               if (calling_mod && calling_mod != probed_mod) {
+               if (calling_mod != probed_mod) {
                        if (unlikely(!try_module_get(probed_mod))) {
                                preempt_enable();
                                return -EINVAL;