Skip to content

Commit f4626c1

Browse files
committed
ubsan: Add awareness of signed integer overflow traps
On arm64, UBSAN traps can be decoded from the trap instruction. Add the add, sub, and mul overflow trap codes now that CONFIG_UBSAN_SIGNED_WRAP exists. Seen under clang 19: Internal error: UBSAN: unrecognized failure code: 00000000f2005515 [#1] PREEMPT SMP Reported-by: Nathan Chancellor <nathan@kernel.org> Closes: https://lore.kernel.org/lkml/20240411-fix-ubsan-in-hardening-config-v1-0-e0177c80ffaa@kernel.org Fixes: 557f8c5 ("ubsan: Reintroduce signed overflow sanitizer") Tested-by: Nathan Chancellor <nathan@kernel.org> Link: https://lore.kernel.org/r/20240415182832.work.932-kees@kernel.org Signed-off-by: Kees Cook <keescook@chromium.org>
1 parent 7fcb91d commit f4626c1

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

lib/ubsan.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,10 @@ const char *report_ubsan_failure(struct pt_regs *regs, u32 check_type)
4444
case ubsan_shift_out_of_bounds:
4545
return "UBSAN: shift out of bounds";
4646
#endif
47-
#ifdef CONFIG_UBSAN_DIV_ZERO
47+
#if defined(CONFIG_UBSAN_DIV_ZERO) || defined(CONFIG_UBSAN_SIGNED_WRAP)
4848
/*
49-
* SanitizerKind::IntegerDivideByZero emits
49+
* SanitizerKind::IntegerDivideByZero and
50+
* SanitizerKind::SignedIntegerOverflow emit
5051
* SanitizerHandler::DivremOverflow.
5152
*/
5253
case ubsan_divrem_overflow:
@@ -77,6 +78,19 @@ const char *report_ubsan_failure(struct pt_regs *regs, u32 check_type)
7778
return "UBSAN: alignment assumption";
7879
case ubsan_type_mismatch:
7980
return "UBSAN: type mismatch";
81+
#endif
82+
#ifdef CONFIG_UBSAN_SIGNED_WRAP
83+
/*
84+
* SanitizerKind::SignedIntegerOverflow emits
85+
* SanitizerHandler::AddOverflow, SanitizerHandler::SubOverflow,
86+
* or SanitizerHandler::MulOverflow.
87+
*/
88+
case ubsan_add_overflow:
89+
return "UBSAN: integer addition overflow";
90+
case ubsan_sub_overflow:
91+
return "UBSAN: integer subtraction overflow";
92+
case ubsan_mul_overflow:
93+
return "UBSAN: integer multiplication overflow";
8094
#endif
8195
default:
8296
return "UBSAN: unrecognized failure code";

0 commit comments

Comments
 (0)