Skip to content

Commit 6ca03f9

Browse files
Jiri Slabygregkh
authored andcommitted
vt: keyboard, simplify vt_kdgkbsent
Use 'strlen' of the string, add one for NUL terminator and simply do 'copy_to_user' instead of the explicit 'for' loop. This makes the KDGKBSENT case more compact. The only thing we need to take care about is NULL 'func_table[i]'. Use an empty string in that case. The original check for overflow could never trigger as the func_buf strings are always shorter or equal to 'struct kbsentry's. Cc: <stable@vger.kernel.org> Signed-off-by: Jiri Slaby <jslaby@suse.cz> Link: https://lore.kernel.org/r/20201019085517.10176-1-jslaby@suse.cz Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent c97f2a6 commit 6ca03f9

1 file changed

Lines changed: 9 additions & 19 deletions

File tree

drivers/tty/vt/keyboard.c

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1995,9 +1995,7 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
19951995
int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
19961996
{
19971997
struct kbsentry *kbs;
1998-
char *p;
19991998
u_char *q;
2000-
u_char __user *up;
20011999
int sz, fnw_sz;
20022000
int delta;
20032001
char *first_free, *fj, *fnw;
@@ -2023,23 +2021,15 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
20232021
i = array_index_nospec(kbs->kb_func, MAX_NR_FUNC);
20242022

20252023
switch (cmd) {
2026-
case KDGKBSENT:
2027-
sz = sizeof(kbs->kb_string) - 1; /* sz should have been
2028-
a struct member */
2029-
up = user_kdgkb->kb_string;
2030-
p = func_table[i];
2031-
if(p)
2032-
for ( ; *p && sz; p++, sz--)
2033-
if (put_user(*p, up++)) {
2034-
ret = -EFAULT;
2035-
goto reterr;
2036-
}
2037-
if (put_user('\0', up)) {
2038-
ret = -EFAULT;
2039-
goto reterr;
2040-
}
2041-
kfree(kbs);
2042-
return ((p && *p) ? -EOVERFLOW : 0);
2024+
case KDGKBSENT: {
2025+
/* size should have been a struct member */
2026+
unsigned char *from = func_table[i] ? : "";
2027+
2028+
ret = copy_to_user(user_kdgkb->kb_string, from,
2029+
strlen(from) + 1) ? -EFAULT : 0;
2030+
2031+
goto reterr;
2032+
}
20432033
case KDSKBSENT:
20442034
if (!perm) {
20452035
ret = -EPERM;

0 commit comments

Comments
 (0)