mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Aristeu Rozanski <aris@cathedrallabs.org>
To: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Cc: David Herrmann <dh.herrmann@googlemail.com>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] uinput strnlen bugfix
Date: Tue, 8 Feb 2011 14:58:55 -0500	[thread overview]
Message-ID: <20110208195855.GL22170@cathedrallabs.org> (raw)
In-Reply-To: <20110208073848.GA865@core.coreip.homeip.net>

On Mon, Feb 07, 2011 at 11:38:48PM -0800, Dmitry Torokhov wrote:
> Input: uinput - use memdup_user() and friends
> 
> From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
> 
> Instead of open-coding copying of data structures from userspace use
> memdup_user() and strndup_user(). Note that this introduces change in
> behavior because driver used to truncate 'phys' longer than 1024 bytes,
> but now it will refuse to set 'phys' that long. Arguably trying to set
> such 'phys' is suspect anyways.
> 
> Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
> ---
> 
>  drivers/input/misc/uinput.c |   35 ++++++++++-------------------------
>  1 files changed, 10 insertions(+), 25 deletions(-)
> 
> 
> diff --git a/drivers/input/misc/uinput.c b/drivers/input/misc/uinput.c
> index c0888e3..7f8331f 100644
> --- a/drivers/input/misc/uinput.c
> +++ b/drivers/input/misc/uinput.c
> @@ -361,14 +361,9 @@ static int uinput_setup_device(struct uinput_device *udev, const char __user *bu
>  
>  	dev = udev->dev;
>  
> -	user_dev = kmalloc(sizeof(struct uinput_user_dev), GFP_KERNEL);
> -	if (!user_dev)
> -		return -ENOMEM;
> -
> -	if (copy_from_user(user_dev, buffer, sizeof(struct uinput_user_dev))) {
> -		retval = -EFAULT;
> -		goto exit;
> -	}
> +	user_dev = memdup_user(buffer, sizeof(struct uinput_user_dev));
> +	if (!IS_ERR(user_dev))
> +		return PTR_ERR(user_dev);
>  
>  	udev->ff_effects_max = user_dev->ff_effects_max;
>  
> @@ -621,7 +616,6 @@ static long uinput_ioctl_handler(struct file *file, unsigned int cmd,
>  	struct uinput_ff_upload ff_up;
>  	struct uinput_ff_erase  ff_erase;
>  	struct uinput_request   *req;
> -	int                     length;
>  	char			*phys;
>  
>  	retval = mutex_lock_interruptible(&udev->mutex);
> @@ -688,24 +682,15 @@ static long uinput_ioctl_handler(struct file *file, unsigned int cmd,
>  				retval = -EINVAL;
>  				goto out;
>  			}
> -			length = strnlen_user(p, 1024);
> -			if (length <= 0) {
> -				retval = -EFAULT;
> -				break;
> +
> +			phys = strndup_user(p, 1024);
> +			if (IS_ERR(phys)) {
> +				retval = PTR_ERR(phys);
> +				goto out;
>  			}
> +
>  			kfree(udev->dev->phys);
> -			udev->dev->phys = phys = kmalloc(length, GFP_KERNEL);
> -			if (!phys) {
> -				retval = -ENOMEM;
> -				break;
> -			}
> -			if (copy_from_user(phys, p, length)) {
> -				udev->dev->phys = NULL;
> -				kfree(phys);
> -				retval = -EFAULT;
> -				break;
> -			}
> -			phys[length - 1] = '\0';
> +			udev->dev->phys = phys;
>  			break;
>  
>  		case UI_BEGIN_FF_UPLOAD:
looks good to me
Acked-by: Aristeu Rozanski <aris@ruivo.org>

-- 
Aristeu


      reply	other threads:[~2011-02-08 19:59 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-02-06 16:49 David Herrmann
2011-02-06 16:55 ` Aristeu Rozanski
2011-02-06 16:57   ` David Herrmann
2011-02-06 17:23     ` Aristeu Rozanski
2011-02-07  7:40       ` Dmitry Torokhov
2011-02-07 12:52         ` David Herrmann
2011-02-07 13:25         ` Aristeu Rozanski
2011-02-08  7:38         ` Dmitry Torokhov
2011-02-08 19:58           ` Aristeu Rozanski [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=20110208195855.GL22170@cathedrallabs.org \
    --to=aris@cathedrallabs.org \
    --cc=dh.herrmann@googlemail.com \
    --cc=dmitry.torokhov@gmail.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

all inboxes | Powered by JetHome®