[ Upstream commit a0fe2c6479aab5723239b315ef1b552673f434a3 ] 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. Signed-off-by: Jann Horn <ja...@google.com> Signed-off-by: Borislav Petkov <b...@suse.de> Reviewed-by: Mukesh Ojha <mo...@codeaurora.org> Cc: Andrei Vagin <ava...@openvz.org> Cc: Andrew Morton <a...@linux-foundation.org> Cc: Dan Carpenter <dan.carpen...@oracle.com> Cc: Greg Kroah-Hartman <gre...@linuxfoundation.org> Cc: "H. Peter Anvin" <h...@zytor.com> Cc: Ingo Molnar <mi...@kernel.org> Cc: Jani Nikula <jani.nik...@intel.com> Cc: Kees Cook <keesc...@chromium.org> Cc: Masahiro Yamada <yamada.masah...@socionext.com> Cc: NeilBrown <ne...@suse.com> Cc: Peter Zijlstra <pet...@infradead.org> Cc: Qiaowei Ren <qiaowei....@intel.com> Cc: Thomas Gleixner <t...@linutronix.de> Cc: x86-ml <x...@kernel.org> Link: https://lkml.kernel.org/r/20190329214652.258477-1-ja...@google.com Signed-off-by: Sasha Levin <sas...@kernel.org> --- 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 d6aac75b51baa..3d83ebb302cfd 100644 --- a/include/linux/kernel.h +++ b/include/linux/kernel.h @@ -73,8 +73,8 @@ #define u64_to_user_ptr(x) ( \ { \ - typecheck(u64, x); \ - (void __user *)(uintptr_t)x; \ + typecheck(u64, (x)); \ + (void __user *)(uintptr_t)(x); \ } \ ) -- 2.20.1