Skip to content

Commit 6aaa31a

Browse files
aryabinintorvalds
authored andcommitted
ubsan: remove overflow checks
Since GCC 8.0 -fsanitize=signed-integer-overflow doesn't work with -fwrapv. -fwrapv makes signed overflows defines and GCC essentially disables ubsan checks. On GCC < 8.0 -fwrapv doesn't have influence on -fsanitize=signed-integer-overflow setting, so it kinda works but generates false-positves and violates uaccess rules: lib/iov_iter.o: warning: objtool: iovec_from_user()+0x22d: call to __ubsan_handle_add_overflow() with UACCESS enabled Disable signed overflow checks to avoid these problems. Remove unsigned overflow checks as well. Unsigned overflow appeared as side effect of commit cdf8a76 ("ubsan: move cc-option tests into Kconfig"), but it never worked (kernel doesn't boot). And unsigned overflows are allowed by C standard, so it just pointless. Link: https://lkml.kernel.org/r/20210209232348.20510-1-ryabinin.a.a@gmail.com Signed-off-by: Andrey Ryabinin <ryabinin.a.a@gmail.com> Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org> Cc: Josh Poimboeuf <jpoimboe@redhat.com> Cc: Randy Dunlap <rdunlap@infradead.org> Cc: Stephen Rothwell <sfr@canb.auug.org.au> Cc: Dmitry Vyukov <dvyukov@google.com> Cc: Kees Cook <keescook@chromium.org> Cc: Alexander Viro <viro@zeniv.linux.org.uk> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent d54ce61 commit 6aaa31a

File tree

4 files changed

+0
-136
lines changed

4 files changed

+0
-136
lines changed

lib/Kconfig.ubsan

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -112,23 +112,6 @@ config UBSAN_UNREACHABLE
112112
This option enables -fsanitize=unreachable which checks for control
113113
flow reaching an expected-to-be-unreachable position.
114114

115-
config UBSAN_SIGNED_OVERFLOW
116-
bool "Perform checking for signed arithmetic overflow"
117-
default UBSAN
118-
depends on $(cc-option,-fsanitize=signed-integer-overflow)
119-
help
120-
This option enables -fsanitize=signed-integer-overflow which checks
121-
for overflow of any arithmetic operations with signed integers.
122-
123-
config UBSAN_UNSIGNED_OVERFLOW
124-
bool "Perform checking for unsigned arithmetic overflow"
125-
depends on $(cc-option,-fsanitize=unsigned-integer-overflow)
126-
depends on !X86_32 # avoid excessive stack usage on x86-32/clang
127-
help
128-
This option enables -fsanitize=unsigned-integer-overflow which checks
129-
for overflow of any arithmetic operations with unsigned integers. This
130-
currently causes x86 to fail to boot.
131-
132115
config UBSAN_OBJECT_SIZE
133116
bool "Perform checking for accesses beyond the end of objects"
134117
default UBSAN

lib/test_ubsan.c

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -11,51 +11,6 @@ typedef void(*test_ubsan_fp)(void);
1111
#config, IS_ENABLED(config) ? "y" : "n"); \
1212
} while (0)
1313

14-
static void test_ubsan_add_overflow(void)
15-
{
16-
volatile int val = INT_MAX;
17-
volatile unsigned int uval = UINT_MAX;
18-
19-
UBSAN_TEST(CONFIG_UBSAN_SIGNED_OVERFLOW);
20-
val += 2;
21-
22-
UBSAN_TEST(CONFIG_UBSAN_UNSIGNED_OVERFLOW);
23-
uval += 2;
24-
}
25-
26-
static void test_ubsan_sub_overflow(void)
27-
{
28-
volatile int val = INT_MIN;
29-
volatile unsigned int uval = 0;
30-
volatile int val2 = 2;
31-
32-
UBSAN_TEST(CONFIG_UBSAN_SIGNED_OVERFLOW);
33-
val -= val2;
34-
35-
UBSAN_TEST(CONFIG_UBSAN_UNSIGNED_OVERFLOW);
36-
uval -= val2;
37-
}
38-
39-
static void test_ubsan_mul_overflow(void)
40-
{
41-
volatile int val = INT_MAX / 2;
42-
volatile unsigned int uval = UINT_MAX / 2;
43-
44-
UBSAN_TEST(CONFIG_UBSAN_SIGNED_OVERFLOW);
45-
val *= 3;
46-
47-
UBSAN_TEST(CONFIG_UBSAN_UNSIGNED_OVERFLOW);
48-
uval *= 3;
49-
}
50-
51-
static void test_ubsan_negate_overflow(void)
52-
{
53-
volatile int val = INT_MIN;
54-
55-
UBSAN_TEST(CONFIG_UBSAN_SIGNED_OVERFLOW);
56-
val = -val;
57-
}
58-
5914
static void test_ubsan_divrem_overflow(void)
6015
{
6116
volatile int val = 16;
@@ -155,10 +110,6 @@ static void test_ubsan_object_size_mismatch(void)
155110
}
156111

157112
static const test_ubsan_fp test_ubsan_array[] = {
158-
test_ubsan_add_overflow,
159-
test_ubsan_sub_overflow,
160-
test_ubsan_mul_overflow,
161-
test_ubsan_negate_overflow,
162113
test_ubsan_shift_out_of_bounds,
163114
test_ubsan_out_of_bounds,
164115
test_ubsan_load_invalid_value,

lib/ubsan.c

Lines changed: 0 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -163,74 +163,6 @@ static void ubsan_epilogue(void)
163163
}
164164
}
165165

166-
static void handle_overflow(struct overflow_data *data, void *lhs,
167-
void *rhs, char op)
168-
{
169-
170-
struct type_descriptor *type = data->type;
171-
char lhs_val_str[VALUE_LENGTH];
172-
char rhs_val_str[VALUE_LENGTH];
173-
174-
if (suppress_report(&data->location))
175-
return;
176-
177-
ubsan_prologue(&data->location, type_is_signed(type) ?
178-
"signed-integer-overflow" :
179-
"unsigned-integer-overflow");
180-
181-
val_to_string(lhs_val_str, sizeof(lhs_val_str), type, lhs);
182-
val_to_string(rhs_val_str, sizeof(rhs_val_str), type, rhs);
183-
pr_err("%s %c %s cannot be represented in type %s\n",
184-
lhs_val_str,
185-
op,
186-
rhs_val_str,
187-
type->type_name);
188-
189-
ubsan_epilogue();
190-
}
191-
192-
void __ubsan_handle_add_overflow(void *data,
193-
void *lhs, void *rhs)
194-
{
195-
196-
handle_overflow(data, lhs, rhs, '+');
197-
}
198-
EXPORT_SYMBOL(__ubsan_handle_add_overflow);
199-
200-
void __ubsan_handle_sub_overflow(void *data,
201-
void *lhs, void *rhs)
202-
{
203-
handle_overflow(data, lhs, rhs, '-');
204-
}
205-
EXPORT_SYMBOL(__ubsan_handle_sub_overflow);
206-
207-
void __ubsan_handle_mul_overflow(void *data,
208-
void *lhs, void *rhs)
209-
{
210-
handle_overflow(data, lhs, rhs, '*');
211-
}
212-
EXPORT_SYMBOL(__ubsan_handle_mul_overflow);
213-
214-
void __ubsan_handle_negate_overflow(void *_data, void *old_val)
215-
{
216-
struct overflow_data *data = _data;
217-
char old_val_str[VALUE_LENGTH];
218-
219-
if (suppress_report(&data->location))
220-
return;
221-
222-
ubsan_prologue(&data->location, "negation-overflow");
223-
224-
val_to_string(old_val_str, sizeof(old_val_str), data->type, old_val);
225-
226-
pr_err("negation of %s cannot be represented in type %s:\n",
227-
old_val_str, data->type->type_name);
228-
229-
ubsan_epilogue();
230-
}
231-
EXPORT_SYMBOL(__ubsan_handle_negate_overflow);
232-
233-
234166
void __ubsan_handle_divrem_overflow(void *_data, void *lhs, void *rhs)
235167
{
236168
struct overflow_data *data = _data;

scripts/Makefile.ubsan

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ ubsan-cflags-$(CONFIG_UBSAN_LOCAL_BOUNDS) += -fsanitize=local-bounds
88
ubsan-cflags-$(CONFIG_UBSAN_SHIFT) += -fsanitize=shift
99
ubsan-cflags-$(CONFIG_UBSAN_DIV_ZERO) += -fsanitize=integer-divide-by-zero
1010
ubsan-cflags-$(CONFIG_UBSAN_UNREACHABLE) += -fsanitize=unreachable
11-
ubsan-cflags-$(CONFIG_UBSAN_SIGNED_OVERFLOW) += -fsanitize=signed-integer-overflow
12-
ubsan-cflags-$(CONFIG_UBSAN_UNSIGNED_OVERFLOW) += -fsanitize=unsigned-integer-overflow
1311
ubsan-cflags-$(CONFIG_UBSAN_OBJECT_SIZE) += -fsanitize=object-size
1412
ubsan-cflags-$(CONFIG_UBSAN_BOOL) += -fsanitize=bool
1513
ubsan-cflags-$(CONFIG_UBSAN_ENUM) += -fsanitize=enum

0 commit comments

Comments
 (0)