linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] arm64: avoid multiple evaluation of ptr in get_user/put_user()
@ 2013-09-24  9:00 AKASHI Takahiro
  2013-09-24 14:05 ` Catalin Marinas
  2013-09-24 14:25 ` Catalin Marinas
  0 siblings, 2 replies; 5+ messages in thread
From: AKASHI Takahiro @ 2013-09-24  9:00 UTC (permalink / raw)
  To: linux-arm-kernel

get_user() is defined as a function macro in arm64, and trace_get_user()
calls it as followed:
     get_user(ch, ptr++);
Since the second parameter occurs twice in the definition, 'ptr++' is
unexpectedly evaluated twice and trace_get_user() will generate a bogus
string from user-provided one. As a result, some ftrace sysfs operations,
like "echo FUNCNAME > set_ftrace_filter," hit this case and eventually fail.
This patch fixes the issue both in get_user() and put_user().

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
---
  arch/arm64/include/asm/uaccess.h |   12 ++++++++----
  1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/arch/arm64/include/asm/uaccess.h b/arch/arm64/include/asm/uaccess.h
index edb3d5c..bbeab83 100644
--- a/arch/arm64/include/asm/uaccess.h
+++ b/arch/arm64/include/asm/uaccess.h
@@ -166,9 +166,11 @@ do {									\
   #define get_user(x, ptr)						\
  ({									\
+	__typeof__(*(ptr)) *optr = (ptr);				\
+									\
  	might_fault();							\
-	access_ok(VERIFY_READ, (ptr), sizeof(*(ptr))) ?			\
-		__get_user((x), (ptr)) :				\
+	access_ok(VERIFY_READ, optr, sizeof(*optr)) ?			\
+		__get_user((x), optr) :					\
  		((x) = 0, -EFAULT);					\
  })
  @@ -227,9 +229,11 @@ do {									\
   #define put_user(x, ptr)						\
  ({									\
+	__typeof__(*(ptr)) *optr = (ptr);				\
+									\
  	might_fault();							\
-	access_ok(VERIFY_WRITE, (ptr), sizeof(*(ptr))) ?		\
-		__put_user((x), (ptr)) :				\
+	access_ok(VERIFY_WRITE, optr, sizeof(*optr)) ?			\
+		__put_user((x), optr) :					\
  		-EFAULT;						\
  })
  -- 1.7.9.5

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2013-09-25 13:21 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-09-24  9:00 [PATCH] arm64: avoid multiple evaluation of ptr in get_user/put_user() AKASHI Takahiro
2013-09-24 14:05 ` Catalin Marinas
2013-09-24 14:25 ` Catalin Marinas
2013-09-25  9:29   ` AKASHI Takahiro
2013-09-25 13:21     ` Catalin Marinas

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).