asm-generic: {get,put}_user ptr argument evaluate only 1 time
PATCH 1/1 asm-generic: {get,put}_user ptr argument evaluate only 1 time
Current implemantation ptr argument evaluate 2 times. It'll be an unexpected result.
--- include/asm-generic/uaccess.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
include/asm-generic/uaccess.h +6 -4
@@ -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; \ })
Signature · 1 line
2.1.4
Hi Sato-san,
Quoted 4 lines · Yoshinori Sato
Current implemantation ptr argument evaluate 2 times. It'll be an unexpected result.
Signed-off-by Yoshinori Sato <[email protected]>
Quoted 9 lines
--- include/asm-generic/uaccess.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)include/asm-generic/uaccess.h +0
-0
include/asm-generic/uaccess.h static inline __must_check long __copy_to_user(void __user *to, · line 169
Quoted 9 lines
include/asm-generic/uaccess.h +3
-2@@ -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.
include/asm-generic/uaccess.h extern int __put_user_bad(void) __attribute__((noreturn)); · line 232
Quoted 13 lines
include/asm-generic/uaccess.h +3
-2-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
Quoted 22 lines · Geert Uytterhoeven
Hi Sato-san,
Quoted 4 lines · Yoshinori Sato
Current implemantation ptr argument evaluate 2 times. It'll be an unexpected result.
Signed-off-by Yoshinori Sato <[email protected]>Quoted 10 lines
--- include/asm-generic/uaccess.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)include/asm-generic/uaccess.h +0
-0@@ -163,9 +163,10 @@ static inline __must_check long __copy_to_user(void __user *to,
Quoted 10 lines
include/asm-generic/uaccess.h static inline __must_check long __copy_to_user(void __user *to, · line 169
Quoted 8 lines
include/asm-generic/uaccess.h +3
-2#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.
Quoted 26 lines
include/asm-generic/uaccess.h extern int __put_user_bad(void) __attribute__((noreturn)); · line 232
Quoted 13 lines
include/asm-generic/uaccess.h +3
-2-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
Signature · 2 lines
Yoshinori Sato <[email protected]>
Quoted 4 lines · 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]>
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
PATCH v2 1/1 asm-generic: {get,put}_user ptr argument evaluate only 1 time
In reply to Yoshinori SatoCurrent implemantation ptr argument evaluate 2 times. It'll be an unexpected result.
Changes v2:
Add parenthesis to argument "x".
--- include/asm-generic/uaccess.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
include/asm-generic/uaccess.h +6 -4
@@ -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; \ })
Signature · 1 line
2.1.4
Quoted 7 lines · Arnd Bergmann
Quoted 4 lines · 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]>
Quoted 7 lines
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.
Signature · 2 lines
Yoshinori Sato <[email protected]>
PATCH v3 1/1 asm-generic: {get,put}_user ptr argument evaluate only 1 time
In reply to Yoshinori SatoCurrent implemantation ptr argument evaluate 2 times. It'll be an unexpected result.
Changes v3:
Some build error fix.
Changes v2:
Argument x protect.
--- include/asm-generic/uaccess.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
include/asm-generic/uaccess.h +6 -4
@@ -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; \ })
Signature · 1 line
2.1.4
Review
Quoted 3 lines · Yoshinori Sato
#define
get_user(x, ptr)\
({ \(quoted diff) +1
-0+ uintptr_t __uip = (uintptr_t)(ptr); \
const?
include/asm-generic/uaccess.h extern int __put_user_bad(void) __attribute__((noreturn)); · line 234
Quoted 7 lines
include/asm-generic/uaccess.h +2
-2might_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
Quoted 8 lines · David Howells
Review
Quoted 3 lines · Yoshinori Sato
#define
get_user(x, ptr)\
({ \(quoted diff) +1
-0+ uintptr_t __uip = (uintptr_t)(ptr); \const?
OK.
Quoted 9 lines
include/asm-generic/uaccess.h extern int __put_user_bad(void) __attribute__((noreturn)); · line 234
Quoted 7 lines
include/asm-generic/uaccess.h +2
-2might_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.
Quoted 1 line
David
Signature · 2 lines
Yoshinori Sato <[email protected]>
PATCH v4 1/1 asm-generic: {get,put}_user ptr argument evaluate only 1 time
In reply to Yoshinori SatoCurrent 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.
--- include/asm-generic/uaccess.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
include/asm-generic/uaccess.h +6 -4
@@ -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; \ })
Signature · 1 line
2.1.4
Review
Quoted 3 lines · Yoshinori Sato
#define
put_user(x, ptr)\
({ \(quoted diff) +1
-0+ const void *__p = (ptr); \
Not const here, though...
David
PATCH v5 1/1 asm-generic: {get,put}_user ptr argument evaluate only 1 time
In reply to Yoshinori SatoCurrent 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.
--- include/asm-generic/uaccess.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
include/asm-generic/uaccess.h +6 -4
@@ -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; \ })
Signature · 1 line
2.1.4