Skip to content
Commit f8d0a22b authored by Kees Cook's avatar Kees Cook Committed by Andrew Morton
Browse files

ubsan: reintroduce signed overflow sanitizer

In order to mitigate unexpected signed wrap-around[1], bring back the
signed integer overflow sanitizer.  It was removed in commit 6aaa31ae
("ubsan: remove overflow checks") because it was effectively a no-op when
combined with -fno-strict-overflow (which correctly changes signed
overflow from being "undefined" to being explicitly "wrap around").

Compilers are adjusting their sanitizers to trap wrap-around and to
detecting common code patterns that should not be instrumented (e.g.  "var
+ offset < var").  Prepare for this and explicitly rename the option from
"OVERFLOW" to "WRAP".

To annotate intentional wrap-around arithmetic, the add/sub/mul_wrap()
helpers can be used for individual statements.  At the function level, the
__signed_wrap attribute can be used to mark an entire function as
expecting its signed arithmetic to wrap around.  For a single object file
the Makefile can use "UBSAN_WRAP_SIGNED_target.o := n" to mark it as
wrapping, and for an entire directory, "UBSAN_WRAP_SIGNED := n" can be
used.

Additionally keep these disabled under CONFIG_COMPILE_TEST for now.

Link: https://github.com/KSPP/linux/issues/26 [1]
Link: https://lkml.kernel.org/r/20240205093725.make.582-kees@kernel.org


Signed-off-by: default avatarKees Cook <keescook@chromium.org>
Reviewed-by: default avatarMarco Elver <elver@google.com>
Cc: Justin Stitt <justinstitt@google.com>
Cc: Miguel Ojeda <ojeda@kernel.org>
Cc: Nathan Chancellor <nathan@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Hao Luo <haoluo@google.com>
Cc: Andrey Konovalov <andreyknvl@gmail.com>
Cc: Andrey Ryabinin <ryabinin.a.a@gmail.com>
Cc: Masahiro Yamada <masahiroy@kernel.org>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Nicolas Schier <nicolas@fjasle.eu>
Cc: Przemek Kitszel <przemyslaw.kitszel@intel.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
parent 28996b4f
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment