From: Greg Kroah-Hartman Date: Fri, 22 Sep 2017 16:22:49 +0000 (+0200) Subject: 4.4-stable patches X-Git-Tag: v3.18.72~2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=43ce1a8ff269f24e8414e317654ed67e08b9271c;p=thirdparty%2Fkernel%2Fstable-queue.git 4.4-stable patches added patches: ftrace-fix-memleak-when-unregistering-dynamic-ops-when-tracing-disabled.patch --- diff --git a/queue-4.4/ftrace-fix-memleak-when-unregistering-dynamic-ops-when-tracing-disabled.patch b/queue-4.4/ftrace-fix-memleak-when-unregistering-dynamic-ops-when-tracing-disabled.patch new file mode 100644 index 00000000000..67aed5c677f --- /dev/null +++ b/queue-4.4/ftrace-fix-memleak-when-unregistering-dynamic-ops-when-tracing-disabled.patch @@ -0,0 +1,75 @@ +From edb096e00724f02db5f6ec7900f3bbd465c6c76f Mon Sep 17 00:00:00 2001 +From: "Steven Rostedt (VMware)" +Date: Fri, 1 Sep 2017 12:18:28 -0400 +Subject: ftrace: Fix memleak when unregistering dynamic ops when tracing disabled + +From: Steven Rostedt (VMware) + +commit edb096e00724f02db5f6ec7900f3bbd465c6c76f upstream. + +If function tracing is disabled by the user via the function-trace option or +the proc sysctl file, and a ftrace_ops that was allocated on the heap is +unregistered, then the shutdown code exits out without doing the proper +clean up. This was found via kmemleak and running the ftrace selftests, as +one of the tests unregisters with function tracing disabled. + + # cat kmemleak +unreferenced object 0xffffffffa0020000 (size 4096): + comm "swapper/0", pid 1, jiffies 4294668889 (age 569.209s) + hex dump (first 32 bytes): + 55 ff 74 24 10 55 48 89 e5 ff 74 24 18 55 48 89 U.t$.UH...t$.UH. + e5 48 81 ec a8 00 00 00 48 89 44 24 50 48 89 4c .H......H.D$PH.L + backtrace: + [] kmemleak_vmalloc+0x85/0xf0 + [] __vmalloc_node_range+0x281/0x3e0 + [] module_alloc+0x4f/0x90 + [] arch_ftrace_update_trampoline+0x160/0x420 + [] ftrace_startup+0xe7/0x300 + [] register_ftrace_function+0x72/0x90 + [] trace_selftest_ops+0x204/0x397 + [] trace_selftest_startup_function+0x394/0x624 + [] run_tracer_selftest+0x15c/0x1d7 + [] init_trace_selftests+0x75/0x192 + [] do_one_initcall+0x90/0x1e2 + [] kernel_init_freeable+0x350/0x3fe + [] kernel_init+0x13/0x122 + [] ret_from_fork+0x2a/0x40 + [] 0xffffffffffffffff + +Fixes: 12cce594fa ("ftrace/x86: Allow !CONFIG_PREEMPT dynamic ops to use allocated trampolines") +Signed-off-by: Steven Rostedt (VMware) +Signed-off-by: Greg Kroah-Hartman + +--- + kernel/trace/ftrace.c | 10 ++++++---- + 1 file changed, 6 insertions(+), 4 deletions(-) + +--- a/kernel/trace/ftrace.c ++++ b/kernel/trace/ftrace.c +@@ -2667,13 +2667,14 @@ static int ftrace_shutdown(struct ftrace + + if (!command || !ftrace_enabled) { + /* +- * If these are control ops, they still need their +- * per_cpu field freed. Since, function tracing is ++ * If these are dynamic or control ops, they still ++ * need their data freed. Since, function tracing is + * not currently active, we can just free them + * without synchronizing all CPUs. + */ +- if (ops->flags & FTRACE_OPS_FL_CONTROL) +- control_ops_free(ops); ++ if (ops->flags & (FTRACE_OPS_FL_DYNAMIC | FTRACE_OPS_FL_CONTROL)) ++ goto free_ops; ++ + return 0; + } + +@@ -2728,6 +2729,7 @@ static int ftrace_shutdown(struct ftrace + if (ops->flags & (FTRACE_OPS_FL_DYNAMIC | FTRACE_OPS_FL_CONTROL)) { + schedule_on_each_cpu(ftrace_sync); + ++ free_ops: + arch_ftrace_trampoline_free(ops); + + if (ops->flags & FTRACE_OPS_FL_CONTROL) diff --git a/queue-4.4/series b/queue-4.4/series index aea209febc1..56f0ccdf7b7 100644 --- a/queue-4.4/series +++ b/queue-4.4/series @@ -62,3 +62,4 @@ bcache-correct-cache_dirty_target-in-__update_writeback_rate.patch bcache-correct-return-value-for-sysfs-attach-errors.patch bcache-fix-for-gc-and-write-back-race.patch bcache-fix-bch_hprint-crash-and-improve-output.patch +ftrace-fix-memleak-when-unregistering-dynamic-ops-when-tracing-disabled.patch