Skip to content

Commit 272a767

Browse files
committed
ubsan/overflow: Enable pattern exclusions
To make integer wrap-around mitigation actually useful, the associated sanitizers must not instrument cases where the wrap-around is explicitly defined (e.g. "-2UL"), being tested for (e.g. "if (a + b < a)"), or where it has no impact on code flow (e.g. "while (var--)"). Enable pattern exclusions for the integer wrap sanitizers. Reviewed-by: Justin Stitt <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Kees Cook <[email protected]>
1 parent ed2b548 commit 272a767

File tree

2 files changed

+2
-0
lines changed

2 files changed

+2
-0
lines changed

lib/Kconfig.ubsan

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ config UBSAN_INTEGER_WRAP
120120
bool "Perform checking for integer arithmetic wrap-around"
121121
default UBSAN
122122
depends on !COMPILE_TEST
123+
depends on $(cc-option,-fsanitize-undefined-ignore-overflow-pattern=all)
123124
depends on $(cc-option,-fsanitize=signed-integer-overflow)
124125
depends on $(cc-option,-fsanitize=unsigned-integer-overflow)
125126
depends on $(cc-option,-fsanitize=implicit-signed-integer-truncation)

scripts/Makefile.ubsan

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ ubsan-cflags-$(CONFIG_UBSAN_TRAP) += $(call cc-option,-fsanitize-trap=undefined
1515
export CFLAGS_UBSAN := $(ubsan-cflags-y)
1616

1717
ubsan-integer-wrap-cflags-$(CONFIG_UBSAN_INTEGER_WRAP) += \
18+
-fsanitize-undefined-ignore-overflow-pattern=all \
1819
-fsanitize=signed-integer-overflow \
1920
-fsanitize=unsigned-integer-overflow \
2021
-fsanitize=implicit-signed-integer-truncation \

0 commit comments

Comments
 (0)