[PATCH 4/4] sandbox: reinstate cooked terminal mode on sanitizer-induced death

Ahmad Fatoum a.fatoum at pengutronix.de
Mon Jul 6 02:28:06 EDT 2020


If we exit due to AddressSanitizer error, we remain in raw mode, which
is not best user experience. Currently every exit is an AddressSanitizer
death due to leaks. We want to encourage users to always have ASan
enabled, to catch more errors, thus call cookmode() on exit.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 arch/sandbox/os/Makefile | 4 ++++
 arch/sandbox/os/common.c | 6 ++++++
 2 files changed, 10 insertions(+)

diff --git a/arch/sandbox/os/Makefile b/arch/sandbox/os/Makefile
index 1d32a197ead4..f307e6a828c1 100644
--- a/arch/sandbox/os/Makefile
+++ b/arch/sandbox/os/Makefile
@@ -6,6 +6,10 @@ KBUILD_CPPFLAGS = $(patsubst %,-I$(srctree)/%include,$(machdirs))
 
 KBUILD_CPPFLAGS += -DCONFIG_MALLOC_SIZE=$(CONFIG_MALLOC_SIZE)
 
+ifeq ($(CONFIG_KASAN),y)
+KBUILD_CPPFLAGS += -DCONFIG_KASAN=1
+endif
+
 KBUILD_CFLAGS := -Wall
 NOSTDINC_FLAGS :=
 
diff --git a/arch/sandbox/os/common.c b/arch/sandbox/os/common.c
index 534571c0e668..69fadb3b47a4 100644
--- a/arch/sandbox/os/common.c
+++ b/arch/sandbox/os/common.c
@@ -44,6 +44,8 @@
 #include <mach/linux.h>
 #include <mach/hostfile.h>
 
+void __sanitizer_set_death_callback(void (*callback)(void));
+
 int sdl_xres;
 int sdl_yres;
 
@@ -345,6 +347,10 @@ int main(int argc, char *argv[])
 	int fdno = 0, envno = 0, option_index = 0;
 	char *aux;
 
+#ifdef CONFIG_KASAN
+	__sanitizer_set_death_callback(cookmode);
+#endif
+
 	while (1) {
 		option_index = 0;
 		opt = getopt_long(argc, argv, optstring,
-- 
2.27.0




More information about the barebox mailing list