All of lore.kernel.org
 help / color / mirror / Atom feed
From: Heiko Carstens <heiko.carstens@de.ibm.com>
To: Muhammad Falak R Wani <falakreyaz@gmail.com>
Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>,
	Jan Kara <jack@suse.cz>,
	linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] ks390/keyboard: use memdup_user_nul().
Date: Fri, 20 May 2016 15:41:06 +0200	[thread overview]
Message-ID: <20160520134106.GF3461@osiris> (raw)
In-Reply-To: <1463750488-12565-1-git-send-email-falakreyaz@gmail.com>

On Fri, May 20, 2016 at 06:51:20PM +0530, Muhammad Falak R Wani wrote:
> Use memdup_user_nul to duplicate a memory region from user-space
> to kernel-space and terminate with a NULL, instead of open coding
> using kmalloc + copy_from_user and explicitly NULL terminating.
> 
> Signed-off-by: Muhammad Falak R Wani <falakreyaz@gmail.com>
> ---
>  drivers/s390/char/keyboard.c | 11 +++--------
>  1 file changed, 3 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/s390/char/keyboard.c b/drivers/s390/char/keyboard.c
> index ef04a9f..f82a7dc 100644
> --- a/drivers/s390/char/keyboard.c
> +++ b/drivers/s390/char/keyboard.c
> @@ -438,18 +438,13 @@ do_kdgkb_ioctl(struct kbd_data *kbd, struct kbsentry __user *u_kbs,
>  			return -EFAULT;
>  		if (len > sizeof(u_kbs->kb_string))
>  			return -EINVAL;
> -		p = kmalloc(len, GFP_KERNEL);
> -		if (!p)
> -			return -ENOMEM;
> -		if (copy_from_user(p, u_kbs->kb_string, len)) {
> -			kfree(p);
> -			return -EFAULT;
> -		}
> +		p = memdup_user_nul(u_kbs->kb_string, len);
> +		if (IS_ERR(p))
> +			return PTR_ERR(p);
>  		/*
>  		 * Make sure the string is terminated by 0. User could have
>  		 * modified it between us running strnlen_user() and copying it.
>  		 */
> -		p[len - 1] = 0;

I removed the comment above as well and folded that into your patch.
Applied, thanks!

      reply	other threads:[~2016-05-20 13:41 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-20 13:21 [PATCH v2] ks390/keyboard: use memdup_user_nul() Muhammad Falak R Wani
2016-05-20 13:41 ` Heiko Carstens [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=20160520134106.GF3461@osiris \
    --to=heiko.carstens@de.ibm.com \
    --cc=falakreyaz@gmail.com \
    --cc=jack@suse.cz \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-s390@vger.kernel.org \
    --cc=schwidefsky@de.ibm.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 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.