linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH V2] Fix unsafe memory access by memcmp
@ 2022-04-04  2:52 Charlie Sands
  2022-04-04  8:02 ` Michael Straube
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Charlie Sands @ 2022-04-04  2:52 UTC (permalink / raw)
  To: gregkh; +Cc: Larry.Finger, phil, linux-staging, linux-kernel, paskripkin

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.

 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..4b4eec2bde96 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)
+		return 0;
+
+	if (!memcmp(wrqu_data, "status", 6)) {
 		rtw_p2p_get_status(dev, info, wrqu, extra);
-	} else if (!memcmp(wrqu->data.pointer, "role", 4)) {
+	} else if (!memcmp(wrqu_data, "role", 4)) {
 		rtw_p2p_get_role(dev, info, wrqu, extra);
-	} else if (!memcmp(wrqu->data.pointer, "peer_ifa", 8)) {
+	} else if (!memcmp(wrqu_data, "peer_ifa", 8)) {
 		rtw_p2p_get_peer_ifaddr(dev, info, wrqu, extra);
-	} else if (!memcmp(wrqu->data.pointer, "req_cm", 6)) {
+	} else if (!memcmp(wrqu_data, "req_cm", 6)) {
 		rtw_p2p_get_req_cm(dev, info, wrqu, extra);
-	} else if (!memcmp(wrqu->data.pointer, "peer_deva", 9)) {
+	} else if (!memcmp(wrqu_data, "peer_deva", 9)) {
 		/*	Get the P2P device address when receiving the provision discovery request frame. */
 		rtw_p2p_get_peer_devaddr(dev, info, wrqu, extra);
-	} else if (!memcmp(wrqu->data.pointer, "group_id", 8)) {
+	} else if (!memcmp(wrqu_data, "group_id", 8)) {
 		rtw_p2p_get_groupid(dev, info, wrqu, extra);
-	} else if (!memcmp(wrqu->data.pointer, "peer_deva_inv", 9)) {
+	} else if (!memcmp(wrqu_data, "peer_deva_inv", 9)) {
 		/*	Get the P2P device address when receiving the P2P Invitation request frame. */
 		rtw_p2p_get_peer_devaddr_by_invitation(dev, info, wrqu, extra);
-	} else if (!memcmp(wrqu->data.pointer, "op_ch", 5)) {
+	} else if (!memcmp(wrqu_data, "op_ch", 5)) {
 		rtw_p2p_get_op_ch(dev, info, wrqu, extra);
 	}
 	return 0;
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH V2] Fix unsafe memory access by memcmp
  2022-04-04  2:52 [PATCH V2] Fix unsafe memory access by memcmp Charlie Sands
@ 2022-04-04  8:02 ` Michael Straube
  2022-04-04 10:50 ` Dan Carpenter
  2022-04-04 16:33 ` Pavel Skripkin
  2 siblings, 0 replies; 10+ messages in thread
From: Michael Straube @ 2022-04-04  8:02 UTC (permalink / raw)
  To: Charlie Sands, gregkh
  Cc: Larry.Finger, phil, linux-staging, linux-kernel, paskripkin

On 4/4/22 04:52, 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.
> 
>   drivers/staging/r8188eu/os_dep/ioctl_linux.c | 21 ++++++++++++--------
>   1 file changed, 13 insertions(+), 8 deletions(-)
> 

Hi Charlie,

thanks for your patch. Looks good to me, but you should include
staging: r8188eu: in the subject line.

"staging: r8188eu: Fix unsafe memory access by memcmp"

thanks,
Michael

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH V2] Fix unsafe memory access by memcmp
  2022-04-04  2:52 [PATCH V2] Fix unsafe memory access by memcmp Charlie Sands
  2022-04-04  8:02 ` Michael Straube
@ 2022-04-04 10:50 ` Dan Carpenter
  2022-04-04 11:25   ` Fabio M. De Francesco
  2022-04-04 16:33 ` Pavel Skripkin
  2 siblings, 1 reply; 10+ messages in thread
From: Dan Carpenter @ 2022-04-04 10:50 UTC (permalink / raw)
  To: Charlie Sands
  Cc: gregkh, Larry.Finger, phil, linux-staging, linux-kernel, paskripkin

On Sun, Apr 03, 2022 at 10:52:07PM -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.
> 
>  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..4b4eec2bde96 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)
> +		return 0;

return -EFAULT;  We can't assume that that user wants to copy 9 bytes
especially when they're passing a 4 character + NUL string.

This is a custom ioctl.  Called from ioctl_private_iw_point().

I think if you try to dereference a user pointer like this then it will
cause a crash, right?  So that means no one has ever tested or used this
code and we hopefully we can just delete it?

regards,
dan carpenter

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH V2] Fix unsafe memory access by memcmp
  2022-04-04 10:50 ` Dan Carpenter
@ 2022-04-04 11:25   ` Fabio M. De Francesco
  2022-04-04 12:03     ` Dan Carpenter
  0 siblings, 1 reply; 10+ messages in thread
From: Fabio M. De Francesco @ 2022-04-04 11:25 UTC (permalink / raw)
  To: Charlie Sands, Dan Carpenter
  Cc: gregkh, Larry.Finger, phil, linux-staging, linux-kernel, paskripkin

On luned? 4 aprile 2022 12:50:41 CEST Dan Carpenter wrote:
> On Sun, Apr 03, 2022 at 10:52:07PM -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.
> > 
> >  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..4b4eec2bde96 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)
> > +		return 0;
> 
> return -EFAULT;  We can't assume that that user wants to copy 9 bytes
> especially when they're passing a 4 character + NUL string.
> 
> This is a custom ioctl.  Called from ioctl_private_iw_point().
> 
> I think if you try to dereference a user pointer like this then it will
> cause a crash, right?  So that means no one has ever tested or used this
> code and we hopefully we can just delete it?

After a quick look, I'm pretty confident that we can also delete 
rtw_p2p_get2() and rtw_p2p_set() unless I'm overlooking something.

Thanks,

Fabio M. De Francesco




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH V2] Fix unsafe memory access by memcmp
  2022-04-04 11:25   ` Fabio M. De Francesco
@ 2022-04-04 12:03     ` Dan Carpenter
  2022-04-04 14:29       ` Fabio M. De Francesco
  0 siblings, 1 reply; 10+ messages in thread
From: Dan Carpenter @ 2022-04-04 12:03 UTC (permalink / raw)
  To: Fabio M. De Francesco
  Cc: Charlie Sands, gregkh, Larry.Finger, phil, linux-staging,
	linux-kernel, paskripkin

On Mon, Apr 04, 2022 at 01:25:37PM +0200, Fabio M. De Francesco wrote:
> On luned? 4 aprile 2022 12:50:41 CEST Dan Carpenter wrote:
> > On Sun, Apr 03, 2022 at 10:52:07PM -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.
> > > 
> > >  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..4b4eec2bde96 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)
> > > +		return 0;
> > 
> > return -EFAULT;  We can't assume that that user wants to copy 9 bytes
> > especially when they're passing a 4 character + NUL string.
> > 
> > This is a custom ioctl.  Called from ioctl_private_iw_point().
> > 
> > I think if you try to dereference a user pointer like this then it will
> > cause a crash, right?  So that means no one has ever tested or used this
> > code and we hopefully we can just delete it?
> 
> After a quick look, I'm pretty confident that we can also delete 
> rtw_p2p_get2() and rtw_p2p_set() unless I'm overlooking something.

What are the problems with rtw_p2p_get2() and rtw_p2p_set()?

regards,
dan carpenter


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH V2] Fix unsafe memory access by memcmp
  2022-04-04 12:03     ` Dan Carpenter
@ 2022-04-04 14:29       ` Fabio M. De Francesco
  2022-04-04 14:35         ` Dan Carpenter
  2022-04-04 14:36         ` Greg KH
  0 siblings, 2 replies; 10+ messages in thread
From: Fabio M. De Francesco @ 2022-04-04 14:29 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Charlie Sands, gregkh, Larry.Finger, phil, linux-staging,
	linux-kernel, paskripkin

On luned? 4 aprile 2022 14:03:32 CEST Dan Carpenter wrote:
> On Mon, Apr 04, 2022 at 01:25:37PM +0200, Fabio M. De Francesco wrote:
> > On luned? 4 aprile 2022 12:50:41 CEST Dan Carpenter wrote:
> > > On Sun, Apr 03, 2022 at 10:52:07PM -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.
> > > > 
> > > >  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..4b4eec2bde96 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)
> > > > +		return 0;
> > > 
> > > return -EFAULT;  We can't assume that that user wants to copy 9 bytes
> > > especially when they're passing a 4 character + NUL string.
> > > 
> > > This is a custom ioctl.  Called from ioctl_private_iw_point().
> > > 
> > > I think if you try to dereference a user pointer like this then it will
> > > cause a crash, right?  So that means no one has ever tested or used this
> > > code and we hopefully we can just delete it?
> > 
> > After a quick look, I'm pretty confident that we can also delete 
> > rtw_p2p_get2() and rtw_p2p_set() unless I'm overlooking something.
> 
> What are the problems with rtw_p2p_get2() and rtw_p2p_set()?
> 
> regards,
> dan carpenter
> 
Is it safe to access user space pointers without using proper helpers? 
In those cases I mean: is it safe without using copy_from_user()?

As I said, perhaps I'm overlooking something. However my conclusions 
follow by your own argument.

If I understand what you wrote, you asked to delete rtw_p2p_get()
because it looks like nobody "has ever tested or used this code".

rtw_p2p_get2() and rtw_p2p_set() use the same pattern of rtw_p2p_get()
when they access user space without using the proper helpers.

Therefore, I thought that, if you suggest to delete rtw_p2p_get(), why
not also rtw_p2p_set() and rtw_p2p_get2() that use the same unsafe
accesses?

What am I still missing?

Thanks,

Fabio M. De Francesco








^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH V2] Fix unsafe memory access by memcmp
  2022-04-04 14:29       ` Fabio M. De Francesco
@ 2022-04-04 14:35         ` Dan Carpenter
  2022-04-04 14:47           ` Fabio M. De Francesco
  2022-04-04 14:36         ` Greg KH
  1 sibling, 1 reply; 10+ messages in thread
From: Dan Carpenter @ 2022-04-04 14:35 UTC (permalink / raw)
  To: Fabio M. De Francesco
  Cc: Charlie Sands, gregkh, Larry.Finger, phil, linux-staging,
	linux-kernel, paskripkin

On Mon, Apr 04, 2022 at 04:29:48PM +0200, Fabio M. De Francesco wrote:
> On luned? 4 aprile 2022 14:03:32 CEST Dan Carpenter wrote:
> > On Mon, Apr 04, 2022 at 01:25:37PM +0200, Fabio M. De Francesco wrote:
> > > On luned? 4 aprile 2022 12:50:41 CEST Dan Carpenter wrote:
> > > > On Sun, Apr 03, 2022 at 10:52:07PM -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.
> > > > > 
> > > > >  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..4b4eec2bde96 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)
> > > > > +		return 0;
> > > > 
> > > > return -EFAULT;  We can't assume that that user wants to copy 9 bytes
> > > > especially when they're passing a 4 character + NUL string.
> > > > 
> > > > This is a custom ioctl.  Called from ioctl_private_iw_point().
> > > > 
> > > > I think if you try to dereference a user pointer like this then it will
> > > > cause a crash, right?  So that means no one has ever tested or used this
> > > > code and we hopefully we can just delete it?
> > > 
> > > After a quick look, I'm pretty confident that we can also delete 
> > > rtw_p2p_get2() and rtw_p2p_set() unless I'm overlooking something.
> > 
> > What are the problems with rtw_p2p_get2() and rtw_p2p_set()?
> > 
> > regards,
> > dan carpenter
> > 
> Is it safe to access user space pointers without using proper helpers? 

No.

> In those cases I mean: is it safe without using copy_from_user()?

Correct.  You need to use copy_from_user().

> 
> As I said, perhaps I'm overlooking something. However my conclusions 
> follow by your own argument.
> 
> If I understand what you wrote, you asked to delete rtw_p2p_get()
> because it looks like nobody "has ever tested or used this code".
> 
> rtw_p2p_get2() and rtw_p2p_set() use the same pattern of rtw_p2p_get()
> when they access user space without using the proper helpers.

Those functions use "extra" which is a kernel pointer.  Which user
pointer do they use?  Sparse doesn't detect it.

regards,
dan carpenter

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH V2] Fix unsafe memory access by memcmp
  2022-04-04 14:29       ` Fabio M. De Francesco
  2022-04-04 14:35         ` Dan Carpenter
@ 2022-04-04 14:36         ` Greg KH
  1 sibling, 0 replies; 10+ messages in thread
From: Greg KH @ 2022-04-04 14:36 UTC (permalink / raw)
  To: Fabio M. De Francesco
  Cc: Dan Carpenter, Charlie Sands, Larry.Finger, phil, linux-staging,
	linux-kernel, paskripkin

On Mon, Apr 04, 2022 at 04:29:48PM +0200, Fabio M. De Francesco wrote:
> On luned? 4 aprile 2022 14:03:32 CEST Dan Carpenter wrote:
> > On Mon, Apr 04, 2022 at 01:25:37PM +0200, Fabio M. De Francesco wrote:
> > > On luned? 4 aprile 2022 12:50:41 CEST Dan Carpenter wrote:
> > > > On Sun, Apr 03, 2022 at 10:52:07PM -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.
> > > > > 
> > > > >  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..4b4eec2bde96 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)
> > > > > +		return 0;
> > > > 
> > > > return -EFAULT;  We can't assume that that user wants to copy 9 bytes
> > > > especially when they're passing a 4 character + NUL string.
> > > > 
> > > > This is a custom ioctl.  Called from ioctl_private_iw_point().
> > > > 
> > > > I think if you try to dereference a user pointer like this then it will
> > > > cause a crash, right?  So that means no one has ever tested or used this
> > > > code and we hopefully we can just delete it?
> > > 
> > > After a quick look, I'm pretty confident that we can also delete 
> > > rtw_p2p_get2() and rtw_p2p_set() unless I'm overlooking something.
> > 
> > What are the problems with rtw_p2p_get2() and rtw_p2p_set()?
> > 
> > regards,
> > dan carpenter
> > 
> Is it safe to access user space pointers without using proper helpers? 

No.


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH V2] Fix unsafe memory access by memcmp
  2022-04-04 14:35         ` Dan Carpenter
@ 2022-04-04 14:47           ` Fabio M. De Francesco
  0 siblings, 0 replies; 10+ messages in thread
From: Fabio M. De Francesco @ 2022-04-04 14:47 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Charlie Sands, gregkh, Larry.Finger, phil, linux-staging,
	linux-kernel, paskripkin

On luned? 4 aprile 2022 16:35:31 CEST Dan Carpenter wrote:
> On Mon, Apr 04, 2022 at 04:29:48PM +0200, Fabio M. De Francesco wrote:

> > Is it safe to access user space pointers without using proper helpers? 
> 
> No.
> 
> > In those cases I mean: is it safe without using copy_from_user()?
> 
> Correct.  You need to use copy_from_user().
> 
> > 
> > As I said, perhaps I'm overlooking something. However my conclusions 
> > follow by your own argument.
> > 
> > If I understand what you wrote, you asked to delete rtw_p2p_get()
> > because it looks like nobody "has ever tested or used this code".
> > 
> > rtw_p2p_get2() and rtw_p2p_set() use the same pattern of rtw_p2p_get()
> > when they access user space without using the proper helpers.
> 
> Those functions use "extra" which is a kernel pointer.  Which user
> pointer do they use?  Sparse doesn't detect it.

You're right, sorry. This is what I had overlooked. I took a brief look
(just 5 seconds or something) and saw the same arguments that 
rtw_p2p_get() takes and then a long list of calls to memcmp().

I overlooked that they were called using the 4th argument ("extra").

Sorry for the noise.

Fabio

 



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH V2] Fix unsafe memory access by memcmp
  2022-04-04  2:52 [PATCH V2] Fix unsafe memory access by memcmp Charlie Sands
  2022-04-04  8:02 ` Michael Straube
  2022-04-04 10:50 ` Dan Carpenter
@ 2022-04-04 16:33 ` Pavel Skripkin
  2 siblings, 0 replies; 10+ messages in thread
From: Pavel Skripkin @ 2022-04-04 16:33 UTC (permalink / raw)
  To: Charlie Sands, gregkh; +Cc: Larry.Finger, phil, linux-staging, linux-kernel


[-- Attachment #1.1: Type: text/plain, Size: 1414 bytes --]

Hi Charlie,

On 4/4/22 05:52, 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.
> 

You did not improved error handling of copy_from_user() as I suggested. 
if (expr) and if (expr != 0) are exactly the same

>   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..4b4eec2bde96 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)
> +		return 0;
> +

I've suggested to return -EFAULT here




With regards,
Pavel Skripkin

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 840 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2022-04-04 21:49 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-04  2:52 [PATCH V2] Fix unsafe memory access by memcmp Charlie Sands
2022-04-04  8:02 ` Michael Straube
2022-04-04 10:50 ` Dan Carpenter
2022-04-04 11:25   ` Fabio M. De Francesco
2022-04-04 12:03     ` Dan Carpenter
2022-04-04 14:29       ` Fabio M. De Francesco
2022-04-04 14:35         ` Dan Carpenter
2022-04-04 14:47           ` Fabio M. De Francesco
2022-04-04 14:36         ` Greg KH
2022-04-04 16:33 ` Pavel Skripkin

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).