]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/4.18.14/x86-vdso-fix-asm-constraints-on-vdso-syscall-fallbacks.patch
4.9-stable patches
[thirdparty/kernel/stable-queue.git] / releases / 4.18.14 / x86-vdso-fix-asm-constraints-on-vdso-syscall-fallbacks.patch
1 From 715bd9d12f84d8f5cc8ad21d888f9bc304a8eb0b Mon Sep 17 00:00:00 2001
2 From: Andy Lutomirski <luto@kernel.org>
3 Date: Mon, 1 Oct 2018 12:52:15 -0700
4 Subject: x86/vdso: Fix asm constraints on vDSO syscall fallbacks
5
6 From: Andy Lutomirski <luto@kernel.org>
7
8 commit 715bd9d12f84d8f5cc8ad21d888f9bc304a8eb0b upstream.
9
10 The syscall fallbacks in the vDSO have incorrect asm constraints.
11 They are not marked as writing to their outputs -- instead, they are
12 marked as clobbering "memory", which is useless. In particular, gcc
13 is smart enough to know that the timespec parameter hasn't escaped,
14 so a memory clobber doesn't clobber it. And passing a pointer as an
15 asm *input* does not tell gcc that the pointed-to value is changed.
16
17 Add in the fact that the asm instructions weren't volatile, and gcc
18 was free to omit them entirely unless their sole output (the return
19 value) is used. Which it is (phew!), but that stops happening with
20 some upcoming patches.
21
22 As a trivial example, the following code:
23
24 void test_fallback(struct timespec *ts)
25 {
26 vdso_fallback_gettime(CLOCK_MONOTONIC, ts);
27 }
28
29 compiles to:
30
31 00000000000000c0 <test_fallback>:
32 c0: c3 retq
33
34 To add insult to injury, the RCX and R11 clobbers on 64-bit
35 builds were missing.
36
37 The "memory" clobber is also unnecessary -- no ordering with respect to
38 other memory operations is needed, but that's going to be fixed in a
39 separate not-for-stable patch.
40
41 Fixes: 2aae950b21e4 ("x86_64: Add vDSO for x86-64 with gettimeofday/clock_gettime/getcpu")
42 Signed-off-by: Andy Lutomirski <luto@kernel.org>
43 Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
44 Cc: stable@vger.kernel.org
45 Link: https://lkml.kernel.org/r/2c0231690551989d2fafa60ed0e7b5cc8b403908.1538422295.git.luto@kernel.org
46 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
47
48 ---
49 arch/x86/entry/vdso/vclock_gettime.c | 18 ++++++++++--------
50 1 file changed, 10 insertions(+), 8 deletions(-)
51
52 --- a/arch/x86/entry/vdso/vclock_gettime.c
53 +++ b/arch/x86/entry/vdso/vclock_gettime.c
54 @@ -43,8 +43,9 @@ extern u8 hvclock_page
55 notrace static long vdso_fallback_gettime(long clock, struct timespec *ts)
56 {
57 long ret;
58 - asm("syscall" : "=a" (ret) :
59 - "0" (__NR_clock_gettime), "D" (clock), "S" (ts) : "memory");
60 + asm ("syscall" : "=a" (ret), "=m" (*ts) :
61 + "0" (__NR_clock_gettime), "D" (clock), "S" (ts) :
62 + "memory", "rcx", "r11");
63 return ret;
64 }
65
66 @@ -52,8 +53,9 @@ notrace static long vdso_fallback_gtod(s
67 {
68 long ret;
69
70 - asm("syscall" : "=a" (ret) :
71 - "0" (__NR_gettimeofday), "D" (tv), "S" (tz) : "memory");
72 + asm ("syscall" : "=a" (ret), "=m" (*tv), "=m" (*tz) :
73 + "0" (__NR_gettimeofday), "D" (tv), "S" (tz) :
74 + "memory", "rcx", "r11");
75 return ret;
76 }
77
78 @@ -64,12 +66,12 @@ notrace static long vdso_fallback_gettim
79 {
80 long ret;
81
82 - asm(
83 + asm (
84 "mov %%ebx, %%edx \n"
85 "mov %2, %%ebx \n"
86 "call __kernel_vsyscall \n"
87 "mov %%edx, %%ebx \n"
88 - : "=a" (ret)
89 + : "=a" (ret), "=m" (*ts)
90 : "0" (__NR_clock_gettime), "g" (clock), "c" (ts)
91 : "memory", "edx");
92 return ret;
93 @@ -79,12 +81,12 @@ notrace static long vdso_fallback_gtod(s
94 {
95 long ret;
96
97 - asm(
98 + asm (
99 "mov %%ebx, %%edx \n"
100 "mov %2, %%ebx \n"
101 "call __kernel_vsyscall \n"
102 "mov %%edx, %%ebx \n"
103 - : "=a" (ret)
104 + : "=a" (ret), "=m" (*tv), "=m" (*tz)
105 : "0" (__NR_gettimeofday), "g" (tv), "c" (tz)
106 : "memory", "edx");
107 return ret;