Commit f0996bc2 authored by Andrey Ryabinin's avatar Andrey Ryabinin Committed by Linus Torvalds

ubsan: Fix nasty -Wbuiltin-declaration-mismatch GCC-9 warnings

Building lib/ubsan.c with gcc-9 results in a ton of nasty warnings like
this one:

    lib/ubsan.c warning: conflicting types for built-in function
         ‘__ubsan_handle_negate_overflow’; expected ‘void(void *, void *)’ [-Wbuiltin-declaration-mismatch]

The kernel's declarations of __ubsan_handle_*() often uses 'unsigned
long' types in parameters while GCC these parameters as 'void *' types,
hence the mismatch.

Fix this by using 'void *' to match GCC's declarations.
Reported-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: default avatarAndrey Ryabinin <aryabinin@virtuozzo.com>
Fixes: c6d30853 ("UBSAN: run-time undefined behavior sanity checker")
Cc: <stable@vger.kernel.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent e93c9c99
...@@ -86,11 +86,13 @@ static bool is_inline_int(struct type_descriptor *type) ...@@ -86,11 +86,13 @@ static bool is_inline_int(struct type_descriptor *type)
return bits <= inline_bits; return bits <= inline_bits;
} }
static s_max get_signed_val(struct type_descriptor *type, unsigned long val) static s_max get_signed_val(struct type_descriptor *type, void *val)
{ {
if (is_inline_int(type)) { if (is_inline_int(type)) {
unsigned extra_bits = sizeof(s_max)*8 - type_bit_width(type); unsigned extra_bits = sizeof(s_max)*8 - type_bit_width(type);
return ((s_max)val) << extra_bits >> extra_bits; unsigned long ulong_val = (unsigned long)val;
return ((s_max)ulong_val) << extra_bits >> extra_bits;
} }
if (type_bit_width(type) == 64) if (type_bit_width(type) == 64)
...@@ -99,15 +101,15 @@ static s_max get_signed_val(struct type_descriptor *type, unsigned long val) ...@@ -99,15 +101,15 @@ static s_max get_signed_val(struct type_descriptor *type, unsigned long val)
return *(s_max *)val; return *(s_max *)val;
} }
static bool val_is_negative(struct type_descriptor *type, unsigned long val) static bool val_is_negative(struct type_descriptor *type, void *val)
{ {
return type_is_signed(type) && get_signed_val(type, val) < 0; return type_is_signed(type) && get_signed_val(type, val) < 0;
} }
static u_max get_unsigned_val(struct type_descriptor *type, unsigned long val) static u_max get_unsigned_val(struct type_descriptor *type, void *val)
{ {
if (is_inline_int(type)) if (is_inline_int(type))
return val; return (unsigned long)val;
if (type_bit_width(type) == 64) if (type_bit_width(type) == 64)
return *(u64 *)val; return *(u64 *)val;
...@@ -116,7 +118,7 @@ static u_max get_unsigned_val(struct type_descriptor *type, unsigned long val) ...@@ -116,7 +118,7 @@ static u_max get_unsigned_val(struct type_descriptor *type, unsigned long val)
} }
static void val_to_string(char *str, size_t size, struct type_descriptor *type, static void val_to_string(char *str, size_t size, struct type_descriptor *type,
unsigned long value) void *value)
{ {
if (type_is_int(type)) { if (type_is_int(type)) {
if (type_bit_width(type) == 128) { if (type_bit_width(type) == 128) {
...@@ -163,8 +165,8 @@ static void ubsan_epilogue(unsigned long *flags) ...@@ -163,8 +165,8 @@ static void ubsan_epilogue(unsigned long *flags)
current->in_ubsan--; current->in_ubsan--;
} }
static void handle_overflow(struct overflow_data *data, unsigned long lhs, static void handle_overflow(struct overflow_data *data, void *lhs,
unsigned long rhs, char op) void *rhs, char op)
{ {
struct type_descriptor *type = data->type; struct type_descriptor *type = data->type;
...@@ -191,8 +193,7 @@ static void handle_overflow(struct overflow_data *data, unsigned long lhs, ...@@ -191,8 +193,7 @@ static void handle_overflow(struct overflow_data *data, unsigned long lhs,
} }
void __ubsan_handle_add_overflow(struct overflow_data *data, void __ubsan_handle_add_overflow(struct overflow_data *data,
unsigned long lhs, void *lhs, void *rhs)
unsigned long rhs)
{ {
handle_overflow(data, lhs, rhs, '+'); handle_overflow(data, lhs, rhs, '+');
...@@ -200,23 +201,21 @@ void __ubsan_handle_add_overflow(struct overflow_data *data, ...@@ -200,23 +201,21 @@ void __ubsan_handle_add_overflow(struct overflow_data *data,
EXPORT_SYMBOL(__ubsan_handle_add_overflow); EXPORT_SYMBOL(__ubsan_handle_add_overflow);
void __ubsan_handle_sub_overflow(struct overflow_data *data, void __ubsan_handle_sub_overflow(struct overflow_data *data,
unsigned long lhs, void *lhs, void *rhs)
unsigned long rhs)
{ {
handle_overflow(data, lhs, rhs, '-'); handle_overflow(data, lhs, rhs, '-');
} }
EXPORT_SYMBOL(__ubsan_handle_sub_overflow); EXPORT_SYMBOL(__ubsan_handle_sub_overflow);
void __ubsan_handle_mul_overflow(struct overflow_data *data, void __ubsan_handle_mul_overflow(struct overflow_data *data,
unsigned long lhs, void *lhs, void *rhs)
unsigned long rhs)
{ {
handle_overflow(data, lhs, rhs, '*'); handle_overflow(data, lhs, rhs, '*');
} }
EXPORT_SYMBOL(__ubsan_handle_mul_overflow); EXPORT_SYMBOL(__ubsan_handle_mul_overflow);
void __ubsan_handle_negate_overflow(struct overflow_data *data, void __ubsan_handle_negate_overflow(struct overflow_data *data,
unsigned long old_val) void *old_val)
{ {
unsigned long flags; unsigned long flags;
char old_val_str[VALUE_LENGTH]; char old_val_str[VALUE_LENGTH];
...@@ -237,8 +236,7 @@ EXPORT_SYMBOL(__ubsan_handle_negate_overflow); ...@@ -237,8 +236,7 @@ EXPORT_SYMBOL(__ubsan_handle_negate_overflow);
void __ubsan_handle_divrem_overflow(struct overflow_data *data, void __ubsan_handle_divrem_overflow(struct overflow_data *data,
unsigned long lhs, void *lhs, void *rhs)
unsigned long rhs)
{ {
unsigned long flags; unsigned long flags;
char rhs_val_str[VALUE_LENGTH]; char rhs_val_str[VALUE_LENGTH];
...@@ -323,7 +321,7 @@ static void ubsan_type_mismatch_common(struct type_mismatch_data_common *data, ...@@ -323,7 +321,7 @@ static void ubsan_type_mismatch_common(struct type_mismatch_data_common *data,
} }
void __ubsan_handle_type_mismatch(struct type_mismatch_data *data, void __ubsan_handle_type_mismatch(struct type_mismatch_data *data,
unsigned long ptr) void *ptr)
{ {
struct type_mismatch_data_common common_data = { struct type_mismatch_data_common common_data = {
.location = &data->location, .location = &data->location,
...@@ -332,12 +330,12 @@ void __ubsan_handle_type_mismatch(struct type_mismatch_data *data, ...@@ -332,12 +330,12 @@ void __ubsan_handle_type_mismatch(struct type_mismatch_data *data,
.type_check_kind = data->type_check_kind .type_check_kind = data->type_check_kind
}; };
ubsan_type_mismatch_common(&common_data, ptr); ubsan_type_mismatch_common(&common_data, (unsigned long)ptr);
} }
EXPORT_SYMBOL(__ubsan_handle_type_mismatch); EXPORT_SYMBOL(__ubsan_handle_type_mismatch);
void __ubsan_handle_type_mismatch_v1(struct type_mismatch_data_v1 *data, void __ubsan_handle_type_mismatch_v1(struct type_mismatch_data_v1 *data,
unsigned long ptr) void *ptr)
{ {
struct type_mismatch_data_common common_data = { struct type_mismatch_data_common common_data = {
...@@ -347,12 +345,12 @@ void __ubsan_handle_type_mismatch_v1(struct type_mismatch_data_v1 *data, ...@@ -347,12 +345,12 @@ void __ubsan_handle_type_mismatch_v1(struct type_mismatch_data_v1 *data,
.type_check_kind = data->type_check_kind .type_check_kind = data->type_check_kind
}; };
ubsan_type_mismatch_common(&common_data, ptr); ubsan_type_mismatch_common(&common_data, (unsigned long)ptr);
} }
EXPORT_SYMBOL(__ubsan_handle_type_mismatch_v1); EXPORT_SYMBOL(__ubsan_handle_type_mismatch_v1);
void __ubsan_handle_vla_bound_not_positive(struct vla_bound_data *data, void __ubsan_handle_vla_bound_not_positive(struct vla_bound_data *data,
unsigned long bound) void *bound)
{ {
unsigned long flags; unsigned long flags;
char bound_str[VALUE_LENGTH]; char bound_str[VALUE_LENGTH];
...@@ -369,8 +367,7 @@ void __ubsan_handle_vla_bound_not_positive(struct vla_bound_data *data, ...@@ -369,8 +367,7 @@ void __ubsan_handle_vla_bound_not_positive(struct vla_bound_data *data,
} }
EXPORT_SYMBOL(__ubsan_handle_vla_bound_not_positive); EXPORT_SYMBOL(__ubsan_handle_vla_bound_not_positive);
void __ubsan_handle_out_of_bounds(struct out_of_bounds_data *data, void __ubsan_handle_out_of_bounds(struct out_of_bounds_data *data, void *index)
unsigned long index)
{ {
unsigned long flags; unsigned long flags;
char index_str[VALUE_LENGTH]; char index_str[VALUE_LENGTH];
...@@ -388,7 +385,7 @@ void __ubsan_handle_out_of_bounds(struct out_of_bounds_data *data, ...@@ -388,7 +385,7 @@ void __ubsan_handle_out_of_bounds(struct out_of_bounds_data *data,
EXPORT_SYMBOL(__ubsan_handle_out_of_bounds); EXPORT_SYMBOL(__ubsan_handle_out_of_bounds);
void __ubsan_handle_shift_out_of_bounds(struct shift_out_of_bounds_data *data, void __ubsan_handle_shift_out_of_bounds(struct shift_out_of_bounds_data *data,
unsigned long lhs, unsigned long rhs) void *lhs, void *rhs)
{ {
unsigned long flags; unsigned long flags;
struct type_descriptor *rhs_type = data->rhs_type; struct type_descriptor *rhs_type = data->rhs_type;
...@@ -439,7 +436,7 @@ void __ubsan_handle_builtin_unreachable(struct unreachable_data *data) ...@@ -439,7 +436,7 @@ void __ubsan_handle_builtin_unreachable(struct unreachable_data *data)
EXPORT_SYMBOL(__ubsan_handle_builtin_unreachable); EXPORT_SYMBOL(__ubsan_handle_builtin_unreachable);
void __ubsan_handle_load_invalid_value(struct invalid_value_data *data, void __ubsan_handle_load_invalid_value(struct invalid_value_data *data,
unsigned long val) void *val)
{ {
unsigned long flags; unsigned long flags;
char val_str[VALUE_LENGTH]; char val_str[VALUE_LENGTH];
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment