Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1404447

Re: [PATCH v2] ks390/keyboard: use memdup_user_nul().

From Heiko Carstens <heiko.carstens@de.ibm.com>
Newsgroups linux.kernel
Subject Re: [PATCH v2] ks390/keyboard: use memdup_user_nul().
Date 2016-05-20 15:50 +0200
Message-ID <rASYq-68P-37@gated-at.bofh.it> (permalink)
References <rASF5-60q-37@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


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!

Back to linux.kernel | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

[PATCH v2] ks390/keyboard: use memdup_user_nul(). Muhammad Falak R Wani <falakreyaz@gmail.com> - 2016-05-20 15:30 +0200
  Re: [PATCH v2] ks390/keyboard: use memdup_user_nul(). Heiko Carstens <heiko.carstens@de.ibm.com> - 2016-05-20 15:50 +0200

csiph-web