linux-staging.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: Charlie Sands <sandsch@northvilleschools.net>
Cc: gregkh@linuxfoundation.org, Larry.Finger@lwfinger.net,
	phil@philpotter.co.uk, linux-staging@lists.linux.dev,
	linux-kernel@vger.kernel.org, paskripkin@gmail.com,
	straube.linux@gmail.com, fmdefrancesco@gmail.com
Subject: Re: [PATCH V3] staging: r8188eu: Fix unsafe memory access by memcmp.
Date: Wed, 6 Apr 2022 16:14:26 +0300	[thread overview]
Message-ID: <20220406131426.GH3293@kadam> (raw)
In-Reply-To: <Yk14tpZCOFCsvtup@sckzor-linux.localdomain>

On Wed, Apr 06, 2022 at 07:25:42AM -0400, Charlie Sands wrote:
> This patch fixes sparse warnings about the memcmp function unsafely accessing 
> userspace memory without first copying it to kernel space.
> 
> Signed-off-by: Charlie Sands <sandsch@northvilleschools.net>
> ---
> 
> V2: Fixed checkpatch.pl warning and changed variable name as suggested by Greg
> K. H. and improved error checking on the "copy_from_user" function as suggested
> by Pavel Skripkin.
> 
> V3: return -EFAULT from the function when there is a memory error while moving
> it from user space to kernel space and fix incorrect subject from V2
> 
>  drivers/staging/r8188eu/os_dep/ioctl_linux.c | 21 ++++++++++++--------
>  1 file changed, 13 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/staging/r8188eu/os_dep/ioctl_linux.c b/drivers/staging/r8188eu/os_dep/ioctl_linux.c
> index 7df213856d66..9f2182b8e451 100644
> --- a/drivers/staging/r8188eu/os_dep/ioctl_linux.c
> +++ b/drivers/staging/r8188eu/os_dep/ioctl_linux.c
> @@ -3233,23 +3233,28 @@ static int rtw_p2p_get(struct net_device *dev,
>  			       struct iw_request_info *info,
>  			       union iwreq_data *wrqu, char *extra)
>  {
> -	if (!memcmp(wrqu->data.pointer, "status", 6)) {
> +	char wrqu_data[9];
> +
> +	if (copy_from_user(wrqu_data, wrqu->data.pointer, 9) != 0)

How do you know that the user buffer is passing 9 characters long?

You're fixing a real bug, sure, but you've inventing a new API and it's
a rubbish API.  Just delete rtw_p2p_get() and the associated code.  It
has never worked so no one will miss it.

regards,
dan carpenter



      reply	other threads:[~2022-04-06 14:48 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-06 11:25 [PATCH V3] staging: r8188eu: Fix unsafe memory access by memcmp Charlie Sands
2022-04-06 13:14 ` Dan Carpenter [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=20220406131426.GH3293@kadam \
    --to=dan.carpenter@oracle.com \
    --cc=Larry.Finger@lwfinger.net \
    --cc=fmdefrancesco@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-staging@lists.linux.dev \
    --cc=paskripkin@gmail.com \
    --cc=phil@philpotter.co.uk \
    --cc=sandsch@northvilleschools.net \
    --cc=straube.linux@gmail.com \
    /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;
as well as URLs for NNTP newsgroup(s).