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

From: Thorsten Blum
Date: Fri Sep 13 2024 - 15:03:30 EST


On 13. Sep 2024, at 20:40, Andy Shevchenko <andriy.shevchenko@xxxxxxxxxxxxxxx> wrote:
> On Fri, Sep 13, 2024 at 09:46:30AM -0700, Nathan Chancellor wrote:
>> On Mon, Sep 09, 2024 at 06:27:26PM +0200, 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.
>
>>> /* Fix up all the pointers, since krealloc can move us */
>>> for (i = 0; i < mk->mp->num; i++)
>
> Shouldn't this for loop and followed by assignment also be -1:ed?

That should be fine as mk->mp->num was already incremented before the
for-loop.