提交 8cb81811 编写于 作者: J Jan Kara 提交者: Martin Schwidefsky

s390/keyboard: avoid off-by-one when using strnlen_user()

strnlen_user() returns the length of the string including terminating 0.
So avoid counting it again and unnecessarily reducing maximum string
size by 1.
Signed-off-by: NJan Kara <jack@suse.cz>
Signed-off-by: NHeiko Carstens <heiko.carstens@de.ibm.com>
Signed-off-by: NMartin Schwidefsky <schwidefsky@de.ibm.com>
上级 2e4aa2f2
...@@ -433,20 +433,23 @@ do_kdgkb_ioctl(struct kbd_data *kbd, struct kbsentry __user *u_kbs, ...@@ -433,20 +433,23 @@ do_kdgkb_ioctl(struct kbd_data *kbd, struct kbsentry __user *u_kbs,
case KDSKBSENT: case KDSKBSENT:
if (!perm) if (!perm)
return -EPERM; return -EPERM;
len = strnlen_user(u_kbs->kb_string, len = strnlen_user(u_kbs->kb_string, sizeof(u_kbs->kb_string));
sizeof(u_kbs->kb_string) - 1);
if (!len) if (!len)
return -EFAULT; return -EFAULT;
if (len > sizeof(u_kbs->kb_string) - 1) if (len > sizeof(u_kbs->kb_string))
return -EINVAL; return -EINVAL;
p = kmalloc(len + 1, GFP_KERNEL); p = kmalloc(len, GFP_KERNEL);
if (!p) if (!p)
return -ENOMEM; return -ENOMEM;
if (copy_from_user(p, u_kbs->kb_string, len)) { if (copy_from_user(p, u_kbs->kb_string, len)) {
kfree(p); kfree(p);
return -EFAULT; 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]); kfree(kbd->func_table[kb_func]);
kbd->func_table[kb_func] = p; kbd->func_table[kb_func] = p;
break; break;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册