mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: Oleg Drokin <green@linuxhacker.ru>
Cc: devel@driverdev.osuosl.org,
	Andreas Dilger <andreas.dilger@intel.com>,
	James Simmons <jsimmons@infradead.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Jian Yu <jian.yu@intel.com>,
	Lustre Development List <lustre-devel@lists.lustre.org>
Subject: Re: [PATCH] staging/lustre: Use proper number of bytes in copy_from_user
Date: Mon, 21 Nov 2016 11:14:40 +0100	[thread overview]
Message-ID: <20161121101440.GA9749@kroah.com> (raw)
In-Reply-To: <1479707208-1241688-1-git-send-email-green@linuxhacker.ru>

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

      reply	other threads:[~2016-11-21 10:14 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-21  5:46 Oleg Drokin
2016-11-21 10:14 ` Greg Kroah-Hartman [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20161121101440.GA9749@kroah.com \
    --to=gregkh@linuxfoundation.org \
    --cc=andreas.dilger@intel.com \
    --cc=devel@driverdev.osuosl.org \
    --cc=green@linuxhacker.ru \
    --cc=jian.yu@intel.com \
    --cc=jsimmons@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lustre-devel@lists.lustre.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome