@@ -45,13 +45,6 @@ static bool was_reported(struct source_location *location)
45
45
return test_and_set_bit (REPORTED_BIT , & location -> reported );
46
46
}
47
47
48
- static void print_source_location (const char * prefix ,
49
- struct source_location * loc )
50
- {
51
- pr_err ("%s %s:%d:%d\n" , prefix , loc -> file_name ,
52
- loc -> line & LINE_MASK , loc -> column & COLUMN_MASK );
53
- }
54
-
55
48
static bool suppress_report (struct source_location * loc )
56
49
{
57
50
return current -> in_ubsan || was_reported (loc );
@@ -140,13 +133,14 @@ static void val_to_string(char *str, size_t size, struct type_descriptor *type,
140
133
}
141
134
}
142
135
143
- static void ubsan_prologue (struct source_location * location )
136
+ static void ubsan_prologue (struct source_location * loc , const char * reason )
144
137
{
145
138
current -> in_ubsan ++ ;
146
139
147
140
pr_err ("========================================"
148
141
"========================================\n" );
149
- print_source_location ("UBSAN: Undefined behaviour in" , location );
142
+ pr_err ("UBSAN: %s in %s:%d:%d\n" , reason , loc -> file_name ,
143
+ loc -> line & LINE_MASK , loc -> column & COLUMN_MASK );
150
144
}
151
145
152
146
static void ubsan_epilogue (void )
@@ -180,12 +174,12 @@ static void handle_overflow(struct overflow_data *data, void *lhs,
180
174
if (suppress_report (& data -> location ))
181
175
return ;
182
176
183
- ubsan_prologue (& data -> location );
177
+ ubsan_prologue (& data -> location , type_is_signed (type ) ?
178
+ "signed-integer-overflow" :
179
+ "unsigned-integer-overflow" );
184
180
185
181
val_to_string (lhs_val_str , sizeof (lhs_val_str ), type , lhs );
186
182
val_to_string (rhs_val_str , sizeof (rhs_val_str ), type , rhs );
187
- pr_err ("%s integer overflow:\n" ,
188
- type_is_signed (type ) ? "signed" : "unsigned" );
189
183
pr_err ("%s %c %s cannot be represented in type %s\n" ,
190
184
lhs_val_str ,
191
185
op ,
@@ -225,7 +219,7 @@ void __ubsan_handle_negate_overflow(struct overflow_data *data,
225
219
if (suppress_report (& data -> location ))
226
220
return ;
227
221
228
- ubsan_prologue (& data -> location );
222
+ ubsan_prologue (& data -> location , "negation-overflow" );
229
223
230
224
val_to_string (old_val_str , sizeof (old_val_str ), data -> type , old_val );
231
225
@@ -245,7 +239,7 @@ void __ubsan_handle_divrem_overflow(struct overflow_data *data,
245
239
if (suppress_report (& data -> location ))
246
240
return ;
247
241
248
- ubsan_prologue (& data -> location );
242
+ ubsan_prologue (& data -> location , "division-overflow" );
249
243
250
244
val_to_string (rhs_val_str , sizeof (rhs_val_str ), data -> type , rhs );
251
245
@@ -264,7 +258,7 @@ static void handle_null_ptr_deref(struct type_mismatch_data_common *data)
264
258
if (suppress_report (data -> location ))
265
259
return ;
266
260
267
- ubsan_prologue (data -> location );
261
+ ubsan_prologue (data -> location , "null-ptr-deref" );
268
262
269
263
pr_err ("%s null pointer of type %s\n" ,
270
264
type_check_kinds [data -> type_check_kind ],
@@ -279,7 +273,7 @@ static void handle_misaligned_access(struct type_mismatch_data_common *data,
279
273
if (suppress_report (data -> location ))
280
274
return ;
281
275
282
- ubsan_prologue (data -> location );
276
+ ubsan_prologue (data -> location , "misaligned-access" );
283
277
284
278
pr_err ("%s misaligned address %p for type %s\n" ,
285
279
type_check_kinds [data -> type_check_kind ],
@@ -295,7 +289,7 @@ static void handle_object_size_mismatch(struct type_mismatch_data_common *data,
295
289
if (suppress_report (data -> location ))
296
290
return ;
297
291
298
- ubsan_prologue (data -> location );
292
+ ubsan_prologue (data -> location , "object-size-mismatch" );
299
293
pr_err ("%s address %p with insufficient space\n" ,
300
294
type_check_kinds [data -> type_check_kind ],
301
295
(void * ) ptr );
@@ -354,7 +348,7 @@ void __ubsan_handle_out_of_bounds(struct out_of_bounds_data *data, void *index)
354
348
if (suppress_report (& data -> location ))
355
349
return ;
356
350
357
- ubsan_prologue (& data -> location );
351
+ ubsan_prologue (& data -> location , "array-index-out-of-bounds" );
358
352
359
353
val_to_string (index_str , sizeof (index_str ), data -> index_type , index );
360
354
pr_err ("index %s is out of range for type %s\n" , index_str ,
@@ -375,7 +369,7 @@ void __ubsan_handle_shift_out_of_bounds(struct shift_out_of_bounds_data *data,
375
369
if (suppress_report (& data -> location ))
376
370
goto out ;
377
371
378
- ubsan_prologue (& data -> location );
372
+ ubsan_prologue (& data -> location , "shift-out-of-bounds" );
379
373
380
374
val_to_string (rhs_str , sizeof (rhs_str ), rhs_type , rhs );
381
375
val_to_string (lhs_str , sizeof (lhs_str ), lhs_type , lhs );
@@ -407,7 +401,7 @@ EXPORT_SYMBOL(__ubsan_handle_shift_out_of_bounds);
407
401
408
402
void __ubsan_handle_builtin_unreachable (struct unreachable_data * data )
409
403
{
410
- ubsan_prologue (& data -> location );
404
+ ubsan_prologue (& data -> location , "unreachable" );
411
405
pr_err ("calling __builtin_unreachable()\n" );
412
406
ubsan_epilogue ();
413
407
panic ("can't return from __builtin_unreachable()" );
@@ -422,7 +416,7 @@ void __ubsan_handle_load_invalid_value(struct invalid_value_data *data,
422
416
if (suppress_report (& data -> location ))
423
417
return ;
424
418
425
- ubsan_prologue (& data -> location );
419
+ ubsan_prologue (& data -> location , "invalid-load" );
426
420
427
421
val_to_string (val_str , sizeof (val_str ), data -> type , val );
428
422
0 commit comments