overflow: Introduce wrapping_assign_add() and wrapping_assign_sub()
authorKees Cook <keescook@chromium.org>
Sat, 27 Jan 2024 06:09:50 +0000 (22:09 -0800)
committerKees Cook <keescook@chromium.org>
Thu, 29 Feb 2024 21:38:01 +0000 (13:38 -0800)
commit08d45ee84bb2650e237e150caca87cc4ded9b3e2
tree0f0474672597c717e276bcd41242f7d50535aa9c
parentd70de8054c58d7bd9a4654c9f4797d29fa46d545
overflow: Introduce wrapping_assign_add() and wrapping_assign_sub()

This allows replacements of the idioms "var += offset" and "var -=
offset" with the wrapping_assign_add() and wrapping_assign_sub() helpers
respectively. They will avoid wrap-around sanitizer instrumentation.

Add to the selftests to validate behavior and lack of side-effects.

Reviewed-by: Marco Elver <elver@google.com>
Acked-by: Mark Rutland <mark.rutland@arm.com>
Signed-off-by: Kees Cook <keescook@chromium.org>
include/linux/overflow.h
lib/overflow_kunit.c