For simplicity in splitting out UBSan options into separate rules, remove CONFIG_UBSAN_SANITIZE_ALL, effectively defaulting to "y", which is how it is generally used anyway. (There are no ":= y" cases beyond where a specific file is enabled when a top-level ":= n" is in effect.)
Unified · Split
| @@ -49,34 +49,22 @@ Report example · 48 unmodified lines | |||
| 49 | Usage | 49 | Usage |
| 50 | ----- | 50 | ----- |
| 51 | 51 | ||
| 52 | To enable UBSAN configure kernel with:: | 52 | To enable UBSAN, configure the kernel with:: |
| 53 | 53 | ||
| 54 | CONFIG_UBSAN=y | 54 | CONFIG_UBSAN=y |
| 55 | 55 | ||
| 56 | and to check the entire kernel:: | 56 | To exclude files from being instrumented use:: |
| 57 | |||
| 58 | CONFIG_UBSAN_SANITIZE_ALL=y | ||
| 59 | |||
| 60 | To enable instrumentation for specific files or directories, add a line | ||
| 61 | similar to the following to the respective kernel Makefile: | ||
| 62 | |||
| 63 | - For a single file (e.g. main.o):: | ||
| 64 | |||
| 65 | UBSAN_SANITIZE_main.o := y | ||
| 66 | |||
| 67 | - For all files in one directory:: | ||
| 68 | |||
| 69 | UBSAN_SANITIZE := y | ||
| 70 | |||
| 71 | To exclude files from being instrumented even if | ||
| 72 | ``CONFIG_UBSAN_SANITIZE_ALL=y``, use:: | ||
| 73 | 57 | ||
| 74 | UBSAN_SANITIZE_main.o := n | 58 | UBSAN_SANITIZE_main.o := n |
| 75 | 59 | ||
| 76 | and:: | 60 | and to exclude all targets in one directory use:: |
| 77 | 61 | ||
| 78 | UBSAN_SANITIZE := n | 62 | UBSAN_SANITIZE := n |
| 79 | 63 | ||
| 64 | When disabled for all targets, specific files can be enabled using:: | ||
| 65 | |||
| 66 | UBSAN_SANITIZE_main.o := y | ||
| 67 | |||
| 80 | Detection of unaligned accesses controlled through the separate option - | 68 | Detection of unaligned accesses controlled through the separate option - |
| 81 | CONFIG_UBSAN_ALIGNMENT. It's off by default on architectures that support | 69 | CONFIG_UBSAN_ALIGNMENT. It's off by default on architectures that support |
| 82 | unaligned accesses (CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS=y). One could | 70 | unaligned accesses (CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS=y). One could |
| @@ -29,7 +29,7 @@ config ARM · 28 unmodified lines | |||
| 29 | select ARCH_HAVE_NMI_SAFE_CMPXCHG if CPU_V7 || CPU_V7M || CPU_V6K | 29 | select ARCH_HAVE_NMI_SAFE_CMPXCHG if CPU_V7 || CPU_V7M || CPU_V6K |
| 30 | select ARCH_HAS_GCOV_PROFILE_ALL | 30 | select ARCH_HAS_GCOV_PROFILE_ALL |
| 31 | select ARCH_KEEP_MEMBLOCK | 31 | select ARCH_KEEP_MEMBLOCK |
| 32 | select ARCH_HAS_UBSAN_SANITIZE_ALL | 32 | select ARCH_HAS_UBSAN |
| 33 | select ARCH_MIGHT_HAVE_PC_PARPORT | 33 | select ARCH_MIGHT_HAVE_PC_PARPORT |
| 34 | select ARCH_OPTIONAL_KERNEL_RWX if ARCH_HAS_STRICT_KERNEL_RWX | 34 | select ARCH_OPTIONAL_KERNEL_RWX if ARCH_HAS_STRICT_KERNEL_RWX |
| 35 | select ARCH_OPTIONAL_KERNEL_RWX_DEFAULT if CPU_V7 | 35 | select ARCH_OPTIONAL_KERNEL_RWX_DEFAULT if CPU_V7 |
| @@ -107,7 +107,7 @@ config ARM64 · 106 unmodified lines | |||
| 107 | select ARCH_WANT_LD_ORPHAN_WARN | 107 | select ARCH_WANT_LD_ORPHAN_WARN |
| 108 | select ARCH_WANTS_NO_INSTR | 108 | select ARCH_WANTS_NO_INSTR |
| 109 | select ARCH_WANTS_THP_SWAP if ARM64_4K_PAGES | 109 | select ARCH_WANTS_THP_SWAP if ARM64_4K_PAGES |
| 110 | select ARCH_HAS_UBSAN_SANITIZE_ALL | 110 | select ARCH_HAS_UBSAN |
| 111 | select ARM_AMBA | 111 | select ARM_AMBA |
| 112 | select ARM_ARCH_TIMER | 112 | select ARM_ARCH_TIMER |
| 113 | select ARM_GIC | 113 | select ARM_GIC |
| @@ -14,7 +14,7 @@ config MIPS · 13 unmodified lines | |||
| 14 | select ARCH_HAS_STRNCPY_FROM_USER | 14 | select ARCH_HAS_STRNCPY_FROM_USER |
| 15 | select ARCH_HAS_STRNLEN_USER | 15 | select ARCH_HAS_STRNLEN_USER |
| 16 | select ARCH_HAS_TICK_BROADCAST if GENERIC_CLOCKEVENTS_BROADCAST | 16 | select ARCH_HAS_TICK_BROADCAST if GENERIC_CLOCKEVENTS_BROADCAST |
| 17 | select ARCH_HAS_UBSAN_SANITIZE_ALL | 17 | select ARCH_HAS_UBSAN |
| 18 | select ARCH_HAS_GCOV_PROFILE_ALL | 18 | select ARCH_HAS_GCOV_PROFILE_ALL |
| 19 | select ARCH_KEEP_MEMBLOCK | 19 | select ARCH_KEEP_MEMBLOCK |
| 20 | select ARCH_USE_BUILTIN_BSWAP | 20 | select ARCH_USE_BUILTIN_BSWAP |
| @@ -12,7 +12,7 @@ config PARISC · 11 unmodified lines | |||
| 12 | select ARCH_HAS_ELF_RANDOMIZE | 12 | select ARCH_HAS_ELF_RANDOMIZE |
| 13 | select ARCH_HAS_STRICT_KERNEL_RWX | 13 | select ARCH_HAS_STRICT_KERNEL_RWX |
| 14 | select ARCH_HAS_STRICT_MODULE_RWX | 14 | select ARCH_HAS_STRICT_MODULE_RWX |
| 15 | select ARCH_HAS_UBSAN_SANITIZE_ALL | 15 | select ARCH_HAS_UBSAN |
| 16 | select ARCH_HAS_PTE_SPECIAL | 16 | select ARCH_HAS_PTE_SPECIAL |
| 17 | select ARCH_NO_SG_CHAIN | 17 | select ARCH_NO_SG_CHAIN |
| 18 | select ARCH_SUPPORTS_HUGETLBFS if PA20 | 18 | select ARCH_SUPPORTS_HUGETLBFS if PA20 |
| @@ -154,7 +154,7 @@ config PPC · 153 unmodified lines | |||
| 154 | select ARCH_HAS_SYSCALL_WRAPPER if !SPU_BASE && !COMPAT | 154 | select ARCH_HAS_SYSCALL_WRAPPER if !SPU_BASE && !COMPAT |
| 155 | select ARCH_HAS_TICK_BROADCAST if GENERIC_CLOCKEVENTS_BROADCAST | 155 | select ARCH_HAS_TICK_BROADCAST if GENERIC_CLOCKEVENTS_BROADCAST |
| 156 | select ARCH_HAS_UACCESS_FLUSHCACHE | 156 | select ARCH_HAS_UACCESS_FLUSHCACHE |
| 157 | select ARCH_HAS_UBSAN_SANITIZE_ALL | 157 | select ARCH_HAS_UBSAN |
| 158 | select ARCH_HAVE_NMI_SAFE_CMPXCHG | 158 | select ARCH_HAVE_NMI_SAFE_CMPXCHG |
| 159 | select ARCH_KEEP_MEMBLOCK | 159 | select ARCH_KEEP_MEMBLOCK |
| 160 | select ARCH_MHP_MEMMAP_ON_MEMORY_ENABLE if PPC_RADIX_MMU | 160 | select ARCH_MHP_MEMMAP_ON_MEMORY_ENABLE if PPC_RADIX_MMU |
| @@ -37,7 +37,7 @@ config RISCV · 36 unmodified lines | |||
| 37 | select ARCH_HAS_STRICT_MODULE_RWX if MMU && !XIP_KERNEL | 37 | select ARCH_HAS_STRICT_MODULE_RWX if MMU && !XIP_KERNEL |
| 38 | select ARCH_HAS_SYSCALL_WRAPPER | 38 | select ARCH_HAS_SYSCALL_WRAPPER |
| 39 | select ARCH_HAS_TICK_BROADCAST if GENERIC_CLOCKEVENTS_BROADCAST | 39 | select ARCH_HAS_TICK_BROADCAST if GENERIC_CLOCKEVENTS_BROADCAST |
| 40 | select ARCH_HAS_UBSAN_SANITIZE_ALL | 40 | select ARCH_HAS_UBSAN |
| 41 | select ARCH_HAS_VDSO_DATA | 41 | select ARCH_HAS_VDSO_DATA |
| 42 | select ARCH_KEEP_MEMBLOCK if ACPI | 42 | select ARCH_KEEP_MEMBLOCK if ACPI |
| 43 | select ARCH_OPTIONAL_KERNEL_RWX if ARCH_HAS_STRICT_KERNEL_RWX | 43 | select ARCH_OPTIONAL_KERNEL_RWX if ARCH_HAS_STRICT_KERNEL_RWX |
| @@ -82,7 +82,7 @@ config S390 · 81 unmodified lines | |||
| 82 | select ARCH_HAS_STRICT_KERNEL_RWX | 82 | select ARCH_HAS_STRICT_KERNEL_RWX |
| 83 | select ARCH_HAS_STRICT_MODULE_RWX | 83 | select ARCH_HAS_STRICT_MODULE_RWX |
| 84 | select ARCH_HAS_SYSCALL_WRAPPER | 84 | select ARCH_HAS_SYSCALL_WRAPPER |
| 85 | select ARCH_HAS_UBSAN_SANITIZE_ALL | 85 | select ARCH_HAS_UBSAN |
| 86 | select ARCH_HAS_VDSO_DATA | 86 | select ARCH_HAS_VDSO_DATA |
| 87 | select ARCH_HAVE_NMI_SAFE_CMPXCHG | 87 | select ARCH_HAVE_NMI_SAFE_CMPXCHG |
| 88 | select ARCH_INLINE_READ_LOCK | 88 | select ARCH_INLINE_READ_LOCK |
| @@ -100,7 +100,7 @@ config X86 · 99 unmodified lines | |||
| 100 | select ARCH_HAS_STRICT_MODULE_RWX | 100 | select ARCH_HAS_STRICT_MODULE_RWX |
| 101 | select ARCH_HAS_SYNC_CORE_BEFORE_USERMODE | 101 | select ARCH_HAS_SYNC_CORE_BEFORE_USERMODE |
| 102 | select ARCH_HAS_SYSCALL_WRAPPER | 102 | select ARCH_HAS_SYSCALL_WRAPPER |
| 103 | select ARCH_HAS_UBSAN_SANITIZE_ALL | 103 | select ARCH_HAS_UBSAN |
| 104 | select ARCH_HAS_DEBUG_WX | 104 | select ARCH_HAS_DEBUG_WX |
| 105 | select ARCH_HAS_ZONE_DMA_SET if EXPERT | 105 | select ARCH_HAS_ZONE_DMA_SET if EXPERT |
| 106 | select ARCH_HAVE_NMI_SAFE_CMPXCHG | 106 | select ARCH_HAVE_NMI_SAFE_CMPXCHG |
| @@ -1,5 +1,5 @@ | |||
| 1 | # SPDX-License-Identifier: GPL-2.0-only | 1 | # SPDX-License-Identifier: GPL-2.0-only |
| 2 | config ARCH_HAS_UBSAN_SANITIZE_ALL | 2 | config ARCH_HAS_UBSAN |
| 3 | bool | 3 | bool |
| 4 | 4 | ||
| 5 | menuconfig UBSAN | 5 | menuconfig UBSAN |
| @@ -142,17 +142,6 @@ config UBSAN_ALIGNMENT · 136 unmodified lines | |||
| 142 | Enabling this option on architectures that support unaligned | 142 | Enabling this option on architectures that support unaligned |
| 143 | accesses may produce a lot of false positives. | 143 | accesses may produce a lot of false positives. |
| 144 | 144 | ||
| 145 | config UBSAN_SANITIZE_ALL | ||
| 146 | bool "Enable instrumentation for the entire kernel" | ||
| 147 | depends on ARCH_HAS_UBSAN_SANITIZE_ALL | ||
| 148 | default y | ||
| 149 | help | ||
| 150 | This option activates instrumentation for the entire kernel. | ||
| 151 | If you don't enable this option, you have to explicitly specify | ||
| 152 | UBSAN_SANITIZE := y for the files/directories you want to check for UB. | ||
| 153 | Enabling this option will get kernel image size increased | ||
| 154 | significantly. | ||
| 155 | |||
| 156 | config TEST_UBSAN | 145 | config TEST_UBSAN |
| 157 | tristate "Module for testing for undefined behavior detection" | 146 | tristate "Module for testing for undefined behavior detection" |
| 158 | depends on m | 147 | depends on m |
| @@ -175,7 +175,7 @@ endif · 174 unmodified lines | |||
| 175 | 175 | ||
| 176 | ifeq ($(CONFIG_UBSAN),y) | 176 | ifeq ($(CONFIG_UBSAN),y) |
| 177 | _c_flags += $(if $(patsubst n%,, \ | 177 | _c_flags += $(if $(patsubst n%,, \ |
| 178 | $(UBSAN_SANITIZE_$(basetarget).o)$(UBSAN_SANITIZE)$(CONFIG_UBSAN_SANITIZE_ALL)), \ | 178 | $(UBSAN_SANITIZE_$(basetarget).o)$(UBSAN_SANITIZE)y), \ |
| 179 | $(CFLAGS_UBSAN)) | 179 | $(CFLAGS_UBSAN)) |
| 180 | endif | 180 | endif |
| 181 | 181 | ||