Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1526370 > unrolled thread

[PATCH] staging/lustre: Use proper number of bytes in copy_from_user

Started byOleg Drokin <green@linuxhacker.ru>
First post2016-11-21 06:50 +0100
Last post2016-11-21 11:20 +0100
Articles 2 — 2 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH] staging/lustre: Use proper number of bytes in copy_from_user Oleg Drokin <green@linuxhacker.ru> - 2016-11-21 06:50 +0100
    Re: [PATCH] staging/lustre: Use proper number of bytes in  copy_from_user Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2016-11-21 11:20 +0100

#1526370 — [PATCH] staging/lustre: Use proper number of bytes in copy_from_user

FromOleg Drokin <green@linuxhacker.ru>
Date2016-11-21 06:50 +0100
Subject[PATCH] staging/lustre: Use proper number of bytes in copy_from_user
Message-ID<sFPEl-5rv-1@gated-at.bofh.it>
From: Jian Yu <jian.yu@intel.com>

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>
---
 drivers/staging/lustre/lustre/obdclass/lprocfs_status.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/lustre/lustre/obdclass/lprocfs_status.c b/drivers/staging/lustre/lustre/obdclass/lprocfs_status.c
index 8a2f02f3..db49992 100644
--- a/drivers/staging/lustre/lustre/obdclass/lprocfs_status.c
+++ b/drivers/staging/lustre/lustre/obdclass/lprocfs_status.c
@@ -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;
-- 
2.7.4

[toc] | [next] | [standalone]


#1526526 — Re: [PATCH] staging/lustre: Use proper number of bytes in copy_from_user

FromGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Date2016-11-21 11:20 +0100
SubjectRe: [PATCH] staging/lustre: Use proper number of bytes in copy_from_user
Message-ID<sFTRD-8lZ-19@gated-at.bofh.it>
In reply to#1526370
On Mon, Nov 21, 2016 at 12:46:48AM -0500, Oleg Drokin wrote:
> From: Jian Yu <jian.yu@intel.com>
> 
> 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>
> ---
>  drivers/staging/lustre/lustre/obdclass/lprocfs_status.c | 11 +++++++++--
>  1 file changed, 9 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/staging/lustre/lustre/obdclass/lprocfs_status.c b/drivers/staging/lustre/lustre/obdclass/lprocfs_status.c
> index 8a2f02f3..db49992 100644
> --- a/drivers/staging/lustre/lustre/obdclass/lprocfs_status.c
> +++ b/drivers/staging/lustre/lustre/obdclass/lprocfs_status.c
> @@ -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';
> +

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

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web