public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Kees Cook <keescook@chromium.org>
To: "Gustavo A. R. Silva" <gustavoars@kernel.org>
Cc: "Geoffrey D. Bennett" <g@b4.vu>, Jaroslav Kysela <perex@perex.cz>,
	Takashi Iwai <tiwai@suse.com>,
	alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org,
	linux-hardening@vger.kernel.org
Subject: Re: [PATCH v2][next] ALSA: usb-audio: scarlett2: Use struct_size() helper in scarlett2_usb()
Date: Thu, 20 Jan 2022 15:22:11 -0800	[thread overview]
Message-ID: <202201201522.5E744C15E9@keescook> (raw)
In-Reply-To: <20220120211600.GA28841@embeddedor>

On Thu, Jan 20, 2022 at 03:16:00PM -0600, Gustavo A. R. Silva 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:
> sound/usb/mixer_scarlett_gen2.c:1064:28: warning: using sizeof on a flexible structure
> sound/usb/mixer_scarlett_gen2.c:1065:29: 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>

Looks good to me!

Reviewed-by: Kees Cook <keescook@chromium.org>

> ---
> Changes in v2:
>  - Use correct format specifier %zu for type size_t argument.
> 
>  sound/usb/mixer_scarlett_gen2.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/sound/usb/mixer_scarlett_gen2.c b/sound/usb/mixer_scarlett_gen2.c
> index 53ebabf42472..7ff8a4817c67 100644
> --- a/sound/usb/mixer_scarlett_gen2.c
> +++ b/sound/usb/mixer_scarlett_gen2.c
> @@ -1061,9 +1061,9 @@ static int scarlett2_usb(
>  {
>  	struct scarlett2_data *private = mixer->private_data;
>  	struct usb_device *dev = mixer->chip->dev;
> -	u16 req_buf_size = sizeof(struct scarlett2_usb_packet) + req_size;
> -	u16 resp_buf_size = sizeof(struct scarlett2_usb_packet) + resp_size;
>  	struct scarlett2_usb_packet *req, *resp = NULL;
> +	size_t req_buf_size = struct_size(req, data, req_size);
> +	size_t resp_buf_size = struct_size(resp, data, resp_size);
>  	int err;
>  
>  	req = kmalloc(req_buf_size, GFP_KERNEL);
> @@ -1111,7 +1111,7 @@ static int scarlett2_usb(
>  		usb_audio_err(
>  			mixer->chip,
>  			"Scarlett Gen 2/3 USB response result cmd %x was %d "
> -			"expected %d\n",
> +			"expected %zu\n",
>  			cmd, err, resp_buf_size);
>  		err = -EINVAL;
>  		goto unlock;
> -- 
> 2.27.0
> 

-- 
Kees Cook

  reply	other threads:[~2022-01-20 23:22 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-20 21:16 [PATCH v2][next] ALSA: usb-audio: scarlett2: Use struct_size() helper in scarlett2_usb() Gustavo A. R. Silva
2022-01-20 23:22 ` Kees Cook [this message]
2022-01-25 14:11 ` Takashi Iwai

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=202201201522.5E744C15E9@keescook \
    --to=keescook@chromium.org \
    --cc=alsa-devel@alsa-project.org \
    --cc=g@b4.vu \
    --cc=gustavoars@kernel.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=perex@perex.cz \
    --cc=tiwai@suse.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