Re: [PATCH] string: Add additional __realloc_size() annotations for "dup" helpers

From: Andy Shevchenko
Date: Thu May 02 2024 - 05:46:20 EST


On Thu, May 2, 2024 at 2:32 AM Kees Cook <keescook@xxxxxxxxxxxx> wrote:
>
> Several other "dup"-style interfaces could use the __realloc_size()
> attribute. (As a reminder to myself and others: "realloc" is used here
> instead of "alloc" because the "alloc_size" attribute implies that the
> memory contents are uninitialized. Since we're copying contents into the
> resulting allocation, it must use "realloc_size" to avoid confusing the
> compiler's optimization passes.)
>
> Add KUnit test coverage where possible. (KUnit still does not have the
> ability to manipulate userspace memory.)

Makes sense to me,
Reviewed-by: Andy Shevchenko <andy@xxxxxxxxxx>

..

> + checker(len, kmemdup_array(test_phrases[idx], len, 1, \
> + gfp), kfree(p)); \

Despite being longer, I would put gfp on the previous line for the
sake of logical split (and additionally to be consistent with the
below).

> + checker(len, kmemdup(test_phrases[idx], len, gfp), \
> + kfree(p)); \

--
With Best Regards,
Andy Shevchenko