Skip to contentSkip to conversation

riscv: Enable Undefined Behavior Sanitizer UBSAN

PATCH In review Jisheng Zhang 2 participants 2 messages Aug 4, 2021 – Aug 25, 2021 RISC-V

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 riscv: Enable Undefined Behavior Sanitizer UBSAN

From: Jisheng Zhang <[email protected]>

Select ARCH_HAS_UBSAN_SANITIZE_ALL in order to allow the user to enable CONFIG_UBSAN_SANITIZE_ALL and instrument the entire kernel for ubsan checks.

VDSO is excluded because its build doesn't include the __ubsan_handle_*() functions from lib/ubsan.c, and the VDSO has no sane way to report errors even if it has definitions of these functions.

Passed lib/test_ubsan.c test.

---
 arch/riscv/Kconfig              | 1 +
 arch/riscv/kernel/vdso/Makefile | 1 +
 2 files changed, 2 insertions(+)
arch/riscv/Kconfig +1 -0
index f133ac72572f..cccb95bf8331 100644
@@ -28,6 +28,7 @@ config RISCV
 	select ARCH_HAS_STRICT_KERNEL_RWX if MMU && !XIP_KERNEL
 	select ARCH_HAS_STRICT_MODULE_RWX if MMU && !XIP_KERNEL
 	select ARCH_HAS_TICK_BROADCAST if GENERIC_CLOCKEVENTS_BROADCAST
+	select ARCH_HAS_UBSAN_SANITIZE_ALL
 	select ARCH_OPTIONAL_KERNEL_RWX if ARCH_HAS_STRICT_KERNEL_RWX
 	select ARCH_OPTIONAL_KERNEL_RWX_DEFAULT
 	select ARCH_STACKWALK
arch/riscv/kernel/vdso/Makefile +1 -0
index 24d936c147cd..30a5335bd317 100644
@@ -36,6 +36,7 @@ CFLAGS_REMOVE_vgettimeofday.o = $(CC_FLAGS_FTRACE) -Os
 GCOV_PROFILE := n
 KCOV_INSTRUMENT := n
 KASAN_SANITIZE := n
+UBSAN_SANITIZE := n
 
 # Force dependency
 $(obj)/vdso.o: $(obj)/vdso.so
Signature · 1 line
2.32.0
maintainer
#1 lore raw
Quoted 35 lines · On Wed, 04 Aug 2021 09:30:59 PDT (-0700), [email protected] wrote:

From: Jisheng Zhang <[email protected]>

Select ARCH_HAS_UBSAN_SANITIZE_ALL in order to allow the user to enable CONFIG_UBSAN_SANITIZE_ALL and instrument the entire kernel for ubsan checks.

VDSO is excluded because its build doesn't include the __ubsan_handle_*() functions from lib/ubsan.c, and the VDSO has no sane way to report errors even if it has definitions of these functions.

Passed lib/test_ubsan.c test.

---
 arch/riscv/Kconfig              | 1 +
 arch/riscv/kernel/vdso/Makefile | 1 +
 2 files changed, 2 insertions(+)
arch/riscv/Kconfig +1 -0
index f133ac72572f..cccb95bf8331 100644
@@ -28,6 +28,7 @@ config RISCV
 	select ARCH_HAS_STRICT_KERNEL_RWX if MMU && !XIP_KERNEL
 	select ARCH_HAS_STRICT_MODULE_RWX if MMU && !XIP_KERNEL
 	select ARCH_HAS_TICK_BROADCAST if GENERIC_CLOCKEVENTS_BROADCAST
+	select ARCH_HAS_UBSAN_SANITIZE_ALL
 	select ARCH_OPTIONAL_KERNEL_RWX if ARCH_HAS_STRICT_KERNEL_RWX
 	select ARCH_OPTIONAL_KERNEL_RWX_DEFAULT
 	select ARCH_STACKWALK
arch/riscv/kernel/vdso/Makefile +0 -0
index 24d936c147cd..30a5335bd317 100644

arch/riscv/kernel/vdso/Makefile CFLAGS_REMOVE_vgettimeofday.o = $(CC_FLAGS_FTRACE) -Os · line 42

Quoted 7 lines
arch/riscv/kernel/vdso/Makefile +1 -0
@@ -36,6 +36,7 @@ CFLAGS_REMOVE_vgettimeofday.o = $(CC_FLAGS_FTRACE) -Os
 GCOV_PROFILE := n
 KCOV_INSTRUMENT := n
 KASAN_SANITIZE := n
+UBSAN_SANITIZE := n
 
 # Force dependency
 $(obj)/vdso.o: $(obj)/vdso.so

Thanks, this is on for-next.