linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ks390/keyboard: use memdup_user().
@ 2016-05-20 12:22 Muhammad Falak R Wani
  2016-05-20 13:03 ` Heiko Carstens
  0 siblings, 1 reply; 3+ messages in thread
From: Muhammad Falak R Wani @ 2016-05-20 12:22 UTC (permalink / raw)
  To: Heiko Carstens; +Cc: Martin Schwidefsky, Jan Kara, open list:S390, open list

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@gmail.com>
---
 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.
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] ks390/keyboard: use memdup_user().
  2016-05-20 12:22 [PATCH] ks390/keyboard: use memdup_user() Muhammad Falak R Wani
@ 2016-05-20 13:03 ` Heiko Carstens
  2016-05-20 13:07   ` Muhammad Falak R Wani
  0 siblings, 1 reply; 3+ messages in thread
From: Heiko Carstens @ 2016-05-20 13:03 UTC (permalink / raw)
  To: Muhammad Falak R Wani
  Cc: Martin Schwidefsky, Jan Kara, open list:S390, open list

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@gmail.com>
> ---
>  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?

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] ks390/keyboard: use memdup_user().
  2016-05-20 13:03 ` Heiko Carstens
@ 2016-05-20 13:07   ` Muhammad Falak R Wani
  0 siblings, 0 replies; 3+ messages in thread
From: Muhammad Falak R Wani @ 2016-05-20 13:07 UTC (permalink / raw)
  To: Heiko Carstens; +Cc: Martin Schwidefsky, Jan Kara, open list:S390, open list

On Fri, May 20, 2016 at 03:03:25PM +0200, Heiko Carstens wrote:
> 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@gmail.com>
> > +		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?
> 
Should I send V2 with the suggested changes ?

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-05-20 13:07 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-05-20 12:22 [PATCH] ks390/keyboard: use memdup_user() Muhammad Falak R Wani
2016-05-20 13:03 ` Heiko Carstens
2016-05-20 13:07   ` Muhammad Falak R Wani

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).