aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Kara <jack@suse.cz>2015-06-02 06:38:39 -0400
committerMartin Schwidefsky <schwidefsky@de.ibm.com>2015-06-15 04:51:12 -0400
commit8cb81811e924ff0214ce4e8344e2feb1549cf0ce (patch)
tree4bb8a52ff2121d335f893ad2d2cf4bfa89e47ece
parent2e4aa2f2bdcf9b80bace0b0c460bd407d76f49d3 (diff)
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: Jan Kara <jack@suse.cz> Signed-off-by: Heiko Carstens <heiko.carstens@de.ibm.com> Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
-rw-r--r--drivers/s390/char/keyboard.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/drivers/s390/char/keyboard.c b/drivers/s390/char/keyboard.c
index 01463b052ae7..ef04a9f7a704 100644
--- a/drivers/s390/char/keyboard.c
+++ b/drivers/s390/char/keyboard.c
@@ -433,20 +433,23 @@ do_kdgkb_ioctl(struct kbd_data *kbd, struct kbsentry __user *u_kbs,
433 case KDSKBSENT: 433 case KDSKBSENT:
434 if (!perm) 434 if (!perm)
435 return -EPERM; 435 return -EPERM;
436 len = strnlen_user(u_kbs->kb_string, 436 len = strnlen_user(u_kbs->kb_string, sizeof(u_kbs->kb_string));
437 sizeof(u_kbs->kb_string) - 1);
438 if (!len) 437 if (!len)
439 return -EFAULT; 438 return -EFAULT;
440 if (len > sizeof(u_kbs->kb_string) - 1) 439 if (len > sizeof(u_kbs->kb_string))
441 return -EINVAL; 440 return -EINVAL;
442 p = kmalloc(len + 1, GFP_KERNEL); 441 p = kmalloc(len, GFP_KERNEL);
443 if (!p) 442 if (!p)
444 return -ENOMEM; 443 return -ENOMEM;
445 if (copy_from_user(p, u_kbs->kb_string, len)) { 444 if (copy_from_user(p, u_kbs->kb_string, len)) {
446 kfree(p); 445 kfree(p);
447 return -EFAULT; 446 return -EFAULT;
448 } 447 }
449 p[len] = 0; 448 /*
449 * Make sure the string is terminated by 0. User could have
450 * modified it between us running strnlen_user() and copying it.
451 */
452 p[len - 1] = 0;
450 kfree(kbd->func_table[kb_func]); 453 kfree(kbd->func_table[kb_func]);
451 kbd->func_table[kb_func] = p; 454 kbd->func_table[kb_func] = p;
452 break; 455 break;