* [PATCH v2] ks390/keyboard: use memdup_user_nul().
@ 2016-05-20 13:21 Muhammad Falak R Wani
2016-05-20 13:41 ` Heiko Carstens
0 siblings, 1 reply; 2+ messages in thread
From: Muhammad Falak R Wani @ 2016-05-20 13:21 UTC (permalink / raw)
To: Heiko Carstens; +Cc: Martin Schwidefsky, Jan Kara, linux-s390, linux-kernel
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;
kfree(kbd->func_table[kb_func]);
kbd->func_table[kb_func] = p;
break;
--
1.9.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v2] ks390/keyboard: use memdup_user_nul().
2016-05-20 13:21 [PATCH v2] ks390/keyboard: use memdup_user_nul() Muhammad Falak R Wani
@ 2016-05-20 13:41 ` Heiko Carstens
0 siblings, 0 replies; 2+ messages in thread
From: Heiko Carstens @ 2016-05-20 13:41 UTC (permalink / raw)
To: Muhammad Falak R Wani
Cc: Martin Schwidefsky, Jan Kara, linux-s390, linux-kernel
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!
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2016-05-20 13:41 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 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).