1 From f0996bc2978e02d2ea898101462b960f6119b18f Mon Sep 17 00:00:00 2001
2 From: Andrey Ryabinin <aryabinin@virtuozzo.com>
3 Date: Mon, 6 May 2019 13:45:26 +0300
4 Subject: ubsan: Fix nasty -Wbuiltin-declaration-mismatch GCC-9 warnings
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
9 From: Andrey Ryabinin <aryabinin@virtuozzo.com>
11 commit f0996bc2978e02d2ea898101462b960f6119b18f upstream.
13 Building lib/ubsan.c with gcc-9 results in a ton of nasty warnings like
16 lib/ubsan.c warning: conflicting types for built-in function
17 ‘__ubsan_handle_negate_overflow’; expected ‘void(void *, void *)’ [-Wbuiltin-declaration-mismatch]
19 The kernel's declarations of __ubsan_handle_*() often uses 'unsigned
20 long' types in parameters while GCC these parameters as 'void *' types,
23 Fix this by using 'void *' to match GCC's declarations.
25 Reported-by: Linus Torvalds <torvalds@linux-foundation.org>
26 Signed-off-by: Andrey Ryabinin <aryabinin@virtuozzo.com>
27 Fixes: c6d308534aef ("UBSAN: run-time undefined behavior sanity checker")
28 Cc: <stable@vger.kernel.org>
29 Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
30 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
33 lib/ubsan.c | 49 +++++++++++++++++++++++--------------------------
34 1 file changed, 23 insertions(+), 26 deletions(-)
38 @@ -86,11 +86,13 @@ static bool is_inline_int(struct type_de
39 return bits <= inline_bits;
42 -static s_max get_signed_val(struct type_descriptor *type, unsigned long val)
43 +static s_max get_signed_val(struct type_descriptor *type, void *val)
45 if (is_inline_int(type)) {
46 unsigned extra_bits = sizeof(s_max)*8 - type_bit_width(type);
47 - return ((s_max)val) << extra_bits >> extra_bits;
48 + unsigned long ulong_val = (unsigned long)val;
50 + return ((s_max)ulong_val) << extra_bits >> extra_bits;
53 if (type_bit_width(type) == 64)
54 @@ -99,15 +101,15 @@ static s_max get_signed_val(struct type_
58 -static bool val_is_negative(struct type_descriptor *type, unsigned long val)
59 +static bool val_is_negative(struct type_descriptor *type, void *val)
61 return type_is_signed(type) && get_signed_val(type, val) < 0;
64 -static u_max get_unsigned_val(struct type_descriptor *type, unsigned long val)
65 +static u_max get_unsigned_val(struct type_descriptor *type, void *val)
67 if (is_inline_int(type))
69 + return (unsigned long)val;
71 if (type_bit_width(type) == 64)
73 @@ -116,7 +118,7 @@ static u_max get_unsigned_val(struct typ
76 static void val_to_string(char *str, size_t size, struct type_descriptor *type,
77 - unsigned long value)
80 if (type_is_int(type)) {
81 if (type_bit_width(type) == 128) {
82 @@ -168,8 +170,8 @@ static void ubsan_epilogue(unsigned long
86 -static void handle_overflow(struct overflow_data *data, unsigned long lhs,
87 - unsigned long rhs, char op)
88 +static void handle_overflow(struct overflow_data *data, void *lhs,
92 struct type_descriptor *type = data->type;
93 @@ -196,8 +198,7 @@ static void handle_overflow(struct overf
96 void __ubsan_handle_add_overflow(struct overflow_data *data,
99 + void *lhs, void *rhs)
102 handle_overflow(data, lhs, rhs, '+');
103 @@ -205,23 +206,21 @@ void __ubsan_handle_add_overflow(struct
104 EXPORT_SYMBOL(__ubsan_handle_add_overflow);
106 void __ubsan_handle_sub_overflow(struct overflow_data *data,
109 + void *lhs, void *rhs)
111 handle_overflow(data, lhs, rhs, '-');
113 EXPORT_SYMBOL(__ubsan_handle_sub_overflow);
115 void __ubsan_handle_mul_overflow(struct overflow_data *data,
118 + void *lhs, void *rhs)
120 handle_overflow(data, lhs, rhs, '*');
122 EXPORT_SYMBOL(__ubsan_handle_mul_overflow);
124 void __ubsan_handle_negate_overflow(struct overflow_data *data,
125 - unsigned long old_val)
129 char old_val_str[VALUE_LENGTH];
130 @@ -242,8 +241,7 @@ EXPORT_SYMBOL(__ubsan_handle_negate_over
133 void __ubsan_handle_divrem_overflow(struct overflow_data *data,
136 + void *lhs, void *rhs)
139 char rhs_val_str[VALUE_LENGTH];
140 @@ -328,7 +326,7 @@ static void ubsan_type_mismatch_common(s
143 void __ubsan_handle_type_mismatch(struct type_mismatch_data *data,
147 struct type_mismatch_data_common common_data = {
148 .location = &data->location,
149 @@ -337,12 +335,12 @@ void __ubsan_handle_type_mismatch(struct
150 .type_check_kind = data->type_check_kind
153 - ubsan_type_mismatch_common(&common_data, ptr);
154 + ubsan_type_mismatch_common(&common_data, (unsigned long)ptr);
156 EXPORT_SYMBOL(__ubsan_handle_type_mismatch);
158 void __ubsan_handle_type_mismatch_v1(struct type_mismatch_data_v1 *data,
163 struct type_mismatch_data_common common_data = {
164 @@ -352,7 +350,7 @@ void __ubsan_handle_type_mismatch_v1(str
165 .type_check_kind = data->type_check_kind
168 - ubsan_type_mismatch_common(&common_data, ptr);
169 + ubsan_type_mismatch_common(&common_data, (unsigned long)ptr);
171 EXPORT_SYMBOL(__ubsan_handle_type_mismatch_v1);
173 @@ -376,7 +374,7 @@ void __ubsan_handle_nonnull_return(struc
174 EXPORT_SYMBOL(__ubsan_handle_nonnull_return);
176 void __ubsan_handle_vla_bound_not_positive(struct vla_bound_data *data,
177 - unsigned long bound)
181 char bound_str[VALUE_LENGTH];
182 @@ -393,8 +391,7 @@ void __ubsan_handle_vla_bound_not_positi
184 EXPORT_SYMBOL(__ubsan_handle_vla_bound_not_positive);
186 -void __ubsan_handle_out_of_bounds(struct out_of_bounds_data *data,
187 - unsigned long index)
188 +void __ubsan_handle_out_of_bounds(struct out_of_bounds_data *data, void *index)
191 char index_str[VALUE_LENGTH];
192 @@ -412,7 +409,7 @@ void __ubsan_handle_out_of_bounds(struct
193 EXPORT_SYMBOL(__ubsan_handle_out_of_bounds);
195 void __ubsan_handle_shift_out_of_bounds(struct shift_out_of_bounds_data *data,
196 - unsigned long lhs, unsigned long rhs)
197 + void *lhs, void *rhs)
200 struct type_descriptor *rhs_type = data->rhs_type;
201 @@ -463,7 +460,7 @@ void __ubsan_handle_builtin_unreachable(
202 EXPORT_SYMBOL(__ubsan_handle_builtin_unreachable);
204 void __ubsan_handle_load_invalid_value(struct invalid_value_data *data,
209 char val_str[VALUE_LENGTH];