]> git.proxmox.com Git - pve-kernel.git/blob - patches/kernel/0075-x86-entry-Use-SYSCALL_DEFINE-macros-for-sys_modify_l.patch
af37b4e9b720de3c6fe32d2cd070781bd56cbf73
[pve-kernel.git] / patches / kernel / 0075-x86-entry-Use-SYSCALL_DEFINE-macros-for-sys_modify_l.patch
1 From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2 From: Dave Hansen <dave.hansen@linux.intel.com>
3 Date: Wed, 18 Oct 2017 10:21:07 -0700
4 Subject: [PATCH] x86/entry: Use SYSCALL_DEFINE() macros for sys_modify_ldt()
5 MIME-Version: 1.0
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
8
9 CVE-2017-5754
10
11 We do not have tracepoints for sys_modify_ldt() because we define
12 it directly instead of using the normal SYSCALL_DEFINEx() macros.
13
14 However, there is a reason sys_modify_ldt() does not use the macros:
15 it has an 'int' return type instead of 'unsigned long'. This is
16 a bug, but it's a bug cemented in the ABI.
17
18 What does this mean? If we return -EINVAL from a function that
19 returns 'int', we have 0x00000000ffffffea in %rax. But, if we
20 return -EINVAL from a function returning 'unsigned long', we end
21 up with 0xffffffffffffffea in %rax, which is wrong.
22
23 To work around this and maintain the 'int' behavior while using
24 the SYSCALL_DEFINEx() macros, so we add a cast to 'unsigned int'
25 in both implementations of sys_modify_ldt().
26
27 Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com>
28 Reviewed-by: Andy Lutomirski <luto@kernel.org>
29 Reviewed-by: Brian Gerst <brgerst@gmail.com>
30 Cc: Linus Torvalds <torvalds@linux-foundation.org>
31 Cc: Peter Zijlstra <peterz@infradead.org>
32 Cc: Thomas Gleixner <tglx@linutronix.de>
33 Link: http://lkml.kernel.org/r/20171018172107.1A79C532@viggo.jf.intel.com
34 Signed-off-by: Ingo Molnar <mingo@kernel.org>
35 (cherry picked from commit da20ab35180780e4a6eadc804544f1fa967f3567)
36 Signed-off-by: Andy Whitcroft <apw@canonical.com>
37 Signed-off-by: Kleber Sacilotto de Souza <kleber.souza@canonical.com>
38 (cherry picked from commit d865f635f4b2c3307e79de9be5c49ea8bd4c43a6)
39 Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
40 ---
41 arch/x86/include/asm/syscalls.h | 2 +-
42 arch/x86/kernel/ldt.c | 16 +++++++++++++---
43 arch/x86/um/ldt.c | 7 +++++--
44 3 files changed, 19 insertions(+), 6 deletions(-)
45
46 diff --git a/arch/x86/include/asm/syscalls.h b/arch/x86/include/asm/syscalls.h
47 index 91dfcafe27a6..bad25bb80679 100644
48 --- a/arch/x86/include/asm/syscalls.h
49 +++ b/arch/x86/include/asm/syscalls.h
50 @@ -21,7 +21,7 @@ asmlinkage long sys_ioperm(unsigned long, unsigned long, int);
51 asmlinkage long sys_iopl(unsigned int);
52
53 /* kernel/ldt.c */
54 -asmlinkage int sys_modify_ldt(int, void __user *, unsigned long);
55 +asmlinkage long sys_modify_ldt(int, void __user *, unsigned long);
56
57 /* kernel/signal.c */
58 asmlinkage long sys_rt_sigreturn(void);
59 diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
60 index f0e64db18ac8..0402d44deb4d 100644
61 --- a/arch/x86/kernel/ldt.c
62 +++ b/arch/x86/kernel/ldt.c
63 @@ -12,6 +12,7 @@
64 #include <linux/string.h>
65 #include <linux/mm.h>
66 #include <linux/smp.h>
67 +#include <linux/syscalls.h>
68 #include <linux/slab.h>
69 #include <linux/vmalloc.h>
70 #include <linux/uaccess.h>
71 @@ -294,8 +295,8 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
72 return error;
73 }
74
75 -asmlinkage int sys_modify_ldt(int func, void __user *ptr,
76 - unsigned long bytecount)
77 +SYSCALL_DEFINE3(modify_ldt, int , func , void __user * , ptr ,
78 + unsigned long , bytecount)
79 {
80 int ret = -ENOSYS;
81
82 @@ -313,5 +314,14 @@ asmlinkage int sys_modify_ldt(int func, void __user *ptr,
83 ret = write_ldt(ptr, bytecount, 0);
84 break;
85 }
86 - return ret;
87 + /*
88 + * The SYSCALL_DEFINE() macros give us an 'unsigned long'
89 + * return type, but tht ABI for sys_modify_ldt() expects
90 + * 'int'. This cast gives us an int-sized value in %rax
91 + * for the return code. The 'unsigned' is necessary so
92 + * the compiler does not try to sign-extend the negative
93 + * return codes into the high half of the register when
94 + * taking the value from int->long.
95 + */
96 + return (unsigned int)ret;
97 }
98 diff --git a/arch/x86/um/ldt.c b/arch/x86/um/ldt.c
99 index 836a1eb5df43..3ee234b6234d 100644
100 --- a/arch/x86/um/ldt.c
101 +++ b/arch/x86/um/ldt.c
102 @@ -6,6 +6,7 @@
103 #include <linux/mm.h>
104 #include <linux/sched.h>
105 #include <linux/slab.h>
106 +#include <linux/syscalls.h>
107 #include <linux/uaccess.h>
108 #include <asm/unistd.h>
109 #include <os.h>
110 @@ -369,7 +370,9 @@ void free_ldt(struct mm_context *mm)
111 mm->arch.ldt.entry_count = 0;
112 }
113
114 -int sys_modify_ldt(int func, void __user *ptr, unsigned long bytecount)
115 +SYSCALL_DEFINE3(modify_ldt, int , func , void __user * , ptr ,
116 + unsigned long , bytecount)
117 {
118 - return do_modify_ldt_skas(func, ptr, bytecount);
119 + /* See non-um modify_ldt() for why we do this cast */
120 + return (unsigned int)do_modify_ldt_skas(func, ptr, bytecount);
121 }
122 --
123 2.14.2
124