linux-hardening.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Baolin Wang <baolin.wang7@gmail.com>
To: "Gustavo A. R. Silva" <gustavoars@kernel.org>
Cc: Ohad Ben-Cohen <ohad@wizery.com>,
	Bjorn Andersson <bjorn.andersson@linaro.org>,
	Orson Zhai <orsonzhai@gmail.com>,
	Chunyan Zhang <zhang.lyra@gmail.com>,
	linux-remoteproc@vger.kernel.org,
	LKML <linux-kernel@vger.kernel.org>,
	linux-hardening@vger.kernel.org
Subject: Re: [PATCH][next] hwspinlock: sprd: Use struct_size() helper in devm_kzalloc()
Date: Wed, 26 Jan 2022 11:31:23 +0800	[thread overview]
Message-ID: <CADBw62qd45fuER5oXKoDPwKbOOvwba9ek0Oz+AxtGrF0OL_64A@mail.gmail.com> (raw)
In-Reply-To: <20220125225723.GA78256@embeddedor>

On Wed, Jan 26, 2022 at 6:50 AM Gustavo A. R. Silva
<gustavoars@kernel.org> wrote:
>
> Make use of the struct_size() helper instead of an open-coded version,
> in order to avoid any potential type mistakes or integer overflows that,
> in the worst scenario, could lead to heap overflows.
>
> Also, address the following sparse warnings:
> drivers/hwspinlock/sprd_hwspinlock.c:96:36: warning: using sizeof on a flexible structure
>
> Link: https://github.com/KSPP/linux/issues/174
> Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>

LGTM.
Reviewed-by: Baolin Wang <baolin.wang7@gmail.com>

> ---
>  drivers/hwspinlock/sprd_hwspinlock.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/drivers/hwspinlock/sprd_hwspinlock.c b/drivers/hwspinlock/sprd_hwspinlock.c
> index d221fc9d756d..22e2ffb91743 100644
> --- a/drivers/hwspinlock/sprd_hwspinlock.c
> +++ b/drivers/hwspinlock/sprd_hwspinlock.c
> @@ -93,8 +93,7 @@ static int sprd_hwspinlock_probe(struct platform_device *pdev)
>                 return -ENODEV;
>
>         sprd_hwlock = devm_kzalloc(&pdev->dev,
> -                                  sizeof(struct sprd_hwspinlock_dev) +
> -                                  SPRD_HWLOCKS_NUM * sizeof(*lock),
> +                                  struct_size(sprd_hwlock, bank.lock, SPRD_HWLOCKS_NUM),
>                                    GFP_KERNEL);
>         if (!sprd_hwlock)
>                 return -ENOMEM;
> --
> 2.27.0
>


-- 
Baolin Wang

      reply	other threads:[~2022-01-26  3:30 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-25 22:57 [PATCH][next] hwspinlock: sprd: Use struct_size() helper in devm_kzalloc() Gustavo A. R. Silva
2022-01-26  3:31 ` Baolin Wang [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=CADBw62qd45fuER5oXKoDPwKbOOvwba9ek0Oz+AxtGrF0OL_64A@mail.gmail.com \
    --to=baolin.wang7@gmail.com \
    --cc=bjorn.andersson@linaro.org \
    --cc=gustavoars@kernel.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-remoteproc@vger.kernel.org \
    --cc=ohad@wizery.com \
    --cc=orsonzhai@gmail.com \
    --cc=zhang.lyra@gmail.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).