On Fri, Aug 23, 2024 at 02:33:00PM +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 krealloc() 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.
... > /* Extra pointer for NULL terminator */ > new_attrs = krealloc(mk->mp->grp.attrs, > - sizeof(mk->mp->grp.attrs[0]) * (mk->mp->num + 2), > + sizeof(mk->mp->grp.attrs[0]) * (mk->mp->num + 1), > GFP_KERNEL); Convert this to use krealloc_array(). > if (!new_attrs) > return -ENOMEM; -- With Best Regards, Andy Shevchenko
