]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blame - releases/4.9.175/ubsan-fix-nasty-wbuiltin-declaration-mismatch-gcc-9-warnings.patch
Linux 4.9.175
[thirdparty/kernel/stable-queue.git] / releases / 4.9.175 / ubsan-fix-nasty-wbuiltin-declaration-mismatch-gcc-9-warnings.patch
CommitLineData
d70985a8
GKH
1From f0996bc2978e02d2ea898101462b960f6119b18f Mon Sep 17 00:00:00 2001
2From: Andrey Ryabinin <aryabinin@virtuozzo.com>
3Date: Mon, 6 May 2019 13:45:26 +0300
4Subject: ubsan: Fix nasty -Wbuiltin-declaration-mismatch GCC-9 warnings
5MIME-Version: 1.0
6Content-Type: text/plain; charset=UTF-8
7Content-Transfer-Encoding: 8bit
8
9From: Andrey Ryabinin <aryabinin@virtuozzo.com>
10
11commit f0996bc2978e02d2ea898101462b960f6119b18f upstream.
12
13Building lib/ubsan.c with gcc-9 results in a ton of nasty warnings like
14this one:
15
16 lib/ubsan.c warning: conflicting types for built-in function
17 ‘__ubsan_handle_negate_overflow’; expected ‘void(void *, void *)’ [-Wbuiltin-declaration-mismatch]
18
19The kernel's declarations of __ubsan_handle_*() often uses 'unsigned
20long' types in parameters while GCC these parameters as 'void *' types,
21hence the mismatch.
22
23Fix this by using 'void *' to match GCC's declarations.
24
25Reported-by: Linus Torvalds <torvalds@linux-foundation.org>
26Signed-off-by: Andrey Ryabinin <aryabinin@virtuozzo.com>
27Fixes: c6d308534aef ("UBSAN: run-time undefined behavior sanity checker")
28Cc: <stable@vger.kernel.org>
29Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
30Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
31
32---
33 lib/ubsan.c | 49 +++++++++++++++++++++++--------------------------
34 1 file changed, 23 insertions(+), 26 deletions(-)
35
36--- a/lib/ubsan.c
37+++ b/lib/ubsan.c
38@@ -86,11 +86,13 @@ static bool is_inline_int(struct type_de
39 return bits <= inline_bits;
40 }
41
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)
44 {
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;
49+
50+ return ((s_max)ulong_val) << extra_bits >> extra_bits;
51 }
52
53 if (type_bit_width(type) == 64)
54@@ -99,15 +101,15 @@ static s_max get_signed_val(struct type_
55 return *(s_max *)val;
56 }
57
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)
60 {
61 return type_is_signed(type) && get_signed_val(type, val) < 0;
62 }
63
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)
66 {
67 if (is_inline_int(type))
68- return val;
69+ return (unsigned long)val;
70
71 if (type_bit_width(type) == 64)
72 return *(u64 *)val;
73@@ -116,7 +118,7 @@ static u_max get_unsigned_val(struct typ
74 }
75
76 static void val_to_string(char *str, size_t size, struct type_descriptor *type,
77- unsigned long value)
78+ void *value)
79 {
80 if (type_is_int(type)) {
81 if (type_bit_width(type) == 128) {
82@@ -168,8 +170,8 @@ static void ubsan_epilogue(unsigned long
83 current->in_ubsan--;
84 }
85
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,
89+ void *rhs, char op)
90 {
91
92 struct type_descriptor *type = data->type;
93@@ -196,8 +198,7 @@ static void handle_overflow(struct overf
94 }
95
96 void __ubsan_handle_add_overflow(struct overflow_data *data,
97- unsigned long lhs,
98- unsigned long rhs)
99+ void *lhs, void *rhs)
100 {
101
102 handle_overflow(data, lhs, rhs, '+');
103@@ -205,23 +206,21 @@ void __ubsan_handle_add_overflow(struct
104 EXPORT_SYMBOL(__ubsan_handle_add_overflow);
105
106 void __ubsan_handle_sub_overflow(struct overflow_data *data,
107- unsigned long lhs,
108- unsigned long rhs)
109+ void *lhs, void *rhs)
110 {
111 handle_overflow(data, lhs, rhs, '-');
112 }
113 EXPORT_SYMBOL(__ubsan_handle_sub_overflow);
114
115 void __ubsan_handle_mul_overflow(struct overflow_data *data,
116- unsigned long lhs,
117- unsigned long rhs)
118+ void *lhs, void *rhs)
119 {
120 handle_overflow(data, lhs, rhs, '*');
121 }
122 EXPORT_SYMBOL(__ubsan_handle_mul_overflow);
123
124 void __ubsan_handle_negate_overflow(struct overflow_data *data,
125- unsigned long old_val)
126+ void *old_val)
127 {
128 unsigned long flags;
129 char old_val_str[VALUE_LENGTH];
130@@ -242,8 +241,7 @@ EXPORT_SYMBOL(__ubsan_handle_negate_over
131
132
133 void __ubsan_handle_divrem_overflow(struct overflow_data *data,
134- unsigned long lhs,
135- unsigned long rhs)
136+ void *lhs, void *rhs)
137 {
138 unsigned long flags;
139 char rhs_val_str[VALUE_LENGTH];
140@@ -328,7 +326,7 @@ static void ubsan_type_mismatch_common(s
141 }
142
143 void __ubsan_handle_type_mismatch(struct type_mismatch_data *data,
144- unsigned long ptr)
145+ void *ptr)
146 {
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
151 };
152
153- ubsan_type_mismatch_common(&common_data, ptr);
154+ ubsan_type_mismatch_common(&common_data, (unsigned long)ptr);
155 }
156 EXPORT_SYMBOL(__ubsan_handle_type_mismatch);
157
158 void __ubsan_handle_type_mismatch_v1(struct type_mismatch_data_v1 *data,
159- unsigned long ptr)
160+ void *ptr)
161 {
162
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
166 };
167
168- ubsan_type_mismatch_common(&common_data, ptr);
169+ ubsan_type_mismatch_common(&common_data, (unsigned long)ptr);
170 }
171 EXPORT_SYMBOL(__ubsan_handle_type_mismatch_v1);
172
173@@ -376,7 +374,7 @@ void __ubsan_handle_nonnull_return(struc
174 EXPORT_SYMBOL(__ubsan_handle_nonnull_return);
175
176 void __ubsan_handle_vla_bound_not_positive(struct vla_bound_data *data,
177- unsigned long bound)
178+ void *bound)
179 {
180 unsigned long flags;
181 char bound_str[VALUE_LENGTH];
182@@ -393,8 +391,7 @@ void __ubsan_handle_vla_bound_not_positi
183 }
184 EXPORT_SYMBOL(__ubsan_handle_vla_bound_not_positive);
185
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)
189 {
190 unsigned long flags;
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);
194
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)
198 {
199 unsigned long flags;
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);
203
204 void __ubsan_handle_load_invalid_value(struct invalid_value_data *data,
205- unsigned long val)
206+ void *val)
207 {
208 unsigned long flags;
209 char val_str[VALUE_LENGTH];