linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 1/4] kernel.h: use parentheses around argument in u64_to_user_ptr()
@ 2019-03-29 21:46 Jann Horn
  2019-03-29 21:46 ` [PATCH v3 2/4] x86/microcode: Fix __user annotations around generic_load_microcode() Jann Horn
                   ` (3 more replies)
  0 siblings, 4 replies; 12+ messages in thread
From: Jann Horn @ 2019-03-29 21:46 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar, Borislav Petkov, H. Peter Anvin, jannh
  Cc: x86, linux-kernel, Qiaowei Ren, Mukesh Ojha

Use parentheses around uses of the argument in u64_to_user_ptr() to ensure
that the cast doesn't apply to part of the argument.

There are existing uses of the macro of the form `u64_to_user_ptr(A + B)`,
which expands to `(void __user *)(uintptr_t)A + B` (the cast applies to the
first operand of the addition, the addition is a pointer addition). This
happens to still work as intended, the semantic difference doesn't cause a
difference in behavior.
But I want to use u64_to_user_ptr() with a ternary operator in the
argument, like so: `u64_to_user_ptr(A ? B : C)`. This currently doesn't
work as intended.

Reviewed-by: Mukesh Ojha <mojha@codeaurora.org>
Signed-off-by: Jann Horn <jannh@google.com>
---
 include/linux/kernel.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index 34a5036debd3..2d14e21c16c0 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -47,8 +47,8 @@
 
 #define u64_to_user_ptr(x) (		\
 {					\
-	typecheck(u64, x);		\
-	(void __user *)(uintptr_t)x;	\
+	typecheck(u64, (x));		\
+	(void __user *)(uintptr_t)(x);	\
 }					\
 )
 
-- 
2.21.0.392.gf8f6787159e-goog


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

end of thread, other threads:[~2019-04-03 15:10 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-29 21:46 [PATCH v3 1/4] kernel.h: use parentheses around argument in u64_to_user_ptr() Jann Horn
2019-03-29 21:46 ` [PATCH v3 2/4] x86/microcode: Fix __user annotations around generic_load_microcode() Jann Horn
2019-04-01 17:30   ` Borislav Petkov
2019-04-01 17:53     ` Jann Horn
2019-04-02  9:55       ` David Laight
2019-04-02 10:01       ` Borislav Petkov
2019-04-02 10:26         ` David Laight
2019-03-29 21:46 ` [PATCH v3 3/4] x86/fpu: Fix __user annotations Jann Horn
2019-04-03 12:43   ` [tip:x86/fpu] " tip-bot for Jann Horn
2019-03-29 21:46 ` [PATCH v3 4/4] x86/uaccess: Fix implicit cast of __user pointer Jann Horn
2019-04-03 15:10   ` [tip:x86/asm] " tip-bot for Jann Horn
2019-04-03 11:10 ` [tip:core/urgent] linux/kernel.h: Use parentheses around argument in u64_to_user_ptr() tip-bot for Jann Horn

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).