kasan: Disable branch tracing for core runtime
Subsystems (2)
PATCH 1/1 kasan: Disable branch tracing for core runtime
During early boot, while KASAN is not yet initialized, it is possible to enter reporting code-path and end up in kasan_report(). While uninitialized, the branch there prevents generating any reports, however, under certain circumstances when branches are being traced (TRACE_BRANCH_PROFILING), we may recurse deep enough to cause kernel reboots without warning.
To prevent similar issues in future, we should disable branch tracing for the core runtime.
--- mm/kasan/Makefile | 16 ++++++++-------- mm/kasan/generic.c | 1 - 2 files changed, 8 insertions(+), 9 deletions(-)
mm/kasan/Makefile +8 -8
@@ -15,14 +15,14 @@ CFLAGS_REMOVE_tags_report.o = $(CC_FLAGS_FTRACE) # Function splitter causes unnecessary splits in __asan_load1/__asan_store1 # see: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63533 -CFLAGS_common.o := $(call cc-option, -fno-conserve-stack -fno-stack-protector) -CFLAGS_generic.o := $(call cc-option, -fno-conserve-stack -fno-stack-protector) -CFLAGS_generic_report.o := $(call cc-option, -fno-conserve-stack -fno-stack-protector) -CFLAGS_init.o := $(call cc-option, -fno-conserve-stack -fno-stack-protector) -CFLAGS_quarantine.o := $(call cc-option, -fno-conserve-stack -fno-stack-protector) -CFLAGS_report.o := $(call cc-option, -fno-conserve-stack -fno-stack-protector) -CFLAGS_tags.o := $(call cc-option, -fno-conserve-stack -fno-stack-protector) -CFLAGS_tags_report.o := $(call cc-option, -fno-conserve-stack -fno-stack-protector) +CFLAGS_common.o := $(call cc-option, -fno-conserve-stack -fno-stack-protector) -DDISABLE_BRANCH_PROFILING +CFLAGS_generic.o := $(call cc-option, -fno-conserve-stack -fno-stack-protector) -DDISABLE_BRANCH_PROFILING +CFLAGS_generic_report.o := $(call cc-option, -fno-conserve-stack -fno-stack-protector) -DDISABLE_BRANCH_PROFILING +CFLAGS_init.o := $(call cc-option, -fno-conserve-stack -fno-stack-protector) -DDISABLE_BRANCH_PROFILING +CFLAGS_quarantine.o := $(call cc-option, -fno-conserve-stack -fno-stack-protector) -DDISABLE_BRANCH_PROFILING +CFLAGS_report.o := $(call cc-option, -fno-conserve-stack -fno-stack-protector) -DDISABLE_BRANCH_PROFILING +CFLAGS_tags.o := $(call cc-option, -fno-conserve-stack -fno-stack-protector) -DDISABLE_BRANCH_PROFILING +CFLAGS_tags_report.o := $(call cc-option, -fno-conserve-stack -fno-stack-protector) -DDISABLE_BRANCH_PROFILING obj-$(CONFIG_KASAN) := common.o init.o report.o obj-$(CONFIG_KASAN_GENERIC) += generic.o generic_report.o quarantine.o
mm/kasan/generic.c +0 -1
@@ -15,7 +15,6 @@*/ #define pr_fmt (fmt) KBUILD_MODNAME ": " fmt -#define DISABLE_BRANCH_PROFILING #include <linux/export.h> #include <linux/interrupt.h>
Signature · 1 line
2.26.2.761.g0e0b3e54be-goog
Quoted 59 lines · Marco Elver
During early boot, while KASAN is not yet initialized, it is possible to enter reporting code-path and end up in
kasan_report(). While uninitialized, the branch there prevents generating any reports, however, under certain circumstances when branches are being traced (TRACE_BRANCH_PROFILING), we may recurse deep enough to cause kernel reboots without warning.To prevent similar issues in future, we should disable branch tracing for the core runtime.
Reported-by kernel test robot <[email protected]>Signed-off-by Marco Elver <[email protected]>--- mm/kasan/Makefile | 16 ++++++++-------- mm/kasan/generic.c | 1 - 2 files changed, 8 insertions(+), 9 deletions(-)mm/kasan/Makefile +8
-8@@ -15,14 +15,14 @@ CFLAGS_REMOVE_tags_report.o = $(CC_FLAGS_FTRACE) # Function splitter causes unnecessary splits in __asan_load1/__asan_store1 # see: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63533 -CFLAGS_common.o := $(call cc-option, -fno-conserve-stack -fno-stack-protector) -CFLAGS_generic.o := $(call cc-option, -fno-conserve-stack -fno-stack-protector) -CFLAGS_generic_report.o := $(call cc-option, -fno-conserve-stack -fno-stack-protector) -CFLAGS_init.o := $(call cc-option, -fno-conserve-stack -fno-stack-protector) -CFLAGS_quarantine.o := $(call cc-option, -fno-conserve-stack -fno-stack-protector) -CFLAGS_report.o := $(call cc-option, -fno-conserve-stack -fno-stack-protector) -CFLAGS_tags.o := $(call cc-option, -fno-conserve-stack -fno-stack-protector) -CFLAGS_tags_report.o := $(call cc-option, -fno-conserve-stack -fno-stack-protector) +CFLAGS_common.o := $(call cc-option, -fno-conserve-stack -fno-stack-protector) -DDISABLE_BRANCH_PROFILING +CFLAGS_generic.o := $(call cc-option, -fno-conserve-stack -fno-stack-protector) -DDISABLE_BRANCH_PROFILING +CFLAGS_generic_report.o := $(call cc-option, -fno-conserve-stack -fno-stack-protector) -DDISABLE_BRANCH_PROFILING +CFLAGS_init.o := $(call cc-option, -fno-conserve-stack -fno-stack-protector) -DDISABLE_BRANCH_PROFILING +CFLAGS_quarantine.o := $(call cc-option, -fno-conserve-stack -fno-stack-protector) -DDISABLE_BRANCH_PROFILING +CFLAGS_report.o := $(call cc-option, -fno-conserve-stack -fno-stack-protector) -DDISABLE_BRANCH_PROFILING +CFLAGS_tags.o := $(call cc-option, -fno-conserve-stack -fno-stack-protector) -DDISABLE_BRANCH_PROFILING +CFLAGS_tags_report.o := $(call cc-option, -fno-conserve-stack -fno-stack-protector) -DDISABLE_BRANCH_PROFILING obj-$(CONFIG_KASAN) := common.o init.o report.o obj-$(CONFIG_KASAN_GENERIC) += generic.o generic_report.o quarantine.omm/kasan/generic.c +0
-2@@ -15,7 +15,6 @@*/ #define pr_fmt (fmt) KBUILD_MODNAME ": " fmt -#define DISABLE_BRANCH_PROFILING #include <linux/export.h> #include <linux/interrupt.h> --
Quoted 2 lines
2.26.2.761.g0e0b3e54be-goog
Thanks!
Andrew Morton
maintainerQuoted 9 lines · On Tue, 19 May 2020 23:05:46 +0200 Andrey Konovalov <[email protected]>…
Quoted 8 lines · Marco Elver
During early boot, while KASAN is not yet initialized, it is possible to enter reporting code-path and end up in
kasan_report(). While uninitialized, the branch there prevents generating any reports, however, under certain circumstances when branches are being traced (TRACE_BRANCH_PROFILING), we may recurse deep enough to cause kernel reboots without warning.
Quoted 7 lines
Quoted 3 lines
To prevent similar issues in future, we should disable branch tracing for the core runtime.
...
Reviewed-by Andrey Konovalov <[email protected]>
Thanks, I queued this for 5.7.
Quoted 23 lines · Marco Elver' via kasan-dev
During early boot, while KASAN is not yet initialized, it is possible to enter reporting code-path and end up in
kasan_report(). While uninitialized, the branch there prevents generating any reports, however, under certain circumstances when branches are being traced (TRACE_BRANCH_PROFILING), we may recurse deep enough to cause kernel reboots without warning.To prevent similar issues in future, we should disable branch tracing for the core runtime.
Reported-by kernel test robot <[email protected]>Signed-off-by Marco Elver <[email protected]>--- mm/kasan/Makefile | 16 ++++++++-------- mm/kasan/generic.c | 1 - 2 files changed, 8 insertions(+), 9 deletions(-)mm/kasan/Makefile +0
-0
mm/kasan/Makefile CFLAGS_REMOVE_tags_report.o = $(CC_FLAGS_FTRACE) · line 24
Quoted 10 lines
mm/kasan/Makefile +0
-7@@ -15,14 +15,14 @@ CFLAGS_REMOVE_tags_report.o = $(CC_FLAGS_FTRACE) # Function splitter causes unnecessary splits in __asan_load1/__asan_store1 # see: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63533 -CFLAGS_common.o := $(call cc-option, -fno-conserve-stack -fno-stack-protector) -CFLAGS_generic.o := $(call cc-option, -fno-conserve-stack -fno-stack-protector) -CFLAGS_generic_report.o := $(call cc-option, -fno-conserve-stack -fno-stack-protector) -CFLAGS_init.o := $(call cc-option, -fno-conserve-stack -fno-stack-protector) -CFLAGS_quarantine.o := $(call cc-option, -fno-conserve-stack -fno-stack-protector) -CFLAGS_report.o := $(call cc-option, -fno-conserve-stack -fno-stack-protector) -CFLAGS_tags.o := $(call cc-option, -fno-conserve-stack -fno-stack-protector)
mm/kasan/tags.c:15:9: warning: 'DISABLE_BRANCH_PROFILING' macro redefined [-Wmacro-redefined]
#define DISABLE_BRANCH_PROFILING
^
<command line>:6:9: note: previous definition is here
#define DISABLE_BRANCH_PROFILING 1
^This?
mm/kasan/tags.c +0 -1
@@ -12,7 +12,6 @@*/ #define pr_fmt (fmt) KBUILD_MODNAME ": " fmt -#define DISABLE_BRANCH_PROFILING #include <linux/export.h> #include <linux/interrupt.h>
Quoted 51 lines · Qian Cai
Quoted 23 lines · Marco Elver' via kasan-dev
During early boot, while KASAN is not yet initialized, it is possible to enter reporting code-path and end up in
kasan_report(). While uninitialized, the branch there prevents generating any reports, however, under certain circumstances when branches are being traced (TRACE_BRANCH_PROFILING), we may recurse deep enough to cause kernel reboots without warning.To prevent similar issues in future, we should disable branch tracing for the core runtime.
Reported-by kernel test robot <[email protected]>Signed-off-by Marco Elver <[email protected]>--- mm/kasan/Makefile | 16 ++++++++-------- mm/kasan/generic.c | 1 - 2 files changed, 8 insertions(+), 9 deletions(-)mm/kasan/Makefile +0
-0mm/kasan/Makefile CFLAGS_REMOVE_tags_report.o = $(CC_FLAGS_FTRACE) · line 24
Quoted 10 lines
mm/kasan/Makefile +0
-7@@ -15,14 +15,14 @@ CFLAGS_REMOVE_tags_report.o = $(CC_FLAGS_FTRACE) # Function splitter causes unnecessary splits in __asan_load1/__asan_store1 # see: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63533 -CFLAGS_common.o := $(call cc-option, -fno-conserve-stack -fno-stack-protector) -CFLAGS_generic.o := $(call cc-option, -fno-conserve-stack -fno-stack-protector) -CFLAGS_generic_report.o := $(call cc-option, -fno-conserve-stack -fno-stack-protector) -CFLAGS_init.o := $(call cc-option, -fno-conserve-stack -fno-stack-protector) -CFLAGS_quarantine.o := $(call cc-option, -fno-conserve-stack -fno-stack-protector) -CFLAGS_report.o := $(call cc-option, -fno-conserve-stack -fno-stack-protector) -CFLAGS_tags.o := $(call cc-option, -fno-conserve-stack -fno-stack-protector)
mm/kasan/tags.c:15:9: warning: 'DISABLE_BRANCH_PROFILING' macro redefined [-Wmacro-redefined]#define DISABLE_BRANCH_PROFILING ^ <command line>:6:9: note: previous definition is here #define DISABLE_BRANCH_PROFILING 1 ^This?
mm/kasan/tags.c +0
-0
mm/kasan/tags.c line 17
Quoted 7 lines
mm/kasan/tags.c +0
-1@@ -12,7 +12,6 @@*/ #define pr_fmt (fmt) KBUILD_MODNAME ": " fmt -#define DISABLE_BRANCH_PROFILING #include <linux/export.h> #include <linux/interrupt.h>
I missed this one, thanks! Added this to v2.