tracing: Some fixes for 4.8 (and earlier)
Subsystems (3)
Steven Rostedt
maintainerPATCH 1/4 ftrace/recordmcount: Work around for addition of metag magic but not relocations
In reply to Steven RostedtFrom: Laura Abbott <[email protected]>
glibc recently did a sync up (94e73c95d9b5 "elf.h: Sync with the gabi webpage") that added a #define for EM_METAG but did not add relocations
This triggers build errors:
scripts/recordmcount.c: In function 'do_file':scripts/recordmcount.c:466:28: error: 'R_METAG_ADDR32' undeclared (first use in this function)
case EM_METAG: reltype = R_METAG_ADDR32;
^~~~~~~~~~~~~~
scripts/recordmcount.c:466:28: note: each undeclared identifier is reported only once for each function it appears in
scripts/recordmcount.c:468:20: error: 'R_METAG_NONE' undeclared (first use in this function)
rel_type_nop = R_METAG_NONE;
^~~~~~~~~~~~Work around this change with some more #ifdefery for the relocations.
Fedora Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1354034
--- scripts/recordmcount.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
scripts/recordmcount.c +8 -1
@@ -33,10 +33,17 @@#include <string.h> #include <unistd.h> +/* +* glibc synced up and added the metag number but didn't add the relocations. +* Work around this in a crude manner for now. +*/ #ifndef EM_METAG -/* Remove this when these make it to the standard system elf.h. */ #define EM_METAG 174 +#endif +#ifndef R_METAG_ADDR32 #define R_METAG_ADDR32 2 +#endif +#ifndef R_METAG_NONE #define R_METAG_NONE 3#endif
Signature · 1 line
2.8.1
Steven Rostedt
maintainerLinus,
A few updates and fixes:
. Move the suppressing of the __builtin_return_address >0 warning to the
tracing directory only.
. metag recordmcount fix for newer glibc's
. Two tracing histogram fixes that were reported by KASAN
Please pull the latest trace-v4.8-1 tree, which can be found at:
git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace.git
trace-v4.8-1
Tag SHA1: 2b56101983196edf7c1b2cfcec5fcfeb87a166c6 Head SHA1: 7522c03ae307e657114ff909aec650304371a134
Laura Abbott (1):
ftrace/recordmcount: Work around for addition of metag magic but not relocations
Steven Rostedt (2):
Makefile: Mute warning for __builtin_return_address(>0) for tracing only
tracing: Fix use-after-free in hist_unreg_all/hist_enable_unreg_all
Tom Zanussi (1):
tracing: Fix use-after-free in hist_register_trigger()
----
Makefile | 1 - kernel/trace/Makefile | 4 ++++ kernel/trace/trace_events_hist.c | 14 +++++++------- scripts/recordmcount.c | 9 ++++++++- 4 files changed, 19 insertions(+), 9 deletions(-)
Steven Rostedt
maintainerPATCH 4/4 tracing: Fix use-after-free in hist_register_trigger()
From: Tom Zanussi <[email protected]>
This fixes a use-after-free case flagged by KASAN; make sure the test happens before the potential free in this case.
--- kernel/trace/trace_events_hist.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
kernel/trace/trace_events_hist.c +3 -3
@@ -1441,6 +1441,9 @@ static int hist_register_trigger(char *glob, struct event_trigger_ops *ops, goto out; } +if (hist_data->attrs->pause) + data->paused = true; +if (named_data) {destroy_hist_data (data->private_data); data->private_data = named_data->private_data;
@@ -1448,9 +1451,6 @@ static int hist_register_trigger(char *glob, struct event_trigger_ops *ops, data->ops = &event_hist_trigger_named_ops; } -if (hist_data->attrs->pause) - data->paused = true; -if (data->ops->init) { ret = data->ops->init (data->ops, data);if (ret <0 )
Signature · 1 line
2.8.1
Steven Rostedt
maintainerPATCH 2/4 Makefile: Mute warning for __builtin_return_address(>0) for tracing only
In reply to Steven RostedtFrom: Steven Rostedt <[email protected]>
With the latest gcc compilers, they give a warning if __builtin_return_address() parameter is greater than 0. That is because if it is used by a function called by a top level function (or in the case of the kernel, by assembly), it can try to access stack frames outside the stack and crash the system.
The tracing system uses __builtin_return_address() of up to 2! But it is well aware of the dangers that it may have, and has even added precautions to protect against it (see the thunk code in arch/x86/entry/thunk*.S)
Linus originally added KBUILD_CFLAGS that would suppress the warning for the entire kernel, as simply adding KBUILD_CFLAGS to the tracing directory wouldn't work. The tracing directory plays a bit with the CFLAGS and requires a little more logic.
This adds that special logic to only suppress the warning for the tracing directory. If it is used anywhere else outside of tracing, the warning will still be triggered.
--- Makefile | 1 - kernel/trace/Makefile | 4 ++++ 2 files changed, 4 insertions(+), 1 deletion(-)
Makefile +0 -1
@@ -620,7 +620,6 @@ include arch/$(SRCARCH)/Makefile KBUILD_CFLAGS += $(call cc-option,-fno-delete-null-pointer-checks,) KBUILD_CFLAGS += $(call cc-disable-warning,maybe-uninitialized,) -KBUILD_CFLAGS += $(call cc-disable-warning,frame-address,) ifdef CONFIG_CC_OPTIMIZE_FOR_SIZE KBUILD_CFLAGS += -Os
kernel/trace/Makefile +4 -0
@@ -1,4 +1,8 @@ +# We are fully aware of the dangers of __builtin_return_address() +FRAME_CFLAGS := $(call cc-disable-warning,frame-address) +KBUILD_CFLAGS += $(FRAME_CFLAGS) + # Do not instrument the tracer itself: ifdef CONFIG_FUNCTION_TRACER
Signature · 1 line
2.8.1
Steven Rostedt
maintainerPATCH 3/4 tracing: Fix use-after-free in hist_unreg_all/hist_enable_unreg_all
In reply to Steven RostedtFrom: Steven Rostedt <[email protected]>
While running tools/testing/selftests test suite with KASAN, Dmitry Vyukov hit the following use-after-free report:
==================================================================
BUG: KASAN: use-after-free in hist_unreg_all+0x1a1/0x1d0 at addr ffff880031632cc0 Read of size 8 by task ftracetest/7413 ================================================================== BUG kmalloc-128 (Not tainted): kasan: bad access detected ------------------------------------------------------------------
This fixes the problem, along with the same problem in hist_enable_unreg_all().
--- kernel/trace/trace_events_hist.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
kernel/trace/trace_events_hist.c +4 -4
@@ -1500,9 +1500,9 @@ static void hist_unregister_trigger(char *glob, struct event_trigger_ops *ops,static void hist_unreg_all (struct trace_event_file *file) { -struct event_trigger_data *test; +struct event_trigger_data *test, *n; -list_for_each_entry_rcu (test, &file->triggers, list) { +list_for_each_entry_safe (test, n, &file->triggers, list) {if (test->cmd_ops->trigger_type ==ETT_EVENT_HIST ) {list_del_rcu (&test->list);trace_event_trigger_enable_disable (file,0 );
@@ -1699,9 +1699,9 @@ hist_enable_get_trigger_ops(char *cmd, char *param)static void hist_enable_unreg_all (struct trace_event_file *file) { -struct event_trigger_data *test; +struct event_trigger_data *test, *n; -list_for_each_entry_rcu (test, &file->triggers, list) { +list_for_each_entry_safe (test, n, &file->triggers, list) {if (test->cmd_ops->trigger_type ==ETT_HIST_ENABLE ) {list_del_rcu (&test->list);update_cond_flag (file);
Signature · 1 line
2.8.1
Re: [PATCH 3/4] tracing: Fix use-after-free in hist_unreg_all/hist_enable_unreg_all
Quoted 13 lines · Steven Rostedt
From: Steven Rostedt <[email protected]>
While running
tools/testing/selfteststest suite with KASAN, Dmitry Vyukov hit the following use-after-free report:==================================================================
BUG: KASAN: use-after-free in hist_unreg_all+0x1a1/0x1d0 at addr ffff880031632cc0 Read of size 8 by task ftracetest/7413 ================================================================== BUG kmalloc-128 (Not tainted): kasan: bad access detected ------------------------------------------------------------------
Quoted 6 lines
This fixes the problem, along with the same problem in
hist_enable_unreg_all().Cc Dmitry Vyukov <[email protected]>
s/Cc/Reported-by/ please
Quoted 39 lines
[Copied Steve's hist_enable_unreg_all() fix to hist_unreg_all()]Signed-off-by Tom Zanussi <[email protected]>Signed-off-by Steven Rostedt <[email protected]>--- kernel/trace/trace_events_hist.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)kernel/trace/trace_events_hist.c +4
-5@@ -1500,9 +1500,9 @@ static void hist_unregister_trigger(char *glob, struct event_trigger_ops *ops,static void hist_unreg_all (struct trace_event_file *file) { -struct event_trigger_data *test; +struct event_trigger_data *test, *n; -list_for_each_entry_rcu (test, &file->triggers, list) { +list_for_each_entry_safe (test, n, &file->triggers, list) {if (test->cmd_ops->trigger_type ==ETT_EVENT_HIST ) {list_del_rcu (&test->list);trace_event_trigger_enable_disable (file,0 );@@ -1699,9 +1699,9 @@ hist_enable_get_trigger_ops(char *cmd, char *param)static void hist_enable_unreg_all (struct trace_event_file *file) { -struct event_trigger_data *test; +struct event_trigger_data *test, *n; -list_for_each_entry_rcu (test, &file->triggers, list) { +list_for_each_entry_safe (test, n, &file->triggers, list) {if (test->cmd_ops->trigger_type ==ETT_HIST_ENABLE ) {list_del_rcu (&test->list);update_cond_flag (file); --2.8.1
Steven Rostedt
maintainerRe: [PATCH 3/4] tracing: Fix use-after-free in hist_unreg_all/hist_enable_unreg_all
Quoted 14 lines · On Wed, 3 Aug 2016 16:19:53 +0200 Dmitry Vyukov <[email protected]> wrote:
Quoted 13 lines · Steven Rostedt
From: Steven Rostedt <[email protected]>
While running
tools/testing/selfteststest suite with KASAN, Dmitry Vyukov hit the following use-after-free report:==================================================================
BUG: KASAN: use-after-free in hist_unreg_all+0x1a1/0x1d0 at addr ffff880031632cc0 Read of size 8 by task ftracetest/7413 ================================================================== BUG kmalloc-128 (Not tainted): kasan: bad access detected ------------------------------------------------------------------
Quoted 9 lines
Quoted 6 lines
This fixes the problem, along with the same problem in
hist_enable_unreg_all().Cc Dmitry Vyukov <[email protected]>s/Cc/Reported-by/ please
Wish you posted that back when this was posted (see Link above). Because now it's in my git tree and tagged for Linus to pull. Too much work to rebase for a tag change :-/
-- Steve
Re: [PATCH 1/4] ftrace/recordmcount: Work around for addition of metag magic but not relocations
In reply to Steven RostedtQuoted 44 lines · Steven Rostedt
From: Laura Abbott <[email protected]>
glibc recently did a sync up (
94e73c95d9b5"elf.h: Sync with the gabi webpage") that added a #define forEM_METAGbut did not add relocationsThis triggers build errors:
scripts/recordmcount.c: In function 'do_file':scripts/recordmcount.c:466:28: error: 'R_METAG_ADDR32' undeclared (first use in this function)case EM_METAG: reltype = R_METAG_ADDR32; ^~~~~~~~~~~~~~ scripts/recordmcount.c:466:28: note: each undeclared identifier is reported only once for each function it appears in scripts/recordmcount.c:468:20: error: 'R_METAG_NONE' undeclared (first use in this function) rel_type_nop = R_METAG_NONE; ^~~~~~~~~~~~Work around this change with some more #ifdefery for the relocations.
Fedora Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1354034
Cc [email protected] # v3.9+Cc James Hogan <[email protected]>Fixes 00512bdd4573 ("metag: ftrace support")Reported-by Ross Burton <[email protected]>Signed-off-by Laura Abbott <[email protected]>Signed-off-by Steven Rostedt <[email protected]>--- scripts/recordmcount.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)scripts/recordmcount.c +4
-0@@ -33,10 +33,17 @@#include <string.h> #include <unistd.h> +/* +* glibc synced up and added the metag number but didn't add the relocations. +* Work around this in a crude manner for now. +*/
scripts/recordmcount.c line 48
Quoted 10 lines
scripts/recordmcount.c +4
-1#ifndef EM_METAG -/* Remove this when these make it to the standard system elf.h. */ #define EM_METAG 174 +#endif +#ifndef R_METAG_ADDR32 #define R_METAG_ADDR32 2 +#endif +#ifndef R_METAG_NONE #define R_METAG_NONE 3#endif
FWIW:
Thanks
James