All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] staging: r8188eu: Fix unsafe memory access by memcmp.
@ 2022-04-01 20:12 Charlie Sands
  2022-04-03 11:15 ` Greg KH
  2022-04-03 11:20 ` Pavel Skripkin
  0 siblings, 2 replies; 3+ messages in thread
From: Charlie Sands @ 2022-04-01 20:12 UTC (permalink / raw)
  To: gregkh; +Cc: Larry.Finger, phil, linux-staging, linux-kernel

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>
---
 drivers/staging/r8188eu/os_dep/ioctl_linux.c | 20 ++++++++++++--------
 1 file changed, 12 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..1cfac1b27eb7 100644
--- a/drivers/staging/r8188eu/os_dep/ioctl_linux.c
+++ b/drivers/staging/r8188eu/os_dep/ioctl_linux.c
@@ -3233,23 +3233,27 @@ 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_ptr[9];
+	if (copy_from_user(wrqu_data_ptr, wrqu->data.pointer, 9))
+		return 0;
+
+	if (!memcmp(wrqu_data_ptr, "status", 6)) {
 		rtw_p2p_get_status(dev, info, wrqu, extra);
-	} else if (!memcmp(wrqu->data.pointer, "role", 4)) {
+	} else if (!memcmp(wrqu_data_ptr, "role", 4)) {
 		rtw_p2p_get_role(dev, info, wrqu, extra);
-	} else if (!memcmp(wrqu->data.pointer, "peer_ifa", 8)) {
+	} else if (!memcmp(wrqu_data_ptr, "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_ptr, "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_ptr, "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_ptr, "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_ptr, "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_ptr, "op_ch", 5)) {
 		rtw_p2p_get_op_ch(dev, info, wrqu, extra);
 	}
 	return 0;
-- 
2.35.1


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

* Re: [PATCH] staging: r8188eu: Fix unsafe memory access by memcmp.
  2022-04-01 20:12 [PATCH] staging: r8188eu: Fix unsafe memory access by memcmp Charlie Sands
@ 2022-04-03 11:15 ` Greg KH
  2022-04-03 11:20 ` Pavel Skripkin
  1 sibling, 0 replies; 3+ messages in thread
From: Greg KH @ 2022-04-03 11:15 UTC (permalink / raw)
  To: Charlie Sands; +Cc: Larry.Finger, phil, linux-staging, linux-kernel

On Fri, Apr 01, 2022 at 04:12:47PM -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>
> ---
>  drivers/staging/r8188eu/os_dep/ioctl_linux.c | 20 ++++++++++++--------
>  1 file changed, 12 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..1cfac1b27eb7 100644
> --- a/drivers/staging/r8188eu/os_dep/ioctl_linux.c
> +++ b/drivers/staging/r8188eu/os_dep/ioctl_linux.c
> @@ -3233,23 +3233,27 @@ 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_ptr[9];
> +	if (copy_from_user(wrqu_data_ptr, wrqu->data.pointer, 9))
> +		return 0;

Please do not add checkpatch issues when trying to fix up other issues
:(

And that's a very odd variable name you are creating.  That is not a
pointer at all, and either way, it should not be part of a variable
name, this isn't Windows code :)

thanks,

greg k-h

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

* Re: [PATCH] staging: r8188eu: Fix unsafe memory access by memcmp.
  2022-04-01 20:12 [PATCH] staging: r8188eu: Fix unsafe memory access by memcmp Charlie Sands
  2022-04-03 11:15 ` Greg KH
@ 2022-04-03 11:20 ` Pavel Skripkin
  1 sibling, 0 replies; 3+ messages in thread
From: Pavel Skripkin @ 2022-04-03 11:20 UTC (permalink / raw)
  To: Charlie Sands, gregkh; +Cc: Larry.Finger, phil, linux-staging, linux-kernel

Hi Charlie,

On 4/1/22 23:12, 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>
> ---
>   drivers/staging/r8188eu/os_dep/ioctl_linux.c | 20 ++++++++++++--------
>   1 file changed, 12 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..1cfac1b27eb7 100644
> --- a/drivers/staging/r8188eu/os_dep/ioctl_linux.c
> +++ b/drivers/staging/r8188eu/os_dep/ioctl_linux.c
> @@ -3233,23 +3233,27 @@ 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_ptr[9];
> +	if (copy_from_user(wrqu_data_ptr, wrqu->data.pointer, 9))
> +		return 0;

-EFAULT is standard return value in case of `copy_{to_from}_user` failure



With regards,
Pavel Skripkin

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

end of thread, other threads:[~2022-04-03 11:20 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-04-01 20:12 [PATCH] staging: r8188eu: Fix unsafe memory access by memcmp Charlie Sands
2022-04-03 11:15 ` Greg KH
2022-04-03 11:20 ` Pavel Skripkin

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.