Current implemantation ptr argument evaluate 2 times.
It'll be an unexpected result.
Signed-off-by: Yoshinori Sato <[email protected]>
---
include/asm-generic/uaccess.h | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/include/asm-generic/uaccess.h b/include/asm-generic/uaccess.h
index 72d8803..1b813fb 100644
--- a/include/asm-generic/uaccess.h
+++ b/include/asm-generic/uaccess.h
@@ -163,9 +163,10 @@ static inline __must_check long __copy_to_user(void __user *to,
#define put_user(x, ptr) \
({ \
+ __typeof__((ptr)) __p = (ptr); \
might_fault(); \
- access_ok(VERIFY_WRITE, ptr, sizeof(*ptr)) ? \
- __put_user(x, ptr) : \
+ access_ok(VERIFY_WRITE, __p, sizeof(*__p)) ? \
+ __put_user(x, __p) : \
-EFAULT; \
})
@@ -225,9 +226,10 @@ extern int __put_user_bad(void) __attribute__((noreturn));
#define get_user(x, ptr) \
({ \
+ __typeof__((ptr)) __p = (ptr); \
might_fault(); \
- access_ok(VERIFY_READ, ptr, sizeof(*ptr)) ? \
- __get_user(x, ptr) : \
+ access_ok(VERIFY_READ, __p, sizeof(*__p)) ? \
+ __get_user(x, __p) : \
-EFAULT; \
})
--
2.1.4
Hi Sato-san,
On Thu, Jul 16, 2015 at 7:15 AM, Yoshinori Sato
<[email protected]> wrote:
> Current implemantation ptr argument evaluate 2 times.
> It'll be an unexpected result.
>
> Signed-off-by: Yoshinori Sato <[email protected]>
Acked-by: Geert Uytterhoeven <[email protected]>
> ---
> include/asm-generic/uaccess.h | 10 ++++++----
> 1 file changed, 6 insertions(+), 4 deletions(-)
>
> diff --git a/include/asm-generic/uaccess.h b/include/asm-generic/uaccess.h
> index 72d8803..1b813fb 100644
> --- a/include/asm-generic/uaccess.h
> +++ b/include/asm-generic/uaccess.h
> @@ -163,9 +163,10 @@ static inline __must_check long __copy_to_user(void __user *to,
>
> #define put_user(x, ptr) \
> ({ \
> + __typeof__((ptr)) __p = (ptr); \
> might_fault(); \
> - access_ok(VERIFY_WRITE, ptr, sizeof(*ptr)) ? \
> - __put_user(x, ptr) : \
> + access_ok(VERIFY_WRITE, __p, sizeof(*__p)) ? \
> + __put_user(x, __p) : \
For safety, you may want to change "x" to "(x") while at it.
> -EFAULT; \
> })
>
> @@ -225,9 +226,10 @@ extern int __put_user_bad(void) __attribute__((noreturn));
>
> #define get_user(x, ptr) \
> ({ \
> + __typeof__((ptr)) __p = (ptr); \
> might_fault(); \
> - access_ok(VERIFY_READ, ptr, sizeof(*ptr)) ? \
> - __get_user(x, ptr) : \
> + access_ok(VERIFY_READ, __p, sizeof(*__p)) ? \
> + __get_user(x, __p) : \
Likewise.
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]
In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
On Thu, 16 Jul 2015 15:40:31 +0900,
Geert Uytterhoeven wrote:
>
> Hi Sato-san,
>
> On Thu, Jul 16, 2015 at 7:15 AM, Yoshinori Sato
> <[email protected]> wrote:
> > Current implemantation ptr argument evaluate 2 times.
> > It'll be an unexpected result.
> >
> > Signed-off-by: Yoshinori Sato <[email protected]>
>
> Acked-by: Geert Uytterhoeven <[email protected]>
>
> > ---
> > include/asm-generic/uaccess.h | 10 ++++++----
> > 1 file changed, 6 insertions(+), 4 deletions(-)
> >
> > diff --git a/include/asm-generic/uaccess.h b/include/asm-generic/uaccess.h
> > index 72d8803..1b813fb 100644
> > --- a/include/asm-generic/uaccess.h
> > +++ b/include/asm-generic/uaccess.h
> > @@ -163,9 +163,10 @@ static inline __must_check long __copy_to_user(void __user *to,
> >
> > #define put_user(x, ptr) \
> > ({ \
> > + __typeof__((ptr)) __p = (ptr); \
> > might_fault(); \
> > - access_ok(VERIFY_WRITE, ptr, sizeof(*ptr)) ? \
> > - __put_user(x, ptr) : \
> > + access_ok(VERIFY_WRITE, __p, sizeof(*__p)) ? \
> > + __put_user(x, __p) : \
>
> For safety, you may want to change "x" to "(x") while at it.
That's right.
I'll sent v2.
> > -EFAULT; \
> > })
> >
> > @@ -225,9 +226,10 @@ extern int __put_user_bad(void) __attribute__((noreturn));
> >
> > #define get_user(x, ptr) \
> > ({ \
> > + __typeof__((ptr)) __p = (ptr); \
> > might_fault(); \
> > - access_ok(VERIFY_READ, ptr, sizeof(*ptr)) ? \
> > - __get_user(x, ptr) : \
> > + access_ok(VERIFY_READ, __p, sizeof(*__p)) ? \
> > + __get_user(x, __p) : \
>
> Likewise.
>
> Gr{oetje,eeting}s,
>
> Geert
>
> --
> Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]
>
> In personal conversations with technical people, I call myself a hacker. But
> when I'm talking to journalists I just say "programmer" or something like that.
> -- Linus Torvalds
--
Yoshinori Sato
<[email protected]>
On Thursday 16 July 2015 14:15:22 Yoshinori Sato wrote:
> Current implemantation ptr argument evaluate 2 times.
> It'll be an unexpected result.
>
> Signed-off-by: Yoshinori Sato <[email protected]>
Acked-by: Arnd Bergmann <[email protected]>
Do you want to include this into a pull request of your own?
I'm currently on leave and not planning to merge asm-generic
patches for the next merge window.
Arnd
Current implemantation ptr argument evaluate 2 times.
It'll be an unexpected result.
Changes v2:
Add parenthesis to argument "x".
Signed-off-by: Yoshinori Sato <[email protected]>
---
include/asm-generic/uaccess.h | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/include/asm-generic/uaccess.h b/include/asm-generic/uaccess.h
index 72d8803..ba6ab80 100644
--- a/include/asm-generic/uaccess.h
+++ b/include/asm-generic/uaccess.h
@@ -163,9 +163,10 @@ static inline __must_check long __copy_to_user(void __user *to,
#define put_user(x, ptr) \
({ \
+ __typeof__((ptr)) __p = (ptr); \
might_fault(); \
- access_ok(VERIFY_WRITE, ptr, sizeof(*ptr)) ? \
- __put_user(x, ptr) : \
+ access_ok(VERIFY_WRITE, __p, sizeof(*__p)) ? \
+ __put_user((x), __p) : \
-EFAULT; \
})
@@ -225,9 +226,10 @@ extern int __put_user_bad(void) __attribute__((noreturn));
#define get_user(x, ptr) \
({ \
+ __typeof__((ptr)) __p = (ptr); \
might_fault(); \
- access_ok(VERIFY_READ, ptr, sizeof(*ptr)) ? \
- __get_user(x, ptr) : \
+ access_ok(VERIFY_READ, __p, sizeof(*__p)) ? \
+ __get_user((x), __p) : \
-EFAULT; \
})
--
2.1.4
On Thu, 16 Jul 2015 23:15:21 +0900,
Arnd Bergmann wrote:
>
> On Thursday 16 July 2015 14:15:22 Yoshinori Sato wrote:
> > Current implemantation ptr argument evaluate 2 times.
> > It'll be an unexpected result.
> >
> > Signed-off-by: Yoshinori Sato <[email protected]>
>
> Acked-by: Arnd Bergmann <[email protected]>
>
> Do you want to include this into a pull request of your own?
> I'm currently on leave and not planning to merge asm-generic
> patches for the next merge window.
>
> Arnd
OK.
I'll sent later.
Thanks.
--
Yoshinori Sato
<[email protected]>
Current implemantation ptr argument evaluate 2 times.
It'll be an unexpected result.
Changes v3:
Some build error fix.
Changes v2:
Argument x protect.
Signed-off-by: Yoshinori Sato <[email protected]>
---
include/asm-generic/uaccess.h | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/include/asm-generic/uaccess.h b/include/asm-generic/uaccess.h
index 72d8803..d800a3f 100644
--- a/include/asm-generic/uaccess.h
+++ b/include/asm-generic/uaccess.h
@@ -163,9 +163,10 @@ static inline __must_check long __copy_to_user(void __user *to,
#define put_user(x, ptr) \
({ \
+ uintptr_t __uip = (uintptr_t)(ptr); \
might_fault(); \
- access_ok(VERIFY_WRITE, ptr, sizeof(*ptr)) ? \
- __put_user(x, ptr) : \
+ access_ok(VERIFY_WRITE, __uip, sizeof(*ptr)) ? \
+ __put_user((x), ((__typeof__(*ptr) *)__uip)) : \
-EFAULT; \
})
@@ -225,9 +226,10 @@ extern int __put_user_bad(void) __attribute__((noreturn));
#define get_user(x, ptr) \
({ \
+ uintptr_t __uip = (uintptr_t)(ptr); \
might_fault(); \
- access_ok(VERIFY_READ, ptr, sizeof(*ptr)) ? \
- __get_user(x, ptr) : \
+ access_ok(VERIFY_READ, __uip, sizeof(*ptr)) ? \
+ __get_user((x), (__typeof__(*ptr) *)__uip) : \
-EFAULT; \
})
--
2.1.4
Yoshinori Sato <[email protected]> wrote:
> #define get_user(x, ptr) \
> ({ \
> + uintptr_t __uip = (uintptr_t)(ptr); \
const?
> might_fault(); \
> - access_ok(VERIFY_READ, ptr, sizeof(*ptr)) ? \
> - __get_user(x, ptr) : \
> + access_ok(VERIFY_READ, __uip, sizeof(*ptr)) ? \
> + __get_user((x), (__typeof__(*ptr) *)__uip) : \
> -EFAULT; \
> })
Would it be better to use void* instead of uintptr_t?
David
On Tue, 21 Jul 2015 23:06:13 +0900,
David Howells wrote:
>
> Yoshinori Sato <[email protected]> wrote:
>
> > #define get_user(x, ptr) \
> > ({ \
> > + uintptr_t __uip = (uintptr_t)(ptr); \
>
> const?
OK.
> > might_fault(); \
> > - access_ok(VERIFY_READ, ptr, sizeof(*ptr)) ? \
> > - __get_user(x, ptr) : \
> > + access_ok(VERIFY_READ, __uip, sizeof(*ptr)) ? \
> > + __get_user((x), (__typeof__(*ptr) *)__uip) : \
> > -EFAULT; \
> > })
>
> Would it be better to use void* instead of uintptr_t?
No reason.
I'll changed void*
Thanks.
> David
--
Yoshinori Sato
<[email protected]>
Current implemantation ptr argument evaluate 2 times.
It'll be an unexpected result.
Changes v4:
Temporary pointer type change to const void*
Changes v3:
Some build error fix.
Changes v2:
Argument x protect.
Signed-off-by: Yoshinori Sato <[email protected]>
---
include/asm-generic/uaccess.h | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/include/asm-generic/uaccess.h b/include/asm-generic/uaccess.h
index 72d8803..f02e696 100644
--- a/include/asm-generic/uaccess.h
+++ b/include/asm-generic/uaccess.h
@@ -163,9 +163,10 @@ static inline __must_check long __copy_to_user(void __user *to,
#define put_user(x, ptr) \
({ \
+ const void *__p = (ptr); \
might_fault(); \
- access_ok(VERIFY_WRITE, ptr, sizeof(*ptr)) ? \
- __put_user(x, ptr) : \
+ access_ok(VERIFY_WRITE, __p, sizeof(*ptr)) ? \
+ __put_user((x), ((__typeof__(*(ptr)) *)__p)) : \
-EFAULT; \
})
@@ -225,9 +226,10 @@ extern int __put_user_bad(void) __attribute__((noreturn));
#define get_user(x, ptr) \
({ \
+ const void *__p = (ptr); \
might_fault(); \
- access_ok(VERIFY_READ, ptr, sizeof(*ptr)) ? \
- __get_user(x, ptr) : \
+ access_ok(VERIFY_READ, __p, sizeof(*ptr)) ? \
+ __get_user((x), (__typeof__(*(ptr)) *)__p) : \
-EFAULT; \
})
--
2.1.4
Yoshinori Sato <[email protected]> wrote:
> #define put_user(x, ptr) \
> ({ \
> + const void *__p = (ptr); \
Not const here, though...
David
Current implemantation ptr argument evaluate 2 times.
It'll be an unexpected result.
Changes v5:
Remove unnecessary const.
Changes v4:
Temporary pointer type change to const void*
Changes v3:
Some build error fix.
Changes v2:
Argument x protect.
Signed-off-by: Yoshinori Sato <[email protected]>
---
include/asm-generic/uaccess.h | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/include/asm-generic/uaccess.h b/include/asm-generic/uaccess.h
index 72d8803..1bfa602 100644
--- a/include/asm-generic/uaccess.h
+++ b/include/asm-generic/uaccess.h
@@ -163,9 +163,10 @@ static inline __must_check long __copy_to_user(void __user *to,
#define put_user(x, ptr) \
({ \
+ void *__p = (ptr); \
might_fault(); \
- access_ok(VERIFY_WRITE, ptr, sizeof(*ptr)) ? \
- __put_user(x, ptr) : \
+ access_ok(VERIFY_WRITE, __p, sizeof(*ptr)) ? \
+ __put_user((x), ((__typeof__(*(ptr)) *)__p)) : \
-EFAULT; \
})
@@ -225,9 +226,10 @@ extern int __put_user_bad(void) __attribute__((noreturn));
#define get_user(x, ptr) \
({ \
+ const void *__p = (ptr); \
might_fault(); \
- access_ok(VERIFY_READ, ptr, sizeof(*ptr)) ? \
- __get_user(x, ptr) : \
+ access_ok(VERIFY_READ, __p, sizeof(*ptr)) ? \
+ __get_user((x), (__typeof__(*(ptr)) *)__p) : \
-EFAULT; \
})
--
2.1.4