Skip to contentSkip to conversation

ARM: ubsan: select ARCH_HAS_UBSAN_SANITIZE_ALL

PATCH In review Florian Fainelli 4 participants 8 messages Sep 28, 2022 – Oct 12, 2022 Arm (32-bit)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ARM: ubsan: select ARCH_HAS_UBSAN_SANITIZE_ALL

From: Seung-Woo Kim <[email protected]>

To enable UBSAN on ARM, this patch enables ARCH_HAS_UBSAN_SANITIZE_ALL from arm confiuration. Basic kernel bootup test is passed on arm with CONFIG_UBSAN_SANITIZE_ALL enabled.

[florian: rebased against v6.0-rc7]
---
 arch/arm/Kconfig                  | 1 +
 arch/arm/boot/compressed/Makefile | 1 +
 arch/arm/vdso/Makefile            | 1 +
 3 files changed, 3 insertions(+)
arch/arm/Kconfig +1 -0
index 87badeae3181..c90aa58eab7f 100644
@@ -27,6 +27,7 @@ config ARM
 	select ARCH_HAVE_NMI_SAFE_CMPXCHG if CPU_V7 || CPU_V7M || CPU_V6K
 	select ARCH_HAS_GCOV_PROFILE_ALL
 	select ARCH_KEEP_MEMBLOCK
+	select ARCH_HAS_UBSAN_SANITIZE_ALL
 	select ARCH_MIGHT_HAVE_PC_PARPORT
 	select ARCH_NO_SG_CHAIN if !ARM_HAS_SG_CHAIN
 	select ARCH_OPTIONAL_KERNEL_RWX if ARCH_HAS_STRICT_KERNEL_RWX
arch/arm/boot/compressed/Makefile +1 -0
index 41bcbb460fac..2cc2af13779e 100644
@@ -27,6 +27,7 @@ KASAN_SANITIZE		:= n
 
 # Prevents link failures: __sanitizer_cov_trace_pc() is not linked in.
 KCOV_INSTRUMENT		:= n
+UBSAN_SANITIZE		:= n
 
 #
 # Architecture dependencies
arch/arm/vdso/Makefile +1 -0
index 8ca1c9f262a2..a7ec06ce3785 100644
@@ -37,6 +37,7 @@ endif
 
 # Disable gcov profiling for VDSO code
 GCOV_PROFILE := n
+UBSAN_SANITIZE := n
 
 # Prevents link failures: __sanitizer_cov_trace_pc() is not linked in.
 KCOV_INSTRUMENT := n
Signature · 1 line
2.25.1
#1 lore raw
Quoted 9 lines · Florian Fainelli

From: Seung-Woo Kim <[email protected]>

To enable UBSAN on ARM, this patch enables ARCH_HAS_UBSAN_SANITIZE_ALL from arm confiuration. Basic kernel bootup test is passed on arm with CONFIG_UBSAN_SANITIZE_ALL enabled.

[florian: rebased against v6.0-rc7]

Ah-ha, thanks for testing this. What devices did you check this on? I know boot-up on arm32 can be very device-specific.

Which UBSAN configs did you try?

Thanks!

-Kees

Signature · 1 line
Kees Cook
#2 lore raw
Quoted 7 lines · Kees Cook
Quoted 6 lines · Florian Fainelli

From: Seung-Woo Kim <[email protected]>

To enable UBSAN on ARM, this patch enables ARCH_HAS_UBSAN_SANITIZE_ALL from arm confiuration. Basic kernel bootup test is passed on arm with CONFIG_UBSAN_SANITIZE_ALL enabled.

Quoted 6 lines
Quoted 3 lines
[florian: rebased against v6.0-rc7]

Ah-ha, thanks for testing this. What devices did you check this on? I know boot-up on arm32 can be very device-specific.

This was tested on an ARCH_BRCMSTB system which is using an ARMv8 CPU booted in AArch32 mode, so virtually equivalent to armv7l. A raspberry Pi 4B is also happily booting with it.

Quoted 2 lines

Which UBSAN configs did you try?

All CONFIG_UBSAN_* work with the exception of CONFIG_UBSAN_ALIGNMENT on my ARCH_BRCMSTB system, however it works fine on the Raspberry Pi 4B. Florian

Tested-by
#3 lore raw
Quoted 15 lines · Florian Fainelli
Quoted 7 lines · Kees Cook
Quoted 6 lines · Florian Fainelli

From: Seung-Woo Kim <[email protected]>

To enable UBSAN on ARM, this patch enables ARCH_HAS_UBSAN_SANITIZE_ALL from arm confiuration. Basic kernel bootup test is passed on arm with CONFIG_UBSAN_SANITIZE_ALL enabled.

Quoted 6 lines
Quoted 3 lines
[florian: rebased against v6.0-rc7]

Ah-ha, thanks for testing this. What devices did you check this on? I know boot-up on arm32 can be very device-specific.

Quoted 7 lines

This was tested on an ARCH_BRCMSTB system which is using an ARMv8 CPU booted in AArch32 mode, so virtually equivalent to armv7l. A raspberry Pi 4B is also happily booting with it.

Quoted 2 lines

Which UBSAN configs did you try?

All CONFIG_UBSAN_* work with the exception of CONFIG_UBSAN_ALIGNMENT on my ARCH_BRCMSTB system, however it works fine on the Raspberry Pi 4B. Florian

I also tested on a BCM63138 board (ARM A9) under ARCH_BCMBCA using the multi_v7_defconfig with all the UBSAN configs enabled except UBSAN_ALIGNMENT and board boots up fine. Turning on UBSAN_ALIGNMENT results in flood of false positive misaligned-access warnings. This is fine as ARM supports unaligned access.

It did catch an out-of-band bug in mach-sunxi smp code. I will submit a separate patch to fix that bug.

#4 lore raw
Quoted 29 lines · William Zhang
Quoted 20 lines · Florian Fainelli
Quoted 7 lines · Kees Cook
Quoted 6 lines · Florian Fainelli

From: Seung-Woo Kim <[email protected]>

To enable UBSAN on ARM, this patch enables ARCH_HAS_UBSAN_SANITIZE_ALL from arm confiuration. Basic kernel bootup test is passed on arm with CONFIG_UBSAN_SANITIZE_ALL enabled.

Quoted 6 lines
Quoted 3 lines
[florian: rebased against v6.0-rc7]

Ah-ha, thanks for testing this. What devices did you check this on? I know boot-up on arm32 can be very device-specific.

This was tested on an ARCH_BRCMSTB system which is using an ARMv8 CPU booted in AArch32 mode, so virtually equivalent to armv7l. A raspberry Pi 4B is also happily booting with it.

Quoted 1 line
Quoted 5 lines
Quoted 1 line

Which UBSAN configs did you try?

All CONFIG_UBSAN_* work with the exception of CONFIG_UBSAN_ALIGNMENT on my ARCH_BRCMSTB system, however it works fine on the Raspberry Pi 4B. Florian

Quoted 8 lines

I also tested on a BCM63138 board (ARM A9) under ARCH_BCMBCA using the multi_v7_defconfig with all the UBSAN configs enabled except UBSAN_ALIGNMENT and board boots up fine. Turning on UBSAN_ALIGNMENT results in flood of false positive misaligned-access warnings. This is fine as ARM supports unaligned access.

It did catch an out-of-band bug in mach-sunxi smp code. I will submit a separate patch to fix that bug.

Yay! :) Move coverage is great. :)

Quoted 2 lines

Thanks!

Signature · 1 line
Kees Cook
#5 lore raw
Quoted 36 lines · Kees Cook
Quoted 35 lines · William Zhang
Quoted 20 lines · Florian Fainelli
Quoted 7 lines · Kees Cook
Quoted 6 lines · Florian Fainelli

From: Seung-Woo Kim <[email protected]>

To enable UBSAN on ARM, this patch enables ARCH_HAS_UBSAN_SANITIZE_ALL from arm confiuration. Basic kernel bootup test is passed on arm with CONFIG_UBSAN_SANITIZE_ALL enabled.

Quoted 6 lines
Quoted 3 lines
[florian: rebased against v6.0-rc7]

Ah-ha, thanks for testing this. What devices did you check this on? I know boot-up on arm32 can be very device-specific.

This was tested on an ARCH_BRCMSTB system which is using an ARMv8 CPU booted in AArch32 mode, so virtually equivalent to armv7l. A raspberry Pi 4B is also happily booting with it.

Quoted 1 line
Quoted 5 lines
Quoted 1 line

Which UBSAN configs did you try?

All CONFIG_UBSAN_* work with the exception of CONFIG_UBSAN_ALIGNMENT on my ARCH_BRCMSTB system, however it works fine on the Raspberry Pi 4B. Florian

I also tested on a BCM63138 board (ARM A9) under ARCH_BCMBCA using the multi_v7_defconfig with all the UBSAN configs enabled except UBSAN_ALIGNMENT and board boots up fine. Turning on UBSAN_ALIGNMENT results in flood of false positive misaligned-access warnings. This is fine as ARM supports unaligned access.

Quoted 7 lines
Quoted 2 lines

It did catch an out-of-band bug in mach-sunxi smp code. I will submit a separate patch to fix that bug.

Yay! :) Move coverage is great. :)

Quoted 2 lines

Submitted to the patch tracker:

https://www.armlinux.org.uk/developer/patches/viewpatch.php?id=9253/1

Signature · 1 line
Florian
#6 lore raw
In reply to Florian Fainelli
Quoted 9 lines · Florian Fainelli

From: Seung-Woo Kim <[email protected]>

To enable UBSAN on ARM, this patch enables ARCH_HAS_UBSAN_SANITIZE_ALL from arm confiuration. Basic kernel bootup test is passed on arm with CONFIG_UBSAN_SANITIZE_ALL enabled.

[florian: rebased against v6.0-rc7]

Pretty cool that it "just works", I was thinking to myself that I should try this one
day. Sorry I was late to look at the patch.

Have you also looked at KCSAN?

Yours,
Linus Walleij

#7 lore raw
Quoted 12 lines · Linus Walleij
Quoted 9 lines · Florian Fainelli

From: Seung-Woo Kim <[email protected]>

To enable UBSAN on ARM, this patch enables ARCH_HAS_UBSAN_SANITIZE_ALL from arm confiuration. Basic kernel bootup test is passed on arm with CONFIG_UBSAN_SANITIZE_ALL enabled.

[florian: rebased against v6.0-rc7]
Quoted 5 lines

Pretty cool that it "just works", I was thinking to myself that I should try this one
day. Sorry I was late to look at the patch.

Have you also looked at KCSAN?

Not yet, that would be next. Most often, at least for ARCH_BRCMSTB the same hardware and set of drivers run on ARM64 which is typically much more feature full, so we get coverage on *SAN features that way. --
Florian