Skip to content

Commit

Permalink
Input: tty/vt/keyboard - use memdup_user()
Browse files Browse the repository at this point in the history
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>
Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
  • Loading branch information
Muhammad Falak R Wani authored and Dmitry Torokhov committed Jul 21, 2016
1 parent c1d7b7c commit 0097ff3
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions drivers/tty/vt/keyboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -1745,16 +1745,10 @@ int vt_do_diacrit(unsigned int cmd, void __user *udp, int perm)
return -EINVAL;

if (ct) {
buf = kmalloc(ct * sizeof(struct kbdiacruc),
GFP_KERNEL);
if (buf == NULL)
return -ENOMEM;

if (copy_from_user(buf, a->kbdiacruc,
ct * sizeof(struct kbdiacruc))) {
kfree(buf);
return -EFAULT;
}
buf = memdup_user(a->kbdiacruc,
ct * sizeof(struct kbdiacruc));
if (IS_ERR(buf))
return PTR_ERR(buf);
}
spin_lock_irqsave(&kbd_event_lock, flags);
if (ct)
Expand Down

0 comments on commit 0097ff3

Please sign in to comment.