Re: [RESEND PATCH v2] params: Annotate struct module_param_attrs with __counted_by()

From: Luis Chamberlain
Date: Thu Feb 13 2025 - 17:21:44 EST


On Thu, Feb 13, 2025 at 11:13:52PM +0100, Thorsten Blum wrote:
> Add the __counted_by compiler attribute to the flexible array member
> attrs to improve access bounds-checking via CONFIG_UBSAN_BOUNDS and
> CONFIG_FORTIFY_SOURCE.
>
> Increment num before adding a new param_attribute to the attrs array and
> adjust the array index accordingly. Increment num immediately after the
> first reallocation such that the reallocation for the NULL terminator
> only needs to add 1 (instead of 2) to mk->mp->num.
>
> Use struct_size() instead of manually calculating the size for the
> reallocation.
>
> Use krealloc_array() for the additional NULL terminator.
>
> Cc: Andy Shevchenko <andriy.shevchenko@xxxxxxxxxxxxxxx>
> Cc: Luis Chamberlain <mcgrof@xxxxxxxxxx>
> Cc: Nathan Chancellor <nathan@xxxxxxxxxx>
> Signed-off-by: Thorsten Blum <thorsten.blum@xxxxxxxxx>

Reviewed-by: Luis Chamberlain <mcgrof@xxxxxxxxxx>

Luis