.. | .. |
---|
143 | 143 | } |
---|
144 | 144 | } |
---|
145 | 145 | |
---|
146 | | -static DEFINE_SPINLOCK(report_lock); |
---|
147 | | - |
---|
148 | | -static void ubsan_prologue(struct source_location *location, |
---|
149 | | - unsigned long *flags) |
---|
| 146 | +static void ubsan_prologue(struct source_location *location) |
---|
150 | 147 | { |
---|
151 | 148 | current->in_ubsan++; |
---|
152 | | - spin_lock_irqsave(&report_lock, *flags); |
---|
153 | 149 | |
---|
154 | 150 | pr_err("========================================" |
---|
155 | 151 | "========================================\n"); |
---|
156 | 152 | print_source_location("UBSAN: Undefined behaviour in", location); |
---|
157 | 153 | } |
---|
158 | 154 | |
---|
159 | | -static void ubsan_epilogue(unsigned long *flags) |
---|
| 155 | +static void ubsan_epilogue(void) |
---|
160 | 156 | { |
---|
161 | 157 | dump_stack(); |
---|
162 | 158 | pr_err("========================================" |
---|
163 | 159 | "========================================\n"); |
---|
164 | | - spin_unlock_irqrestore(&report_lock, *flags); |
---|
| 160 | + |
---|
165 | 161 | current->in_ubsan--; |
---|
166 | 162 | } |
---|
167 | 163 | |
---|
.. | .. |
---|
170 | 166 | { |
---|
171 | 167 | |
---|
172 | 168 | struct type_descriptor *type = data->type; |
---|
173 | | - unsigned long flags; |
---|
174 | 169 | char lhs_val_str[VALUE_LENGTH]; |
---|
175 | 170 | char rhs_val_str[VALUE_LENGTH]; |
---|
176 | 171 | |
---|
177 | 172 | if (suppress_report(&data->location)) |
---|
178 | 173 | return; |
---|
179 | 174 | |
---|
180 | | - ubsan_prologue(&data->location, &flags); |
---|
| 175 | + ubsan_prologue(&data->location); |
---|
181 | 176 | |
---|
182 | 177 | val_to_string(lhs_val_str, sizeof(lhs_val_str), type, lhs); |
---|
183 | 178 | val_to_string(rhs_val_str, sizeof(rhs_val_str), type, rhs); |
---|
.. | .. |
---|
189 | 184 | rhs_val_str, |
---|
190 | 185 | type->type_name); |
---|
191 | 186 | |
---|
192 | | - ubsan_epilogue(&flags); |
---|
| 187 | + ubsan_epilogue(); |
---|
193 | 188 | } |
---|
194 | 189 | |
---|
195 | 190 | void __ubsan_handle_add_overflow(struct overflow_data *data, |
---|
.. | .. |
---|
217 | 212 | void __ubsan_handle_negate_overflow(struct overflow_data *data, |
---|
218 | 213 | void *old_val) |
---|
219 | 214 | { |
---|
220 | | - unsigned long flags; |
---|
221 | 215 | char old_val_str[VALUE_LENGTH]; |
---|
222 | 216 | |
---|
223 | 217 | if (suppress_report(&data->location)) |
---|
224 | 218 | return; |
---|
225 | 219 | |
---|
226 | | - ubsan_prologue(&data->location, &flags); |
---|
| 220 | + ubsan_prologue(&data->location); |
---|
227 | 221 | |
---|
228 | 222 | val_to_string(old_val_str, sizeof(old_val_str), data->type, old_val); |
---|
229 | 223 | |
---|
230 | 224 | pr_err("negation of %s cannot be represented in type %s:\n", |
---|
231 | 225 | old_val_str, data->type->type_name); |
---|
232 | 226 | |
---|
233 | | - ubsan_epilogue(&flags); |
---|
| 227 | + ubsan_epilogue(); |
---|
234 | 228 | } |
---|
235 | 229 | EXPORT_SYMBOL(__ubsan_handle_negate_overflow); |
---|
236 | 230 | |
---|
.. | .. |
---|
238 | 232 | void __ubsan_handle_divrem_overflow(struct overflow_data *data, |
---|
239 | 233 | void *lhs, void *rhs) |
---|
240 | 234 | { |
---|
241 | | - unsigned long flags; |
---|
242 | 235 | char rhs_val_str[VALUE_LENGTH]; |
---|
243 | 236 | |
---|
244 | 237 | if (suppress_report(&data->location)) |
---|
245 | 238 | return; |
---|
246 | 239 | |
---|
247 | | - ubsan_prologue(&data->location, &flags); |
---|
| 240 | + ubsan_prologue(&data->location); |
---|
248 | 241 | |
---|
249 | 242 | val_to_string(rhs_val_str, sizeof(rhs_val_str), data->type, rhs); |
---|
250 | 243 | |
---|
.. | .. |
---|
254 | 247 | else |
---|
255 | 248 | pr_err("division by zero\n"); |
---|
256 | 249 | |
---|
257 | | - ubsan_epilogue(&flags); |
---|
| 250 | + ubsan_epilogue(); |
---|
258 | 251 | } |
---|
259 | 252 | EXPORT_SYMBOL(__ubsan_handle_divrem_overflow); |
---|
260 | 253 | |
---|
261 | 254 | static void handle_null_ptr_deref(struct type_mismatch_data_common *data) |
---|
262 | 255 | { |
---|
263 | | - unsigned long flags; |
---|
264 | | - |
---|
265 | 256 | if (suppress_report(data->location)) |
---|
266 | 257 | return; |
---|
267 | 258 | |
---|
268 | | - ubsan_prologue(data->location, &flags); |
---|
| 259 | + ubsan_prologue(data->location); |
---|
269 | 260 | |
---|
270 | 261 | pr_err("%s null pointer of type %s\n", |
---|
271 | 262 | type_check_kinds[data->type_check_kind], |
---|
272 | 263 | data->type->type_name); |
---|
273 | 264 | |
---|
274 | | - ubsan_epilogue(&flags); |
---|
| 265 | + ubsan_epilogue(); |
---|
275 | 266 | } |
---|
276 | 267 | |
---|
277 | 268 | static void handle_misaligned_access(struct type_mismatch_data_common *data, |
---|
278 | 269 | unsigned long ptr) |
---|
279 | 270 | { |
---|
280 | | - unsigned long flags; |
---|
281 | | - |
---|
282 | 271 | if (suppress_report(data->location)) |
---|
283 | 272 | return; |
---|
284 | 273 | |
---|
285 | | - ubsan_prologue(data->location, &flags); |
---|
| 274 | + ubsan_prologue(data->location); |
---|
286 | 275 | |
---|
287 | 276 | pr_err("%s misaligned address %p for type %s\n", |
---|
288 | 277 | type_check_kinds[data->type_check_kind], |
---|
289 | 278 | (void *)ptr, data->type->type_name); |
---|
290 | 279 | pr_err("which requires %ld byte alignment\n", data->alignment); |
---|
291 | 280 | |
---|
292 | | - ubsan_epilogue(&flags); |
---|
| 281 | + ubsan_epilogue(); |
---|
293 | 282 | } |
---|
294 | 283 | |
---|
295 | 284 | static void handle_object_size_mismatch(struct type_mismatch_data_common *data, |
---|
296 | 285 | unsigned long ptr) |
---|
297 | 286 | { |
---|
298 | | - unsigned long flags; |
---|
299 | | - |
---|
300 | 287 | if (suppress_report(data->location)) |
---|
301 | 288 | return; |
---|
302 | 289 | |
---|
303 | | - ubsan_prologue(data->location, &flags); |
---|
| 290 | + ubsan_prologue(data->location); |
---|
304 | 291 | pr_err("%s address %p with insufficient space\n", |
---|
305 | 292 | type_check_kinds[data->type_check_kind], |
---|
306 | 293 | (void *) ptr); |
---|
307 | 294 | pr_err("for an object of type %s\n", data->type->type_name); |
---|
308 | | - ubsan_epilogue(&flags); |
---|
| 295 | + ubsan_epilogue(); |
---|
309 | 296 | } |
---|
310 | 297 | |
---|
311 | 298 | static void ubsan_type_mismatch_common(struct type_mismatch_data_common *data, |
---|
.. | .. |
---|
352 | 339 | void __ubsan_handle_vla_bound_not_positive(struct vla_bound_data *data, |
---|
353 | 340 | void *bound) |
---|
354 | 341 | { |
---|
355 | | - unsigned long flags; |
---|
356 | 342 | char bound_str[VALUE_LENGTH]; |
---|
357 | 343 | |
---|
358 | 344 | if (suppress_report(&data->location)) |
---|
359 | 345 | return; |
---|
360 | 346 | |
---|
361 | | - ubsan_prologue(&data->location, &flags); |
---|
| 347 | + ubsan_prologue(&data->location); |
---|
362 | 348 | |
---|
363 | 349 | val_to_string(bound_str, sizeof(bound_str), data->type, bound); |
---|
364 | 350 | pr_err("variable length array bound value %s <= 0\n", bound_str); |
---|
365 | 351 | |
---|
366 | | - ubsan_epilogue(&flags); |
---|
| 352 | + ubsan_epilogue(); |
---|
367 | 353 | } |
---|
368 | 354 | EXPORT_SYMBOL(__ubsan_handle_vla_bound_not_positive); |
---|
369 | 355 | |
---|
370 | 356 | void __ubsan_handle_out_of_bounds(struct out_of_bounds_data *data, void *index) |
---|
371 | 357 | { |
---|
372 | | - unsigned long flags; |
---|
373 | 358 | char index_str[VALUE_LENGTH]; |
---|
374 | 359 | |
---|
375 | 360 | if (suppress_report(&data->location)) |
---|
376 | 361 | return; |
---|
377 | 362 | |
---|
378 | | - ubsan_prologue(&data->location, &flags); |
---|
| 363 | + ubsan_prologue(&data->location); |
---|
379 | 364 | |
---|
380 | 365 | val_to_string(index_str, sizeof(index_str), data->index_type, index); |
---|
381 | 366 | pr_err("index %s is out of range for type %s\n", index_str, |
---|
382 | 367 | data->array_type->type_name); |
---|
383 | | - ubsan_epilogue(&flags); |
---|
| 368 | + ubsan_epilogue(); |
---|
384 | 369 | } |
---|
385 | 370 | EXPORT_SYMBOL(__ubsan_handle_out_of_bounds); |
---|
386 | 371 | |
---|
387 | 372 | void __ubsan_handle_shift_out_of_bounds(struct shift_out_of_bounds_data *data, |
---|
388 | 373 | void *lhs, void *rhs) |
---|
389 | 374 | { |
---|
390 | | - unsigned long flags; |
---|
391 | 375 | struct type_descriptor *rhs_type = data->rhs_type; |
---|
392 | 376 | struct type_descriptor *lhs_type = data->lhs_type; |
---|
393 | 377 | char rhs_str[VALUE_LENGTH]; |
---|
.. | .. |
---|
396 | 380 | if (suppress_report(&data->location)) |
---|
397 | 381 | return; |
---|
398 | 382 | |
---|
399 | | - ubsan_prologue(&data->location, &flags); |
---|
| 383 | + ubsan_prologue(&data->location); |
---|
400 | 384 | |
---|
401 | 385 | val_to_string(rhs_str, sizeof(rhs_str), rhs_type, rhs); |
---|
402 | 386 | val_to_string(lhs_str, sizeof(lhs_str), lhs_type, lhs); |
---|
.. | .. |
---|
419 | 403 | lhs_str, rhs_str, |
---|
420 | 404 | lhs_type->type_name); |
---|
421 | 405 | |
---|
422 | | - ubsan_epilogue(&flags); |
---|
| 406 | + ubsan_epilogue(); |
---|
423 | 407 | } |
---|
424 | 408 | EXPORT_SYMBOL(__ubsan_handle_shift_out_of_bounds); |
---|
425 | 409 | |
---|
426 | 410 | |
---|
427 | 411 | void __ubsan_handle_builtin_unreachable(struct unreachable_data *data) |
---|
428 | 412 | { |
---|
429 | | - unsigned long flags; |
---|
430 | | - |
---|
431 | | - ubsan_prologue(&data->location, &flags); |
---|
| 413 | + ubsan_prologue(&data->location); |
---|
432 | 414 | pr_err("calling __builtin_unreachable()\n"); |
---|
433 | | - ubsan_epilogue(&flags); |
---|
| 415 | + ubsan_epilogue(); |
---|
434 | 416 | panic("can't return from __builtin_unreachable()"); |
---|
435 | 417 | } |
---|
436 | 418 | EXPORT_SYMBOL(__ubsan_handle_builtin_unreachable); |
---|
.. | .. |
---|
438 | 420 | void __ubsan_handle_load_invalid_value(struct invalid_value_data *data, |
---|
439 | 421 | void *val) |
---|
440 | 422 | { |
---|
441 | | - unsigned long flags; |
---|
442 | 423 | char val_str[VALUE_LENGTH]; |
---|
443 | 424 | |
---|
444 | 425 | if (suppress_report(&data->location)) |
---|
445 | 426 | return; |
---|
446 | 427 | |
---|
447 | | - ubsan_prologue(&data->location, &flags); |
---|
| 428 | + ubsan_prologue(&data->location); |
---|
448 | 429 | |
---|
449 | 430 | val_to_string(val_str, sizeof(val_str), data->type, val); |
---|
450 | 431 | |
---|
451 | 432 | pr_err("load of value %s is not a valid value for type %s\n", |
---|
452 | 433 | val_str, data->type->type_name); |
---|
453 | 434 | |
---|
454 | | - ubsan_epilogue(&flags); |
---|
| 435 | + ubsan_epilogue(); |
---|
455 | 436 | } |
---|
456 | 437 | EXPORT_SYMBOL(__ubsan_handle_load_invalid_value); |
---|