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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, May 20, 2016 at 05:52:16PM +0530, Muhammad Falak R Wani wrote:
> Use memdup_user to duplicate a memory region from user-space to
> kernel-space, instead of open coding using kmalloc & copy_from_user.
> 
> Signed-off-by: Muhammad Falak R Wani <falakreyaz@xxxxxxxxx>
> ---
>  drivers/s390/char/keyboard.c | 10 +++-------
>  1 file changed, 3 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/s390/char/keyboard.c b/drivers/s390/char/keyboard.c
> index ef04a9f..2955983 100644
> --- a/drivers/s390/char/keyboard.c
> +++ b/drivers/s390/char/keyboard.c
> @@ -438,13 +438,9 @@ 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(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.

Hi Muhammad, thanks for this patch. However could you change this to use
memdup_user_nul() instead, so we can get rid of even more code?

--
To unsubscribe from this list: send the line "unsubscribe linux-s390" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Kernel Development]     [Kernel Newbies]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite Info]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Linux Media]     [Device Mapper]

  Powered by Linux