vt: keyboard, reorder user buffer handling in vt_do_kdgkb_ioctl
authorJiri Slaby <jslaby@suse.cz>
Thu, 29 Oct 2020 11:32:16 +0000 (12:32 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 4 Nov 2020 15:43:38 +0000 (16:43 +0100)
commit07edff9265204e15c9fc8d07cc69e38c4c484e15
tree41bac874491adee454224fd78c666d8d7564d58e
parent9788c950ed4ad2020a7f2e8231abaf77e49d871a
vt: keyboard, reorder user buffer handling in vt_do_kdgkb_ioctl

KDGKBSENT (the getter) needs only 'user_kdgkb->kb_func' from the
userspace, i.e. the index. Then it needs a buffer for a local copy of
'kb_string'.

KDSKBSENT (the setter) needs a copy up to the length of
'user_kdgkb->kb_string'.

That means, we obtain the index before the switch-case and use it in
both paths and:
1) allocate full space in the getter case, and
2) copy the string only in the setter case. We do it by strndup_user
   helper now which was not available when this function was written.

Given we copy the two members of 'struct kbsentry' separately, we no
longer need a local definition. Hence we need to change all the sizeofs
here too.

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Link: https://lore.kernel.org/r/20201029113222.32640-11-jslaby@suse.cz
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/tty/vt/keyboard.c