2017-08-23 22:29:58

by Bart Van Assche

[permalink] [raw]
Subject: [PATCH 0/2] Two copy_in_user() declaration fixes

Hello Al,

When I analyzed the block layer core with sparse I noticed that the declaration
of copy_in_user() and also that of a pointer in compat_hdio_ioctl() are wrong.
Please consider these two patches for kernel v4.14.

Thanks,

Bart.

Bart Van Assche (2):
<linux/uaccess.h>: Fix copy_in_user() declaration
compat_hdio_ioctl: Fix a declaration

block/compat_ioctl.c | 2 +-
include/linux/uaccess.h | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)

--
2.14.0


2017-08-23 22:30:28

by Bart Van Assche

[permalink] [raw]
Subject: [PATCH 1/2] <linux/uaccess.h>: Fix copy_in_user() declaration

copy_in_user() copies data from user-space address @from to user-
space address @to. Hence declare both @from and @to as user-space
pointers.

Fixes: commit d597580d3737 ("generic ...copy_..._user primitives")
Signed-off-by: Bart Van Assche <[email protected]>
Cc: <[email protected]>
---
include/linux/uaccess.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
index acdd6f915a8d..20ef8e6ec2db 100644
--- a/include/linux/uaccess.h
+++ b/include/linux/uaccess.h
@@ -156,7 +156,7 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
}
#ifdef CONFIG_COMPAT
static __always_inline unsigned long __must_check
-copy_in_user(void __user *to, const void *from, unsigned long n)
+copy_in_user(void __user *to, const void __user *from, unsigned long n)
{
might_fault();
if (access_ok(VERIFY_WRITE, to, n) && access_ok(VERIFY_READ, from, n))
--
2.14.0

2017-08-23 22:30:43

by Bart Van Assche

[permalink] [raw]
Subject: [PATCH 2/2] compat_hdio_ioctl: Fix a declaration

This patch avoids that sparse reports the following warning messages:

block/compat_ioctl.c:85:11: warning: incorrect type in assignment (different address spaces)
block/compat_ioctl.c:85:11: expected unsigned long *[noderef] <asn:1>p
block/compat_ioctl.c:85:11: got void [noderef] <asn:1>*
block/compat_ioctl.c:91:21: warning: incorrect type in argument 1 (different address spaces)
block/compat_ioctl.c:91:21: expected void const volatile [noderef] <asn:1>*<noident>
block/compat_ioctl.c:91:21: got unsigned long *[noderef] <asn:1>p
block/compat_ioctl.c:87:53: warning: dereference of noderef expression
block/compat_ioctl.c:91:21: warning: dereference of noderef expression

Fixes: commit d597580d3737 ("generic ...copy_..._user primitives")
Signed-off-by: Bart Van Assche <[email protected]>
Cc: Jens Axboe <[email protected]>
---
block/compat_ioctl.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
index 38554c2ea38a..abaf9d78a206 100644
--- a/block/compat_ioctl.c
+++ b/block/compat_ioctl.c
@@ -79,7 +79,7 @@ static int compat_hdio_getgeo(struct gendisk *disk, struct block_device *bdev,
static int compat_hdio_ioctl(struct block_device *bdev, fmode_t mode,
unsigned int cmd, unsigned long arg)
{
- unsigned long *__user p;
+ unsigned long __user *p;
int error;

p = compat_alloc_user_space(sizeof(unsigned long));
--
2.14.0

2017-08-24 14:40:43

by Jens Axboe

[permalink] [raw]
Subject: Re: [PATCH 2/2] compat_hdio_ioctl: Fix a declaration

On 08/23/2017 04:29 PM, Bart Van Assche wrote:
> This patch avoids that sparse reports the following warning messages:
>
> block/compat_ioctl.c:85:11: warning: incorrect type in assignment (different address spaces)
> block/compat_ioctl.c:85:11: expected unsigned long *[noderef] <asn:1>p
> block/compat_ioctl.c:85:11: got void [noderef] <asn:1>*
> block/compat_ioctl.c:91:21: warning: incorrect type in argument 1 (different address spaces)
> block/compat_ioctl.c:91:21: expected void const volatile [noderef] <asn:1>*<noident>
> block/compat_ioctl.c:91:21: got unsigned long *[noderef] <asn:1>p
> block/compat_ioctl.c:87:53: warning: dereference of noderef expression
> block/compat_ioctl.c:91:21: warning: dereference of noderef expression

Applied for 4.14, thanks Bart.

--
Jens Axboe

2017-08-31 21:22:25

by Bart Van Assche

[permalink] [raw]
Subject: Re: [PATCH 1/2] <linux/uaccess.h>: Fix copy_in_user() declaration

On Wed, 2017-08-23 at 15:29 -0700, Bart Van Assche wrote:
> copy_in_user() copies data from user-space address @from to user-
> space address @to. Hence declare both @from and @to as user-space
> pointers.
> [ ... ]

Hi Al,

Can you have a look at this patch? Patch 2/2 from this series already got
queued for kernel v4.14 by Jens.

Thanks,

Bart.

2017-08-31 21:24:10

by Al Viro

[permalink] [raw]
Subject: Re: [PATCH 1/2] <linux/uaccess.h>: Fix copy_in_user() declaration

On Thu, Aug 31, 2017 at 09:21:37PM +0000, Bart Van Assche wrote:
> On Wed, 2017-08-23 at 15:29 -0700, Bart Van Assche wrote:
> > copy_in_user() copies data from user-space address @from to user-
> > space address @to. Hence declare both @from and @to as user-space
> > pointers.
> > [ ... ]
>
> Hi Al,
>
> Can you have a look at this patch? Patch 2/2 from this series already got
> queued for kernel v4.14 by Jens.

Yes, it's in #for-linus in my local tree.