提交 bc2f7015 编写于 作者: M Masami Hiramatsu 提交者: Linus Torvalds

kprobes: bugfix: try_module_get even if calling_mod is NULL

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: NMasami Hiramatsu <mhiramat@redhat.com>
Cc: Lai Jiangshan <laijs@cn.fujitsu.com>
Cc: Ananth N Mavinakayanahalli <ananth@in.ibm.com>
Cc: Hiroshi Shimamoto <h-shimamoto@ct.jp.nec.com>
Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
上级 51e911e2
...@@ -634,7 +634,7 @@ static int __kprobes __register_kprobe(struct kprobe *p, ...@@ -634,7 +634,7 @@ static int __kprobes __register_kprobe(struct kprobe *p,
* avoid incrementing the module refcount, so as to allow * avoid incrementing the module refcount, so as to allow
* unloading of self probing modules. * unloading of self probing modules.
*/ */
if (calling_mod && calling_mod != probed_mod) { 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;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册