Upon running sparse, "warning: incorrect type in argument 1 (different address spaces)
is brought to notice for this file.let's add correct typecast to make it cleaner and
silence the Sparse warning.
Signed-off-by: Ashish Kalra <[email protected]>
---
drivers/staging/wlan-ng/p80211netdev.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/staging/wlan-ng/p80211netdev.c b/drivers/staging/wlan-ng/p80211netdev.c
index 6f9666dc0277..70570e8a5ad2 100644
--- a/drivers/staging/wlan-ng/p80211netdev.c
+++ b/drivers/staging/wlan-ng/p80211netdev.c
@@ -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;
--
2.25.1
On Tue, Apr 20, 2021 at 02:31:42PM +0530, Ashish Kalra wrote:
> Upon running sparse, "warning: incorrect type in argument 1 (different address spaces)
> is brought to notice for this file.let's add correct typecast to make it cleaner and
> silence the Sparse warning.
>
> Signed-off-by: Ashish Kalra <[email protected]>
> ---
> drivers/staging/wlan-ng/p80211netdev.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/staging/wlan-ng/p80211netdev.c b/drivers/staging/wlan-ng/p80211netdev.c
> index 6f9666dc0277..70570e8a5ad2 100644
> --- a/drivers/staging/wlan-ng/p80211netdev.c
> +++ b/drivers/staging/wlan-ng/p80211netdev.c
> @@ -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);
Why isn't data being declared as a __user pointer to start with? Why is
the cast needed here?
This feels wrong as if it is papering over the real problem.
thanks,
greg k-h
On Thu, Apr 22, 2021 at 10:43:13AM +0200, Greg Kroah-Hartman wrote:
> On Tue, Apr 20, 2021 at 02:31:42PM +0530, Ashish Kalra wrote:
> > Upon running sparse, "warning: incorrect type in argument 1 (different address spaces)
> > is brought to notice for this file.let's add correct typecast to make it cleaner and
> > silence the Sparse warning.
> >
> > Signed-off-by: Ashish Kalra <[email protected]>
> > ---
> > drivers/staging/wlan-ng/p80211netdev.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/drivers/staging/wlan-ng/p80211netdev.c b/drivers/staging/wlan-ng/p80211netdev.c
> > index 6f9666dc0277..70570e8a5ad2 100644
> > --- a/drivers/staging/wlan-ng/p80211netdev.c
> > +++ b/drivers/staging/wlan-ng/p80211netdev.c
> > @@ -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);
>
> Why isn't data being declared as a __user pointer to start with? Why is
> the cast needed here?
>
> This feels wrong as if it is papering over the real problem.
>
> thanks,
>
> greg k-h
Thanks for your inputs
variable data in structure p80211ioctl_req is used only inside this function and is
already casted to void __user * for copy_to_user. Should it be changed
to void __user from caadr_t inside p80211ioctl.h. it should be same at runtime
--- a/drivers/staging/wlan-ng/p80211ioctl.h
+++ b/drivers/staging/wlan-ng/p80211ioctl.h
@@ -81,7 +81,7 @@
struct p80211ioctl_req {
char name[WLAN_DEVNAMELEN_MAX];
- caddr_t data;
+ void __user *data;
Does this looks ok to you and is there any other check possible if this is ok?
Regards
Ashish
On Fri, Apr 23, 2021 at 08:56:19PM +0530, Ashish Kalra wrote:
> On Thu, Apr 22, 2021 at 10:43:13AM +0200, Greg Kroah-Hartman wrote:
> > On Tue, Apr 20, 2021 at 02:31:42PM +0530, Ashish Kalra wrote:
> > > Upon running sparse, "warning: incorrect type in argument 1 (different address spaces)
> > > is brought to notice for this file.let's add correct typecast to make it cleaner and
> > > silence the Sparse warning.
> > >
> > > Signed-off-by: Ashish Kalra <[email protected]>
> > > ---
> > > drivers/staging/wlan-ng/p80211netdev.c | 2 +-
> > > 1 file changed, 1 insertion(+), 1 deletion(-)
> > >
> > > diff --git a/drivers/staging/wlan-ng/p80211netdev.c b/drivers/staging/wlan-ng/p80211netdev.c
> > > index 6f9666dc0277..70570e8a5ad2 100644
> > > --- a/drivers/staging/wlan-ng/p80211netdev.c
> > > +++ b/drivers/staging/wlan-ng/p80211netdev.c
> > > @@ -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);
> >
> > Why isn't data being declared as a __user pointer to start with? Why is
> > the cast needed here?
> >
> > This feels wrong as if it is papering over the real problem.
> >
> > thanks,
> >
> > greg k-h
> Thanks for your inputs
> variable data in structure p80211ioctl_req is used only inside this function and is
> already casted to void __user * for copy_to_user. Should it be changed
> to void __user from caadr_t inside p80211ioctl.h. it should be same at runtime
>
> --- a/drivers/staging/wlan-ng/p80211ioctl.h
> +++ b/drivers/staging/wlan-ng/p80211ioctl.h
> @@ -81,7 +81,7 @@
>
> struct p80211ioctl_req {
> char name[WLAN_DEVNAMELEN_MAX];
> - caddr_t data;
> + void __user *data;
>
> Does this looks ok to you and is there any other check possible if this is ok?
THat looks better. What does running sparse on that change show?
thanks,
greg k-h
On Fri, Apr 23, 2021 at 08:56:19PM +0530, Ashish Kalra wrote:
> On Thu, Apr 22, 2021 at 10:43:13AM +0200, Greg Kroah-Hartman wrote:
> > On Tue, Apr 20, 2021 at 02:31:42PM +0530, Ashish Kalra wrote:
> > > Upon running sparse, "warning: incorrect type in argument 1 (different address spaces)
> > > is brought to notice for this file.let's add correct typecast to make it cleaner and
> > > silence the Sparse warning.
> > >
> > > Signed-off-by: Ashish Kalra <[email protected]>
> > > ---
> > > drivers/staging/wlan-ng/p80211netdev.c | 2 +-
> > > 1 file changed, 1 insertion(+), 1 deletion(-)
> > >
> > > diff --git a/drivers/staging/wlan-ng/p80211netdev.c b/drivers/staging/wlan-ng/p80211netdev.c
> > > index 6f9666dc0277..70570e8a5ad2 100644
> > > --- a/drivers/staging/wlan-ng/p80211netdev.c
> > > +++ b/drivers/staging/wlan-ng/p80211netdev.c
> > > @@ -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);
> >
> > Why isn't data being declared as a __user pointer to start with? Why is
> > the cast needed here?
> >
> > This feels wrong as if it is papering over the real problem.
> >
> > thanks,
> >
> > greg k-h
> Thanks for your inputs
> variable data in structure p80211ioctl_req is used only inside this function and is
> already casted to void __user * for copy_to_user. Should it be changed
> to void __user from caadr_t inside p80211ioctl.h. it should be same at runtime
>
> --- a/drivers/staging/wlan-ng/p80211ioctl.h
> +++ b/drivers/staging/wlan-ng/p80211ioctl.h
> @@ -81,7 +81,7 @@
>
> struct p80211ioctl_req {
> char name[WLAN_DEVNAMELEN_MAX];
> - caddr_t data;
> + void __user *data;
>
> Does this looks ok to you and is there any other check possible if this is ok?
Wait, what is "caddr_t"? Try unwinding that mess first...
On Sat, 2021-04-24 at 08:00 +0200, Greg Kroah-Hartman wrote:
> On Fri, Apr 23, 2021 at 08:56:19PM +0530, Ashish Kalra wrote:
> > On Thu, Apr 22, 2021 at 10:43:13AM +0200, Greg Kroah-Hartman wrote:
> > > On Tue, Apr 20, 2021 at 02:31:42PM +0530, Ashish Kalra wrote:
> > > > Upon running sparse, "warning: incorrect type in argument 1 (different address spaces)
> > > > is brought to notice for this file.let's add correct typecast to make it cleaner and
> > > > silence the Sparse warning.
[]
> > ?struct p80211ioctl_req {
> > ????????char name[WLAN_DEVNAMELEN_MAX];
> > - caddr_t data;
> > + void __user *data;
> >
> > Does this looks ok to you and is there any other check possible if this is ok?
>
> Wait, what is "caddr_t"? Try unwinding that mess first...
Might not be that simple.
include/linux/types.h:typedef __kernel_caddr_t caddr_t;
include/uapi/linux/coda.h:typedef void * caddr_t;
include/uapi/asm-generic/posix_types.h:typedef char * __kernel_caddr_t;
On Fri, Apr 23, 2021 at 11:11:05PM -0700, Joe Perches wrote:
> On Sat, 2021-04-24 at 08:00 +0200, Greg Kroah-Hartman wrote:
> > On Fri, Apr 23, 2021 at 08:56:19PM +0530, Ashish Kalra wrote:
> > > On Thu, Apr 22, 2021 at 10:43:13AM +0200, Greg Kroah-Hartman wrote:
> > > > On Tue, Apr 20, 2021 at 02:31:42PM +0530, Ashish Kalra wrote:
> > > > > Upon running sparse, "warning: incorrect type in argument 1 (different address spaces)
> > > > > is brought to notice for this file.let's add correct typecast to make it cleaner and
> > > > > silence the Sparse warning.
> []
> > > ?struct p80211ioctl_req {
> > > ????????char name[WLAN_DEVNAMELEN_MAX];
> > > - caddr_t data;
> > > + void __user *data;
> > >
> > > Does this looks ok to you and is there any other check possible if this is ok?
> >
> > Wait, what is "caddr_t"? Try unwinding that mess first...
>
> Might not be that simple.
>
> include/linux/types.h:typedef __kernel_caddr_t caddr_t;
> include/uapi/linux/coda.h:typedef void * caddr_t;
> include/uapi/asm-generic/posix_types.h:typedef char * __kernel_caddr_t;
>
>
data is part of p80211ioctl_req and is used at two places only inside p80211knetdev_do_ioctl
it seems both places it will be used as void __user* only
msgbuf = memdup_user(req->data, req->len);
if (result == 0) {
if (copy_to_user
((void __user *)req->data, msgbuf, req->len)) {
result = -EFAULT;
}
}
Will it still be problem if we change it from char * to void *.?
is there any way to check how caller of this function will be using it?
On Sat, Apr 24, 2021 at 01:45:29PM +0530, Ashish Kalra wrote:
> On Fri, Apr 23, 2021 at 11:11:05PM -0700, Joe Perches wrote:
> > On Sat, 2021-04-24 at 08:00 +0200, Greg Kroah-Hartman wrote:
> > > On Fri, Apr 23, 2021 at 08:56:19PM +0530, Ashish Kalra wrote:
> > > > On Thu, Apr 22, 2021 at 10:43:13AM +0200, Greg Kroah-Hartman wrote:
> > > > > On Tue, Apr 20, 2021 at 02:31:42PM +0530, Ashish Kalra wrote:
> > > > > > Upon running sparse, "warning: incorrect type in argument 1 (different address spaces)
> > > > > > is brought to notice for this file.let's add correct typecast to make it cleaner and
> > > > > > silence the Sparse warning.
> > []
> > > > ?struct p80211ioctl_req {
> > > > ????????char name[WLAN_DEVNAMELEN_MAX];
> > > > - caddr_t data;
> > > > + void __user *data;
> > > >
> > > > Does this looks ok to you and is there any other check possible if this is ok?
> > >
> > > Wait, what is "caddr_t"? Try unwinding that mess first...
> >
> > Might not be that simple.
> >
> > include/linux/types.h:typedef __kernel_caddr_t caddr_t;
> > include/uapi/linux/coda.h:typedef void * caddr_t;
> > include/uapi/asm-generic/posix_types.h:typedef char * __kernel_caddr_t;
> >
> >
> data is part of p80211ioctl_req and is used at two places only inside p80211knetdev_do_ioctl
> it seems both places it will be used as void __user* only
>
> msgbuf = memdup_user(req->data, req->len);
>
> if (result == 0) {
> if (copy_to_user
> ((void __user *)req->data, msgbuf, req->len)) {
> result = -EFAULT;
> }
> }
>
> Will it still be problem if we change it from char * to void *.?
Why do you want to change it to void *? Never use a void * unless it
has to point to unknown data. That does not seem the case here.
> is there any way to check how caller of this function will be using it?
Look at the code to determine this...
thanks,
greg k-h
On Sat, Apr 24, 2021 at 10:28:27AM +0200, Greg Kroah-Hartman wrote:
> On Sat, Apr 24, 2021 at 01:45:29PM +0530, Ashish Kalra wrote:
> > On Fri, Apr 23, 2021 at 11:11:05PM -0700, Joe Perches wrote:
> > > On Sat, 2021-04-24 at 08:00 +0200, Greg Kroah-Hartman wrote:
> > > > On Fri, Apr 23, 2021 at 08:56:19PM +0530, Ashish Kalra wrote:
> > > > > On Thu, Apr 22, 2021 at 10:43:13AM +0200, Greg Kroah-Hartman wrote:
> > > > > > On Tue, Apr 20, 2021 at 02:31:42PM +0530, Ashish Kalra wrote:
> > > > > > > Upon running sparse, "warning: incorrect type in argument 1 (different address spaces)
> > > > > > > is brought to notice for this file.let's add correct typecast to make it cleaner and
> > > > > > > silence the Sparse warning.
> > > []
> > > > > ?struct p80211ioctl_req {
> > > > > ????????char name[WLAN_DEVNAMELEN_MAX];
> > > > > - caddr_t data;
> > > > > + void __user *data;
> > > > >
> > > > > Does this looks ok to you and is there any other check possible if this is ok?
> > > >
> > > > Wait, what is "caddr_t"? Try unwinding that mess first...
> > >
> > > Might not be that simple.
> > >
> > > include/linux/types.h:typedef __kernel_caddr_t caddr_t;
> > > include/uapi/linux/coda.h:typedef void * caddr_t;
> > > include/uapi/asm-generic/posix_types.h:typedef char * __kernel_caddr_t;
> > >
> > >
> > data is part of p80211ioctl_req and is used at two places only inside p80211knetdev_do_ioctl
> > it seems both places it will be used as void __user* only
> >
> > msgbuf = memdup_user(req->data, req->len);
> >
> > if (result == 0) {
> > if (copy_to_user
> > ((void __user *)req->data, msgbuf, req->len)) {
> > result = -EFAULT;
> > }
> > }
> >
> > Will it still be problem if we change it from char * to void *.?
>
> Why do you want to change it to void *? Never use a void * unless it
> has to point to unknown data. That does not seem the case here.
>
> > is there any way to check how caller of this function will be using it?
>
> Look at the code to determine this...
>
> thanks,
>
> greg k-h
Thanks Greg and Joe
I have found that adding __user to data is also fixing this warning,
It should be fine logically to make this change
Please share your opinion and will post v2 for this patch
--- a/drivers/staging/wlan-ng/p80211ioctl.h
+++ b/drivers/staging/wlan-ng/p80211ioctl.h
@@ -81,7 +81,7 @@
struct p80211ioctl_req {
char name[WLAN_DEVNAMELEN_MAX];
- caddr_t data;
+ char __user *data;
u32 magic;
u16 len;
u32 result;
--
2.30.2
On Tue, Apr 27, 2021 at 05:53:30PM +0530, ashish wrote:
> On Sat, Apr 24, 2021 at 10:28:27AM +0200, Greg Kroah-Hartman wrote:
> > On Sat, Apr 24, 2021 at 01:45:29PM +0530, Ashish Kalra wrote:
> > > On Fri, Apr 23, 2021 at 11:11:05PM -0700, Joe Perches wrote:
> > > > On Sat, 2021-04-24 at 08:00 +0200, Greg Kroah-Hartman wrote:
> > > > > On Fri, Apr 23, 2021 at 08:56:19PM +0530, Ashish Kalra wrote:
> > > > > > On Thu, Apr 22, 2021 at 10:43:13AM +0200, Greg Kroah-Hartman wrote:
> > > > > > > On Tue, Apr 20, 2021 at 02:31:42PM +0530, Ashish Kalra wrote:
> > > > > > > > Upon running sparse, "warning: incorrect type in argument 1 (different address spaces)
> > > > > > > > is brought to notice for this file.let's add correct typecast to make it cleaner and
> > > > > > > > silence the Sparse warning.
> > > > []
> > > > > > ?struct p80211ioctl_req {
> > > > > > ????????char name[WLAN_DEVNAMELEN_MAX];
> > > > > > - caddr_t data;
> > > > > > + void __user *data;
> > > > > >
> > > > > > Does this looks ok to you and is there any other check possible if this is ok?
> > > > >
> > > > > Wait, what is "caddr_t"? Try unwinding that mess first...
> > > >
> > > > Might not be that simple.
> > > >
> > > > include/linux/types.h:typedef __kernel_caddr_t caddr_t;
> > > > include/uapi/linux/coda.h:typedef void * caddr_t;
> > > > include/uapi/asm-generic/posix_types.h:typedef char * __kernel_caddr_t;
> > > >
> > > >
> > > data is part of p80211ioctl_req and is used at two places only inside p80211knetdev_do_ioctl
> > > it seems both places it will be used as void __user* only
> > >
> > > msgbuf = memdup_user(req->data, req->len);
> > >
> > > if (result == 0) {
> > > if (copy_to_user
> > > ((void __user *)req->data, msgbuf, req->len)) {
> > > result = -EFAULT;
> > > }
> > > }
> > >
> > > Will it still be problem if we change it from char * to void *.?
> >
> > Why do you want to change it to void *? Never use a void * unless it
> > has to point to unknown data. That does not seem the case here.
> >
> > > is there any way to check how caller of this function will be using it?
> >
> > Look at the code to determine this...
> >
> > thanks,
> >
> > greg k-h
> Thanks Greg and Joe
> I have found that adding __user to data is also fixing this warning,
> It should be fine logically to make this change
> Please share your opinion and will post v2 for this patch
>
> --- a/drivers/staging/wlan-ng/p80211ioctl.h
> +++ b/drivers/staging/wlan-ng/p80211ioctl.h
> @@ -81,7 +81,7 @@
>
> struct p80211ioctl_req {
> char name[WLAN_DEVNAMELEN_MAX];
> - caddr_t data;
> + char __user *data;
> u32 magic;
> u16 len;
> u32 result;
> --
> 2.30.2
>
>
>
What do you think, try it and see and if you think it is correct, please
submit that change. Don't wait for us...
thanks,
greg k-h