History

ubsan: remove CONFIG_UBSAN_OBJECT_SIZE

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.

Kees Cook committed 4 years ago

Commit 69d0db01 parent bece04b3 files · +0 −36Browse files

Unified · Split

3 files
  1. lib/Kconfig.ubsan +0 −13
  2. lib/test_ubsan.c +0 −22
  3. scripts/Makefile.ubsan +0 −1
lib/Kconfig.ubsan+0−13
@@ -112,19 +112,6 @@ config UBSAN_UNREACHABLE · 111 unmodified lines
112 This option enables -fsanitize=unreachable which checks for control112 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
115config 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
128config UBSAN_BOOL115config 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 UBSAN117 default UBSAN
lib/test_ubsan.c+0−22
@@ -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
82static 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
91static void test_ubsan_misaligned_access(void)82static 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
101static 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
112static const test_ubsan_fp test_ubsan_array[] = {92static 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. */
121static const test_ubsan_fp skip_ubsan_array[] = {100static 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
126static int __init test_ubsan_init(void)104static int __init test_ubsan_init(void)
scripts/Makefile.ubsan+0−1
@@ -8,7 +8,6 @@ ubsan-cflags-$(CONFIG_UBSAN_LOCAL_BOUNDS) += -fsanitize=local-bounds · 7 unmodified lines
8ubsan-cflags-$(CONFIG_UBSAN_SHIFT) += -fsanitize=shift8ubsan-cflags-$(CONFIG_UBSAN_SHIFT) += -fsanitize=shift
9ubsan-cflags-$(CONFIG_UBSAN_DIV_ZERO) += -fsanitize=integer-divide-by-zero9ubsan-cflags-$(CONFIG_UBSAN_DIV_ZERO) += -fsanitize=integer-divide-by-zero
10ubsan-cflags-$(CONFIG_UBSAN_UNREACHABLE) += -fsanitize=unreachable10ubsan-cflags-$(CONFIG_UBSAN_UNREACHABLE) += -fsanitize=unreachable
11ubsan-cflags-$(CONFIG_UBSAN_OBJECT_SIZE) += -fsanitize=object-size
12ubsan-cflags-$(CONFIG_UBSAN_BOOL) += -fsanitize=bool11ubsan-cflags-$(CONFIG_UBSAN_BOOL) += -fsanitize=bool
13ubsan-cflags-$(CONFIG_UBSAN_ENUM) += -fsanitize=enum12ubsan-cflags-$(CONFIG_UBSAN_ENUM) += -fsanitize=enum
14ubsan-cflags-$(CONFIG_UBSAN_TRAP) += -fsanitize-undefined-trap-on-error13ubsan-cflags-$(CONFIG_UBSAN_TRAP) += -fsanitize-undefined-trap-on-error

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t