Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

staging/lustre: Use proper number of bytes in copy_from_user

This patch removes the usage of MAX_STRING_SIZE from
copy_from_user() and just copies enough bytes to cover
count passed in.

Signed-off-by: Jian Yu <jian.yu@intel.com>
Reviewed-on: http://review.whamcloud.com/23462
Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-8774
Reviewed-by: John L. Hammond <john.hammond@intel.com>
Signed-off-by: Oleg Drokin <green@linuxhacker.ru>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Jian Yu and committed by
Greg Kroah-Hartman
8d130c3b 35487271

+9 -2
+9 -2
drivers/staging/lustre/lustre/obdclass/lprocfs_status.c
··· 400 400 char dummy[MAX_STRING_SIZE + 1], *end; 401 401 unsigned long tmp; 402 402 403 - dummy[MAX_STRING_SIZE] = '\0'; 404 - if (copy_from_user(dummy, buffer, MAX_STRING_SIZE)) 403 + if (count >= sizeof(dummy)) 404 + return -EINVAL; 405 + 406 + if (count == 0) 407 + return 0; 408 + 409 + if (copy_from_user(dummy, buffer, count)) 405 410 return -EFAULT; 411 + 412 + dummy[count] = '\0'; 406 413 407 414 tmp = simple_strtoul(dummy, &end, 0); 408 415 if (dummy == end)