All of lore.kernel.org
 help / color / mirror / Atom feed
From: Clemens Ladisch <clemens@ladisch.de>
To: Arjun Sreedharan <arjun024@gmail.com>
Cc: gregkh@linuxfoundation.org, linux-usb@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] usb: use kcalloc instead of kzalloc
Date: Tue, 19 Aug 2014 12:56:57 +0200	[thread overview]
Message-ID: <53F32D79.8050401@ladisch.de> (raw)
In-Reply-To: <1408444681-1601-1-git-send-email-arjun024@gmail.com>

Arjun Sreedharan wrote:
> kcalloc has protection from integer overflows
> which could arise from the multiplication of
> number of elements and size.

You are implying that such an overflow could arise in this code.
This is false.

> @@ -380,8 +380,7 @@ static int usb_parse_interface(struct device *ddev, int cfgno,
>
>  	if (num_ep > 0) {
>  		/* Can't allocate 0 bytes */
> -		len = sizeof(struct usb_host_endpoint) * num_ep;
> -		alt->endpoint = kzalloc(len, GFP_KERNEL);
> +		alt->endpoint = kcalloc(num_ep, sizeof(struct usb_host_endpoint), GFP_KERNEL);

bNumEndpoints is an unsigned 8-bit integer.

And even if you did not notice this, you should have noticed the if()
directly before this one.

> @@ -683,13 +682,11 @@ int usb_get_configuration(struct usb_device *dev)
>  		return -EINVAL;
>  	}
>
> -	length = ncfg * sizeof(struct usb_host_config);
> -	dev->config = kzalloc(length, GFP_KERNEL);
> +	dev->config = kcalloc(ncfg, sizeof(struct usb_host_config), GFP_KERNEL);
>  	if (!dev->config)
>  		goto err2;
>
> -	length = ncfg * sizeof(char *);
> -	dev->rawdescriptors = kzalloc(length, GFP_KERNEL);
> +	dev->rawdescriptors = kcalloc(ncfg, sizeof(char *), GFP_KERNEL);

Same oversights here.


Regards,
Clemens

  reply	other threads:[~2014-08-19 10:57 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-19 10:38 [PATCH] usb: use kcalloc instead of kzalloc Arjun Sreedharan
2014-08-19 10:56 ` Clemens Ladisch [this message]
2014-08-19 14:41 ` Alan Stern

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=53F32D79.8050401@ladisch.de \
    --to=clemens@ladisch.de \
    --cc=arjun024@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    /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.