Commit fd346c9d authored by Muhammad Falak R Wani's avatar Muhammad Falak R Wani Committed by Martin Schwidefsky

s390/keyboard: use memdup_user_nul()

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: default avatarMuhammad Falak R Wani <falakreyaz@gmail.com>
[heiko.carstens@de.ibm.com: remove comment]
Signed-off-by: default avatarHeiko Carstens <heiko.carstens@de.ibm.com>
Signed-off-by: default avatarMartin Schwidefsky <schwidefsky@de.ibm.com>
parent 1c343f7b
...@@ -438,18 +438,9 @@ do_kdgkb_ioctl(struct kbd_data *kbd, struct kbsentry __user *u_kbs, ...@@ -438,18 +438,9 @@ do_kdgkb_ioctl(struct kbd_data *kbd, struct kbsentry __user *u_kbs,
return -EFAULT; return -EFAULT;
if (len > sizeof(u_kbs->kb_string)) if (len > sizeof(u_kbs->kb_string))
return -EINVAL; return -EINVAL;
p = kmalloc(len, GFP_KERNEL); p = memdup_user_nul(u_kbs->kb_string, len);
if (!p) if (IS_ERR(p))
return -ENOMEM; return PTR_ERR(p);
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;
kfree(kbd->func_table[kb_func]); kfree(kbd->func_table[kb_func]);
kbd->func_table[kb_func] = p; kbd->func_table[kb_func] = p;
break; break;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment