refcount: Annotated intentional signed integer wrap-around
authorKees Cook <keescook@chromium.org>
Wed, 21 Feb 2024 05:16:38 +0000 (21:16 -0800)
committerKees Cook <keescook@chromium.org>
Thu, 29 Feb 2024 21:38:02 +0000 (13:38 -0800)
commit99db710f768e988e70f1164537bf533a017be24d
tree385cf2015d588e9cde29d887463f989c553cf2bb
parente7549481255167dcdab355c539562c7ace17e111
refcount: Annotated intentional signed integer wrap-around

Mark the various refcount_t functions with __signed_wrap, as we depend
on the wrapping behavior to detect the overflow and perform saturation.
Silences warnings seen with the LKDTM REFCOUNT_* tests:

  UBSAN: signed-integer-overflow in ../include/linux/refcount.h:189:11
  2147483647 + 1 cannot be represented in type 'int'

Reviewed-by: Miguel Ojeda <ojeda@kernel.org>
Link: https://lore.kernel.org/r/20240221051634.work.287-kees@kernel.org
Signed-off-by: Kees Cook <keescook@chromium.org>
include/linux/refcount.h