Skip to content

Commit

Permalink
s390/keyboard: use memdup_user_nul()
Browse files Browse the repository at this point in the history
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>
[heiko.carstens@de.ibm.com: remove comment]
Signed-off-by: Heiko Carstens <heiko.carstens@de.ibm.com>

Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
  • Loading branch information
Muhammad Falak R Wani authored and Martin Schwidefsky committed Jun 13, 2016
1 parent 1c343f7 commit fd346c9
Showing 1 changed file with 3 additions and 12 deletions.
15 changes: 3 additions & 12 deletions drivers/s390/char/keyboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -438,18 +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;
}
/*
* 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;
p = memdup_user_nul(u_kbs->kb_string, len);
if (IS_ERR(p))
return PTR_ERR(p);
kfree(kbd->func_table[kb_func]);
kbd->func_table[kb_func] = p;
break;
Expand Down

0 comments on commit fd346c9

Please sign in to comment.