mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Joe Perches <joe@perches.com>
To: Geliang Tang <geliangtang@gmail.com>,
	Ian Abbott <abbotti@mev.co.uk>,
	H Hartley Sweeten <hsweeten@visionengravers.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Arnd Bergmann <arnd@arndb.de>
Cc: devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] staging: comedi: use memdup_user
Date: Fri, 28 Apr 2017 18:53:32 -0700	[thread overview]
Message-ID: <1493430812.1873.26.camel@perches.com> (raw)
In-Reply-To: <6d37f80c3c8cb4572469e30dd5ebae1388b67c97.1493382684.git.geliangtang@gmail.com>

On Sat, 2017-04-29 at 09:45 +0800, Geliang Tang wrote:
> Use memdup_user() helper instead of open-coding to simplify the code.

While I doubt this is a problem, this loses
the multiplication overflow check for
sizeof(*insns) * insnlist.n_isns

> diff --git a/drivers/staging/comedi/comedi_fops.c b/drivers/staging/comedi/comedi_fops.c
[]
> @@ -1450,22 +1450,14 @@ static int do_insnlist_ioctl(struct comedi_device *dev,
>  		return -EFAULT;
>  
>  	data = kmalloc_array(MAX_SAMPLES, sizeof(unsigned int), GFP_KERNEL);
> -	if (!data) {
> -		ret = -ENOMEM;
> -		goto error;
> -	}
> -
> -	insns = kcalloc(insnlist.n_insns, sizeof(*insns), GFP_KERNEL);
> -	if (!insns) {
> -		ret = -ENOMEM;
> -		goto error;
> -	}
> +	if (!data)
> +		return -ENOMEM;
>  
> -	if (copy_from_user(insns, insnlist.insns,
> -			   sizeof(*insns) * insnlist.n_insns)) {
> -		dev_dbg(dev->class_dev, "copy_from_user failed\n");
> -		ret = -EFAULT;
> -		goto error;
> +	insns = memdup_user(insnlist.insns, sizeof(*insns) * insnlist.n_insns);
> +	if (IS_ERR(insns)) {
> +		dev_dbg(dev->class_dev, "memdup_user failed\n");
> +		kfree(data);
> +		return PTR_ERR(insns);
>  	}
>  
>  	for (i = 0; i < insnlist.n_insns; i++) {

  reply	other threads:[~2017-04-29  1:53 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-29  1:45 [PATCH] cciss: " Geliang Tang
2017-04-29  1:45 ` [PATCH] floppy: " Geliang Tang
2017-04-29  1:45 ` [PATCH] powerpc/nvram: " Geliang Tang
2017-06-28  0:08   ` Kees Cook
2017-04-29  1:45 ` [PATCH] powerpc/powernv: " Geliang Tang
2017-07-27 12:37   ` Michael Ellerman
2017-04-29  1:45 ` [PATCH] powerpc/pseries: use memdup_user_nul Geliang Tang
2017-07-27 12:37   ` Michael Ellerman
2017-04-29  1:45 ` [PATCH] pstore: use memdup_user Geliang Tang
2017-06-28  0:07   ` Kees Cook
2017-04-29  1:45 ` [PATCH] skd_main: " Geliang Tang
2017-04-29  1:45 ` [PATCH] staging: comedi: " Geliang Tang
2017-04-29  1:53   ` Joe Perches [this message]
2017-04-29  5:17     ` Greg Kroah-Hartman

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=1493430812.1873.26.camel@perches.com \
    --to=joe@perches.com \
    --cc=abbotti@mev.co.uk \
    --cc=arnd@arndb.de \
    --cc=devel@driverdev.osuosl.org \
    --cc=geliangtang@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=hsweeten@visionengravers.com \
    --cc=linux-kernel@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome