--- zzzz-none-000/linux-3.10.107/drivers/s390/char/keyboard.c 2017-06-27 09:49:32.000000000 +0000 +++ scorpion-7490-727/linux-3.10.107/drivers/s390/char/keyboard.c 2021-02-04 17:41:59.000000000 +0000 @@ -433,20 +433,23 @@ case KDSKBSENT: if (!perm) return -EPERM; - len = strnlen_user(u_kbs->kb_string, - sizeof(u_kbs->kb_string) - 1); + len = strnlen_user(u_kbs->kb_string, sizeof(u_kbs->kb_string)); if (!len) return -EFAULT; - if (len > sizeof(u_kbs->kb_string) - 1) + if (len > sizeof(u_kbs->kb_string)) return -EINVAL; - p = kmalloc(len + 1, GFP_KERNEL); + p = kmalloc(len, GFP_KERNEL); if (!p) return -ENOMEM; if (copy_from_user(p, u_kbs->kb_string, len)) { kfree(p); return -EFAULT; } - p[len] = 0; + /* + * 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]); kbd->func_table[kb_func] = p; break;