Skip to content

Commit ef06565

Browse files
keestorvalds
authored andcommitted
ubsan: include bug type in report header
When syzbot tries to figure out how to deduplicate bug reports, it prefers seeing a hint about a specific bug type (we can do better than just "UBSAN"). This lifts the handler reason into the UBSAN report line that includes the file path that tripped a check. Unfortunately, UBSAN does not provide function names. Suggested-by: Dmitry Vyukov <[email protected]> Signed-off-by: Kees Cook <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Cc: Alexander Potapenko <[email protected]> Cc: Andrey Konovalov <[email protected]> Cc: Andrey Ryabinin <[email protected]> Cc: Ard Biesheuvel <[email protected]> Cc: Arnd Bergmann <[email protected]> Cc: Dan Carpenter <[email protected]> Cc: Elena Petrova <[email protected]> Cc: "Gustavo A. R. Silva" <[email protected]> Link: http://lkml.kernel.org/r/[email protected] Link: https://lore.kernel.org/lkml/CACT4Y+bsLJ-wFx_TaXqax3JByUOWB3uk787LsyMVcfW6JzzGvg@mail.gmail.com Signed-off-by: Linus Torvalds <[email protected]>
1 parent 1d2252f commit ef06565

File tree

1 file changed

+15
-21
lines changed

1 file changed

+15
-21
lines changed

lib/ubsan.c

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,6 @@ static bool was_reported(struct source_location *location)
4545
return test_and_set_bit(REPORTED_BIT, &location->reported);
4646
}
4747

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-
5548
static bool suppress_report(struct source_location *loc)
5649
{
5750
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,
140133
}
141134
}
142135

143-
static void ubsan_prologue(struct source_location *location)
136+
static void ubsan_prologue(struct source_location *loc, const char *reason)
144137
{
145138
current->in_ubsan++;
146139

147140
pr_err("========================================"
148141
"========================================\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);
150144
}
151145

152146
static void ubsan_epilogue(void)
@@ -180,12 +174,12 @@ static void handle_overflow(struct overflow_data *data, void *lhs,
180174
if (suppress_report(&data->location))
181175
return;
182176

183-
ubsan_prologue(&data->location);
177+
ubsan_prologue(&data->location, type_is_signed(type) ?
178+
"signed-integer-overflow" :
179+
"unsigned-integer-overflow");
184180

185181
val_to_string(lhs_val_str, sizeof(lhs_val_str), type, lhs);
186182
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");
189183
pr_err("%s %c %s cannot be represented in type %s\n",
190184
lhs_val_str,
191185
op,
@@ -225,7 +219,7 @@ void __ubsan_handle_negate_overflow(struct overflow_data *data,
225219
if (suppress_report(&data->location))
226220
return;
227221

228-
ubsan_prologue(&data->location);
222+
ubsan_prologue(&data->location, "negation-overflow");
229223

230224
val_to_string(old_val_str, sizeof(old_val_str), data->type, old_val);
231225

@@ -245,7 +239,7 @@ void __ubsan_handle_divrem_overflow(struct overflow_data *data,
245239
if (suppress_report(&data->location))
246240
return;
247241

248-
ubsan_prologue(&data->location);
242+
ubsan_prologue(&data->location, "division-overflow");
249243

250244
val_to_string(rhs_val_str, sizeof(rhs_val_str), data->type, rhs);
251245

@@ -264,7 +258,7 @@ static void handle_null_ptr_deref(struct type_mismatch_data_common *data)
264258
if (suppress_report(data->location))
265259
return;
266260

267-
ubsan_prologue(data->location);
261+
ubsan_prologue(data->location, "null-ptr-deref");
268262

269263
pr_err("%s null pointer of type %s\n",
270264
type_check_kinds[data->type_check_kind],
@@ -279,7 +273,7 @@ static void handle_misaligned_access(struct type_mismatch_data_common *data,
279273
if (suppress_report(data->location))
280274
return;
281275

282-
ubsan_prologue(data->location);
276+
ubsan_prologue(data->location, "misaligned-access");
283277

284278
pr_err("%s misaligned address %p for type %s\n",
285279
type_check_kinds[data->type_check_kind],
@@ -295,7 +289,7 @@ static void handle_object_size_mismatch(struct type_mismatch_data_common *data,
295289
if (suppress_report(data->location))
296290
return;
297291

298-
ubsan_prologue(data->location);
292+
ubsan_prologue(data->location, "object-size-mismatch");
299293
pr_err("%s address %p with insufficient space\n",
300294
type_check_kinds[data->type_check_kind],
301295
(void *) ptr);
@@ -354,7 +348,7 @@ void __ubsan_handle_out_of_bounds(struct out_of_bounds_data *data, void *index)
354348
if (suppress_report(&data->location))
355349
return;
356350

357-
ubsan_prologue(&data->location);
351+
ubsan_prologue(&data->location, "array-index-out-of-bounds");
358352

359353
val_to_string(index_str, sizeof(index_str), data->index_type, index);
360354
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,
375369
if (suppress_report(&data->location))
376370
goto out;
377371

378-
ubsan_prologue(&data->location);
372+
ubsan_prologue(&data->location, "shift-out-of-bounds");
379373

380374
val_to_string(rhs_str, sizeof(rhs_str), rhs_type, rhs);
381375
val_to_string(lhs_str, sizeof(lhs_str), lhs_type, lhs);
@@ -407,7 +401,7 @@ EXPORT_SYMBOL(__ubsan_handle_shift_out_of_bounds);
407401

408402
void __ubsan_handle_builtin_unreachable(struct unreachable_data *data)
409403
{
410-
ubsan_prologue(&data->location);
404+
ubsan_prologue(&data->location, "unreachable");
411405
pr_err("calling __builtin_unreachable()\n");
412406
ubsan_epilogue();
413407
panic("can't return from __builtin_unreachable()");
@@ -422,7 +416,7 @@ void __ubsan_handle_load_invalid_value(struct invalid_value_data *data,
422416
if (suppress_report(&data->location))
423417
return;
424418

425-
ubsan_prologue(&data->location);
419+
ubsan_prologue(&data->location, "invalid-load");
426420

427421
val_to_string(val_str, sizeof(val_str), data->type, val);
428422

0 commit comments

Comments
 (0)