]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/5.0.15/linux-kernel.h-use-parentheses-around-argument-in-u6.patch
Linux 5.0.15
[thirdparty/kernel/stable-queue.git] / releases / 5.0.15 / linux-kernel.h-use-parentheses-around-argument-in-u6.patch
1 From e231ad027fd94ba4595f06b00c284a621c2a4e6d Mon Sep 17 00:00:00 2001
2 From: Jann Horn <jannh@google.com>
3 Date: Fri, 29 Mar 2019 22:46:49 +0100
4 Subject: linux/kernel.h: Use parentheses around argument in u64_to_user_ptr()
5
6 [ Upstream commit a0fe2c6479aab5723239b315ef1b552673f434a3 ]
7
8 Use parentheses around uses of the argument in u64_to_user_ptr() to
9 ensure that the cast doesn't apply to part of the argument.
10
11 There are existing uses of the macro of the form
12
13 u64_to_user_ptr(A + B)
14
15 which expands to
16
17 (void __user *)(uintptr_t)A + B
18
19 (the cast applies to the first operand of the addition, the addition
20 is a pointer addition). This happens to still work as intended, the
21 semantic difference doesn't cause a difference in behavior.
22
23 But I want to use u64_to_user_ptr() with a ternary operator in the
24 argument, like so:
25
26 u64_to_user_ptr(A ? B : C)
27
28 This currently doesn't work as intended.
29
30 Signed-off-by: Jann Horn <jannh@google.com>
31 Signed-off-by: Borislav Petkov <bp@suse.de>
32 Reviewed-by: Mukesh Ojha <mojha@codeaurora.org>
33 Cc: Andrei Vagin <avagin@openvz.org>
34 Cc: Andrew Morton <akpm@linux-foundation.org>
35 Cc: Dan Carpenter <dan.carpenter@oracle.com>
36 Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
37 Cc: "H. Peter Anvin" <hpa@zytor.com>
38 Cc: Ingo Molnar <mingo@kernel.org>
39 Cc: Jani Nikula <jani.nikula@intel.com>
40 Cc: Kees Cook <keescook@chromium.org>
41 Cc: Masahiro Yamada <yamada.masahiro@socionext.com>
42 Cc: NeilBrown <neilb@suse.com>
43 Cc: Peter Zijlstra <peterz@infradead.org>
44 Cc: Qiaowei Ren <qiaowei.ren@intel.com>
45 Cc: Thomas Gleixner <tglx@linutronix.de>
46 Cc: x86-ml <x86@kernel.org>
47 Link: https://lkml.kernel.org/r/20190329214652.258477-1-jannh@google.com
48 Signed-off-by: Sasha Levin <sashal@kernel.org>
49 ---
50 include/linux/kernel.h | 4 ++--
51 1 file changed, 2 insertions(+), 2 deletions(-)
52
53 diff --git a/include/linux/kernel.h b/include/linux/kernel.h
54 index 8f0e68e250a76..fd827b2400596 100644
55 --- a/include/linux/kernel.h
56 +++ b/include/linux/kernel.h
57 @@ -73,8 +73,8 @@
58
59 #define u64_to_user_ptr(x) ( \
60 { \
61 - typecheck(u64, x); \
62 - (void __user *)(uintptr_t)x; \
63 + typecheck(u64, (x)); \
64 + (void __user *)(uintptr_t)(x); \
65 } \
66 )
67
68 --
69 2.20.1
70