staging/lustre: Use proper number of bytes in copy_from_user
PATCH 1/1 staging/lustre: Use proper number of bytes in copy_from_user
From: Jian Yu <[email protected]>
This patch removes the usage of MAX_STRING_SIZE from copy_from_user() and just copies enough bytes to cover count passed in.
Reviewed-on: http://review.whamcloud.com/23462
Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-8774
--- drivers/staging/lustre/lustre/obdclass/lprocfs_status.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
drivers/staging/lustre/lustre/obdclass/lprocfs_status.c +9 -2
@@ -400,10 +400,17 @@ int lprocfs_wr_uint(struct file *file, const char __user *buffer,char dummy[MAX_STRING_SIZE +1 ], *end;unsigned long tmp; - dummy[MAX_STRING_SIZE ] ='\0' ; -if (copy_from_user (dummy, buffer,MAX_STRING_SIZE )) +if (count >=sizeof (dummy)) +return -EINVAL ; + +if (count ==0 ) +return 0 ; + +if (copy_from_user (dummy, buffer, count))return -EFAULT ; + dummy[count] ='\0' ; + tmp =simple_strtoul (dummy, &end,0 );if (dummy == end)return -EINVAL ;
Signature · 1 line
2.7.4
Greg Kroah-Hartman
maintainerQuoted 26 lines · Oleg Drokin
From: Jian Yu <[email protected]>
This patch removes the usage of
MAX_STRING_SIZEfromcopy_from_user()and just copies enough bytes to cover count passed in.Signed-off-by Jian Yu <[email protected]>Reviewed-on: http://review.whamcloud.com/23462
Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-8774Reviewed-by John L. Hammond <[email protected]>Signed-off-by Oleg Drokin <[email protected]>--- drivers/staging/lustre/lustre/obdclass/lprocfs_status.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)drivers/staging/lustre/lustre/obdclass/lprocfs_status.c +1
-2@@ -400,10 +400,17 @@ int lprocfs_wr_uint(struct file *file, const char __user *buffer,char dummy[MAX_STRING_SIZE +1 ], *end;unsigned long tmp; - dummy[MAX_STRING_SIZE ] ='\0' ; -if (copy_from_user (dummy, buffer,MAX_STRING_SIZE )) +if (count >=sizeof (dummy))
drivers/staging/lustre/lustre/obdclass/lprocfs_status.c int lprocfs_wr_uint(struct file *file, const char __user *buffer, · line 413
Quoted 10 lines
drivers/staging/lustre/lustre/obdclass/lprocfs_status.c +8
-0+return -EINVAL ; + +if (count ==0 ) +return 0 ; + +if (copy_from_user (dummy, buffer, count))return -EFAULT ; + dummy[count] ='\0' ; +
You do know about simple_read_from_buffer(), right? I suggest using those simple_* functions where ever you are touching user buffers, like this code.
thanks,
greg k-h