aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2016-01-07 15:42:22 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2016-01-07 15:42:22 -0500
commit2626820d838f9e98f323bf47b4fb7722d1c52e53 (patch)
tree24e6a71ca7fa285e0f6374cf977ebd98b6f935bd
parentb06f3a168cdcd80026276898fd1fee443ef25743 (diff)
parent049fb9bd416077b3622d317a45796be4f2431df3 (diff)
Merge tag 'trace-v4.4-rc4-4' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace
Pull ftrace fix from Steven Rostedt: "PeiyangX Qiu reported that if a module fails to load between calling ftrace_module_init() and do_init_module() that the allocations made in ftrace_module_init() will not be freed, resulting in a memory leak. The solution is to call ftrace_release_mod() on the failing module in the fail path befor do_init_module() is called. This will remove any allocations made for that module, and nothing if ftrace_module_init() wasn't called yet for that module. Note, once do_init_module() is called, the MODULE_GOING notifiers are called for the failed module, which calls into the ftrace code to do the proper clean up (basically calling ftrace_release_mod())" * tag 'trace-v4.4-rc4-4' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace: ftrace/module: Call clean up function when module init fails early
-rw-r--r--include/linux/ftrace.h1
-rw-r--r--kernel/module.c6
2 files changed, 7 insertions, 0 deletions
diff --git a/include/linux/ftrace.h b/include/linux/ftrace.h
index eae6548efbf0..60048c50404e 100644
--- a/include/linux/ftrace.h
+++ b/include/linux/ftrace.h
@@ -586,6 +586,7 @@ extern int ftrace_arch_read_dyn_info(char *buf, int size);
586 586
587extern int skip_trace(unsigned long ip); 587extern int skip_trace(unsigned long ip);
588extern void ftrace_module_init(struct module *mod); 588extern void ftrace_module_init(struct module *mod);
589extern void ftrace_release_mod(struct module *mod);
589 590
590extern void ftrace_disable_daemon(void); 591extern void ftrace_disable_daemon(void);
591extern void ftrace_enable_daemon(void); 592extern void ftrace_enable_daemon(void);
diff --git a/kernel/module.c b/kernel/module.c
index 8f051a106676..38c7bd5583ff 100644
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -3571,6 +3571,12 @@ static int load_module(struct load_info *info, const char __user *uargs,
3571 synchronize_sched(); 3571 synchronize_sched();
3572 mutex_unlock(&module_mutex); 3572 mutex_unlock(&module_mutex);
3573 free_module: 3573 free_module:
3574 /*
3575 * Ftrace needs to clean up what it initialized.
3576 * This does nothing if ftrace_module_init() wasn't called,
3577 * but it must be called outside of module_mutex.
3578 */
3579 ftrace_release_mod(mod);
3574 /* Free lock-classes; relies on the preceding sync_rcu() */ 3580 /* Free lock-classes; relies on the preceding sync_rcu() */
3575 lockdep_free_key_range(mod->module_core, mod->core_size); 3581 lockdep_free_key_range(mod->module_core, mod->core_size);
3576 3582