The object-size sanitizer is redundant to -Warray-bounds, and inappropriately performs its checks at run-time when all information needed for the evaluation is available at compile-time, making it quite difficult to use: https://bugzilla.kernel.org/show_bug.cgi?id=214861 With -Warray-bounds almost enabled globally, it doesn't make sense to keep this around.
Unified · Split
| @@ -112,19 +112,6 @@ config UBSAN_UNREACHABLE · 111 unmodified lines | |||
| 112 | This option enables -fsanitize=unreachable which checks for control | 112 | This option enables -fsanitize=unreachable which checks for control |
| 113 | flow reaching an expected-to-be-unreachable position. | 113 | flow reaching an expected-to-be-unreachable position. |
| 114 | 114 | ||
| 115 | config UBSAN_OBJECT_SIZE | ||
| 116 | bool "Perform checking for accesses beyond the end of objects" | ||
| 117 | default UBSAN | ||
| 118 | # gcc hugely expands stack usage with -fsanitize=object-size | ||
| 119 | # https://lore.kernel.org/lkml/CAHk-=wjPasyJrDuwDnpHJS2TuQfExwe=px-SzLeN8GFMAQJPmQ@mail.gmail.com/ | ||
| 120 | depends on !CC_IS_GCC | ||
| 121 | depends on $(cc-option,-fsanitize=object-size) | ||
| 122 | help | ||
| 123 | This option enables -fsanitize=object-size which checks for accesses | ||
| 124 | beyond the end of objects where the optimizer can determine both the | ||
| 125 | object being operated on and its size, usually seen with bad downcasts, | ||
| 126 | or access to struct members from NULL pointers. | ||
| 127 | |||
| 128 | config UBSAN_BOOL | 115 | config UBSAN_BOOL |
| 129 | bool "Perform checking for non-boolean values used as boolean" | 116 | bool "Perform checking for non-boolean values used as boolean" |
| 130 | default UBSAN | 117 | default UBSAN |
| @@ -79,15 +79,6 @@ static void test_ubsan_load_invalid_value(void) · 78 unmodified lines | |||
| 79 | eval2 = eval; | 79 | eval2 = eval; |
| 80 | } | 80 | } |
| 81 | 81 | ||
| 82 | static void test_ubsan_null_ptr_deref(void) | ||
| 83 | { | ||
| 84 | volatile int *ptr = NULL; | ||
| 85 | int val; | ||
| 86 | |||
| 87 | UBSAN_TEST(CONFIG_UBSAN_OBJECT_SIZE); | ||
| 88 | val = *ptr; | ||
| 89 | } | ||
| 90 | |||
| 91 | static void test_ubsan_misaligned_access(void) | 82 | static void test_ubsan_misaligned_access(void) |
| 92 | { | 83 | { |
| 93 | volatile char arr[5] __aligned(4) = {1, 2, 3, 4, 5}; | 84 | volatile char arr[5] __aligned(4) = {1, 2, 3, 4, 5}; |
| @@ -98,29 +89,16 @@ static void test_ubsan_misaligned_access(void) · 4 unmodified lines | |||
| 98 | *ptr = val; | 89 | *ptr = val; |
| 99 | } | 90 | } |
| 100 | 91 | ||
| 101 | static void test_ubsan_object_size_mismatch(void) | ||
| 102 | { | ||
| 103 | /* "((aligned(8)))" helps this not into be misaligned for ptr-access. */ | ||
| 104 | volatile int val __aligned(8) = 4; | ||
| 105 | volatile long long *ptr, val2; | ||
| 106 | |||
| 107 | UBSAN_TEST(CONFIG_UBSAN_OBJECT_SIZE); | ||
| 108 | ptr = (long long *)&val; | ||
| 109 | val2 = *ptr; | ||
| 110 | } | ||
| 111 | |||
| 112 | static const test_ubsan_fp test_ubsan_array[] = { | 92 | static const test_ubsan_fp test_ubsan_array[] = { |
| 113 | test_ubsan_shift_out_of_bounds, | 93 | test_ubsan_shift_out_of_bounds, |
| 114 | test_ubsan_out_of_bounds, | 94 | test_ubsan_out_of_bounds, |
| 115 | test_ubsan_load_invalid_value, | 95 | test_ubsan_load_invalid_value, |
| 116 | test_ubsan_misaligned_access, | 96 | test_ubsan_misaligned_access, |
| 117 | test_ubsan_object_size_mismatch, | ||
| 118 | }; | 97 | }; |
| 119 | 98 | ||
| 120 | /* Excluded because they Oops the module. */ | 99 | /* Excluded because they Oops the module. */ |
| 121 | static const test_ubsan_fp skip_ubsan_array[] = { | 100 | static const test_ubsan_fp skip_ubsan_array[] = { |
| 122 | test_ubsan_divrem_overflow, | 101 | test_ubsan_divrem_overflow, |
| 123 | test_ubsan_null_ptr_deref, | ||
| 124 | }; | 102 | }; |
| 125 | 103 | ||
| 126 | static int __init test_ubsan_init(void) | 104 | static int __init test_ubsan_init(void) |
| @@ -8,7 +8,6 @@ ubsan-cflags-$(CONFIG_UBSAN_LOCAL_BOUNDS) += -fsanitize=local-bounds · 7 unmodified lines | |||
| 8 | ubsan-cflags-$(CONFIG_UBSAN_SHIFT) += -fsanitize=shift | 8 | ubsan-cflags-$(CONFIG_UBSAN_SHIFT) += -fsanitize=shift |
| 9 | ubsan-cflags-$(CONFIG_UBSAN_DIV_ZERO) += -fsanitize=integer-divide-by-zero | 9 | ubsan-cflags-$(CONFIG_UBSAN_DIV_ZERO) += -fsanitize=integer-divide-by-zero |
| 10 | ubsan-cflags-$(CONFIG_UBSAN_UNREACHABLE) += -fsanitize=unreachable | 10 | ubsan-cflags-$(CONFIG_UBSAN_UNREACHABLE) += -fsanitize=unreachable |
| 11 | ubsan-cflags-$(CONFIG_UBSAN_OBJECT_SIZE) += -fsanitize=object-size | ||
| 12 | ubsan-cflags-$(CONFIG_UBSAN_BOOL) += -fsanitize=bool | 11 | ubsan-cflags-$(CONFIG_UBSAN_BOOL) += -fsanitize=bool |
| 13 | ubsan-cflags-$(CONFIG_UBSAN_ENUM) += -fsanitize=enum | 12 | ubsan-cflags-$(CONFIG_UBSAN_ENUM) += -fsanitize=enum |
| 14 | ubsan-cflags-$(CONFIG_UBSAN_TRAP) += -fsanitize-undefined-trap-on-error | 13 | ubsan-cflags-$(CONFIG_UBSAN_TRAP) += -fsanitize-undefined-trap-on-error |