All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Thorsten Blum <thorsten.blum@toblux.com>
Cc: kees@kernel.org, gustavoars@kernel.org, mcgrof@kernel.org,
	linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org
Subject: Re: [PATCH] params: Annotate struct module_param_attrs with __counted_by()
Date: Fri, 23 Aug 2024 16:40:26 +0300	[thread overview]
Message-ID: <ZsiRSq_fgrnKcQPi@smile.fi.intel.com> (raw)
In-Reply-To: <20240823123300.37574-1-thorsten.blum@toblux.com>

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



      reply	other threads:[~2024-08-23 13:40 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-23 12:33 [PATCH] params: Annotate struct module_param_attrs with __counted_by() Thorsten Blum
2024-08-23 13:40 ` Andy Shevchenko [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZsiRSq_fgrnKcQPi@smile.fi.intel.com \
    --to=andriy.shevchenko@linux.intel.com \
    --cc=gustavoars@kernel.org \
    --cc=kees@kernel.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mcgrof@kernel.org \
    --cc=thorsten.blum@toblux.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.