Skip to contentSkip to conversation

staging: wlan-ng: Fixed incorrect type warning in p80211netdev.c

PATCH In review Pritthijit Nath 4 participants 5 messages Feb 17, 2021 – Feb 19, 2021 Staging

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 staging: wlan-ng: Fixed incorrect type warning in p80211netdev.c

This change fixes a sparse warning "incorrect type in argument 1 (different address spaces)".

---
 drivers/staging/wlan-ng/p80211netdev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/wlan-ng/p80211netdev.c +1 -1
index 6f9666dc0277..70570e8a5ad2 100644
@@ -569,7 +569,7 @@ static int p80211knetdev_do_ioctl(struct net_device *dev,
 		goto bail;
 	}
 
-	msgbuf = memdup_user(req->data, req->len);
+	msgbuf = memdup_user((void __user *)req->data, req->len);
 	if (IS_ERR(msgbuf)) {
 		result = PTR_ERR(msgbuf);
 		goto bail;
Signature · 1 line
2.25.1
maintainer
#1 lore raw
Quoted 13 lines · Pritthijit Nath

This change fixes a sparse warning "incorrect type in argument 1 (different address spaces)".

---
 drivers/staging/wlan-ng/p80211netdev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/wlan-ng/p80211netdev.c +0 -0
index 6f9666dc0277..70570e8a5ad2 100644

drivers/staging/wlan-ng/p80211netdev.c static int p80211knetdev_do_ioctl(struct net_device *dev, · line 572

Quoted 5 lines
drivers/staging/wlan-ng/p80211netdev.c +1 -1
@@ -569,7 +569,7 @@ static int p80211knetdev_do_ioctl(struct net_device *dev,
 		goto bail;
 	}
 
-	msgbuf = memdup_user(req->data, req->len);
+	msgbuf = memdup_user((void __user *)req->data, req->len);

Odd. Why isn't data tagged as a __user pointer to start with?

thanks,

greg k-h

#2 lore raw
Quoted 17 lines · Greg KH
Quoted 16 lines · Pritthijit Nath

This change fixes a sparse warning "incorrect type in argument 1 (different address spaces)".

---
 drivers/staging/wlan-ng/p80211netdev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/wlan-ng/p80211netdev.c +0 -0
index 6f9666dc0277..70570e8a5ad2 100644
@@ -569,7 +569,7 @@ static int p80211knetdev_do_ioctl(struct net_device *dev,
 		goto bail;
 	}
 
Quoted 9 lines

drivers/staging/wlan-ng/p80211netdev.c static int p80211knetdev_do_ioctl(struct net_device *dev, · line 572

Quoted 2 lines
drivers/staging/wlan-ng/p80211netdev.c +1 -1
-	msgbuf = memdup_user(req->data, req->len);
+	msgbuf = memdup_user((void __user *)req->data, req->len);

Odd. Why isn't data tagged as a __user pointer to start with?

thanks,

greg k-h

In lines 540-548 ->

...

static int p80211knetdev_do_ioctl(struct net_device *dev,
struct ifreq *ifr, int cmd)

{
        int result = 0;
        struct p80211ioctl_req *req = (struct p80211ioctl_req *)ifr;
        struct wlandevice *wlandev = dev->ml_priv;
        u8 *msgbuf;

        netdev_dbg(dev, "rx'd ioctl, cmd=%d, len=%d\n", cmd, req->len);

...

it can be seen that *req is essentially coming from an explicit cast of *ifr. ifr->data itself is of char* type. So, imo, an explicit __user pointer cast is required.

The patch above was based on the __user pointer cast done in lines 580-586 ->

...

if (result == 0) {
                if (copy_to_user
                    ((void __user *)req->data, msgbuf, req->len)) {
                        result = -EFAULT;
                }
        }
        kfree(msgbuf);

...

and lines 550-556 ->

#ifdef SIOCETHTOOL
        if (cmd == SIOCETHTOOL) {
                result =
                    p80211netdev_ethtool(wlandev, (void __user *)ifr->ifr_data);
                goto bail;
        }

#endif

#3 lore raw
In reply to Pritthijit Nath
Quoted 13 lines · Pritthijit Nath

This change fixes a sparse warning "incorrect type in argument 1 (different address spaces)".

---
 drivers/staging/wlan-ng/p80211netdev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/wlan-ng/p80211netdev.c +0 -0
index 6f9666dc0277..70570e8a5ad2 100644

drivers/staging/wlan-ng/p80211netdev.c static int p80211knetdev_do_ioctl(struct net_device *dev, · line 572

Quoted 5 lines
drivers/staging/wlan-ng/p80211netdev.c +1 -1
@@ -569,7 +569,7 @@ static int p80211knetdev_do_ioctl(struct net_device *dev,
 		goto bail;
 	}
 
-	msgbuf = memdup_user(req->data, req->len);
+	msgbuf = memdup_user((void __user *)req->data, req->len);

Probably the correct fix is to just change the type of (struct p80211ioctl_req)->data from caddr_t to "void __user *data;".

I haven't looked at this though, so double check.

regards,
dan carpenter

Reviewed-by on v1 1/1
#4 lore raw
In reply to Pritthijit Nath
Quoted 14 lines · pritthijit.nath at icloud.com (Pritthijit Nath)

This change fixes a sparse warning "incorrect type in argument 1 (different address spaces)".

Signed-off-by Pritthijit Nath <pritthijit.nath at icloud.com>
---
  drivers/staging/wlan-ng/p80211netdev.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/wlan-ng/p80211netdev.c +0 -0
index 6f9666dc0277..70570e8a5ad2 100644

drivers/staging/wlan-ng/p80211netdev.c static int p80211knetdev_do_ioctl(struct net_device *dev, · line 575

Quoted 8 lines
drivers/staging/wlan-ng/p80211netdev.c +1 -1
@@ -569,7 +569,7 @@ static int p80211knetdev_do_ioctl(struct net_device *dev,
                 goto bail;
         }
 
-       msgbuf = memdup_user(req->data, req->len);
+       msgbuf = memdup_user((void __user *)req->data, req->len);
         if (IS_ERR(msgbuf)) {
                 result = PTR_ERR(msgbuf);
                 goto bail;