Skip to content

Commit

Permalink
ubsan: disable UBSAN_DIV_ZERO for clang
Browse files Browse the repository at this point in the history
Building with UBSAN_DIV_ZERO with clang produces numerous fallthrough
warnings from objtool.

In the case of uncheck division, UBSAN_DIV_ZERO may introduce new
control flow to check for division by zero.

Because the result of the division is undefined, LLVM may optimize the
control flow such that after the call to __ubsan_handle_divrem_overflow
doesn't matter.  If panic_on_warn was set,
__ubsan_handle_divrem_overflow would panic.

The problem is is that panic_on_warn is run time configurable.  If it's
disabled, then we cannot guarantee that we will be able to recover
safely.  Disable this config for clang until we can come up with a
solution in LLVM.

Link: ClangBuiltLinux/linux#1657
Link: llvm/llvm-project#56289
Link: https://lore.kernel.org/lkml/CAHk-=wj1qhf7y3VNACEexyp5EbkNpdcu_542k-xZpzmYLOjiCg@mail.gmail.com/
Reported-by: Sudip Mukherjee <sudipm.mukherjee@gmail.com>
Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
Change-Id: Ib148a383852bd6a0e9e2c8bafcd10961c37991dc
Acked-by: Nathan Chancellor <nathan@kernel.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

Signed-off-by: Alexander Winkowski <dereference23@outlook.com>
(cherry picked from commit 65b37d8468a4afffbef4ba91c5ae53d3d90e7911)
Signed-off-by: TogoFire <togofire@mailfence.com>
  • Loading branch information
nickdesaulniers authored and TogoFire committed Sep 24, 2024
1 parent cbabe00 commit 444aa57
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/Kconfig.ubsan
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ config UBSAN_SHIFT
config UBSAN_DIV_ZERO
bool "Perform checking for integer divide-by-zero"
depends on $(cc-option,-fsanitize=integer-divide-by-zero)
# https://github.com/ClangBuiltLinux/linux/issues/1657
# https://github.com/llvm/llvm-project/issues/56289
depends on !CC_IS_CLANG
help
This option enables -fsanitize=integer-divide-by-zero which checks
for integer division by zero. This is effectively redundant with the
Expand Down

0 comments on commit 444aa57

Please sign in to comment.