Re: [PATCH] refcount: Annotated intentional signed integer wrap-around

From: Miguel Ojeda
Date: Wed Feb 21 2024 - 05:30:55 EST


On Wed, Feb 21, 2024 at 6:16 AM Kees Cook <keescook@xxxxxxxxxxxx> wrote:
>
> 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'
>
> Signed-off-by: Kees Cook <keescook@xxxxxxxxxxxx>

Not sure why I am the "To:" (i.e. even if it is a change involving
only an addition of an attribute), but it looks good to me (UBSan is
triggering on the few `old + i`s caused by the calls from
`drivers/misc/lkdtm/refcount.c`, right?):

Reviewed-by: Miguel Ojeda <ojeda@xxxxxxxxxx>

As usual, thanks Kees for keeping up on getting the kernel (un)signed
UBSan-clean :)

Cheers,
Miguel