Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1188691 > unrolled thread

[PATCH v3] asm-generic: {get,put}_user ptr argument evaluate only 1 time

Started byYoshinori Sato <ysato@users.sourceforge.jp>
First post2015-07-21 08:20 +0200
Last post2015-07-22 08:10 +0200
Articles 2 — 1 participant

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  [PATCH v3] asm-generic: {get,put}_user ptr argument evaluate only 1 time Yoshinori Sato <ysato@users.sourceforge.jp> - 2015-07-21 08:20 +0200
    Re: [PATCH v3] asm-generic: {get,put}_user ptr argument evaluate only 1 time Yoshinori Sato <ysato@users.sourceforge.jp> - 2015-07-22 08:10 +0200

#1188691 — [PATCH v3] asm-generic: {get,put}_user ptr argument evaluate only 1 time

FromYoshinori Sato <ysato@users.sourceforge.jp>
Date2015-07-21 08:20 +0200
Subject[PATCH v3] asm-generic: {get,put}_user ptr argument evaluate only 1 time
Message-ID<pOz4d-8rH-9@gated-at.bofh.it>
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 <ysato@users.sourceforge.jp>
---
 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

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [next] | [standalone]


#1189667

FromYoshinori Sato <ysato@users.sourceforge.jp>
Date2015-07-22 08:10 +0200
Message-ID<pOVo6-6MK-3@gated-at.bofh.it>
In reply to#1188691
On Tue, 21 Jul 2015 23:06:13 +0900,
David Howells wrote:
> 
> Yoshinori Sato <ysato@users.sourceforge.jp> 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
<ysato@users.sourceforge.jp>
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web