Skip to content

Commit f48f01a

Browse files
samitolvanenIngo Molnar
authored andcommitted
syscalls/x86: Use the correct function type for sys_ni_syscall
Use the correct function type for sys_ni_syscall() in system call tables to fix indirect call mismatches with Control-Flow Integrity (CFI) checking. Signed-off-by: Sami Tolvanen <[email protected]> Acked-by: Andy Lutomirski <[email protected]> Cc: Borislav Petkov <[email protected]> Cc: H . Peter Anvin <[email protected]> Cc: Kees Cook <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Thomas Gleixner <[email protected]> Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Ingo Molnar <[email protected]>
1 parent 00198a6 commit f48f01a

File tree

3 files changed

+15
-11
lines changed

3 files changed

+15
-11
lines changed

arch/x86/entry/syscall_32.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,11 @@
1010
#ifdef CONFIG_IA32_EMULATION
1111
/* On X86_64, we use struct pt_regs * to pass parameters to syscalls */
1212
#define __SYSCALL_I386(nr, sym, qual) extern asmlinkage long sym(const struct pt_regs *);
13-
14-
/* this is a lie, but it does not hurt as sys_ni_syscall just returns -EINVAL */
15-
extern asmlinkage long sys_ni_syscall(const struct pt_regs *);
16-
13+
#define __sys_ni_syscall __ia32_sys_ni_syscall
1714
#else /* CONFIG_IA32_EMULATION */
1815
#define __SYSCALL_I386(nr, sym, qual) extern asmlinkage long sym(unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, unsigned long);
1916
extern asmlinkage long sys_ni_syscall(unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, unsigned long);
17+
#define __sys_ni_syscall sys_ni_syscall
2018
#endif /* CONFIG_IA32_EMULATION */
2119

2220
#include <asm/syscalls_32.h>
@@ -29,6 +27,6 @@ __visible const sys_call_ptr_t ia32_sys_call_table[__NR_syscall_compat_max+1] =
2927
* Smells like a compiler bug -- it doesn't work
3028
* when the & below is removed.
3129
*/
32-
[0 ... __NR_syscall_compat_max] = &sys_ni_syscall,
30+
[0 ... __NR_syscall_compat_max] = &__sys_ni_syscall,
3331
#include <asm/syscalls_32.h>
3432
};

arch/x86/entry/syscall_64.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,17 @@
44
#include <linux/linkage.h>
55
#include <linux/sys.h>
66
#include <linux/cache.h>
7+
#include <linux/syscalls.h>
78
#include <asm/asm-offsets.h>
89
#include <asm/syscall.h>
910

10-
/* this is a lie, but it does not hurt as sys_ni_syscall just returns -EINVAL */
11-
extern asmlinkage long sys_ni_syscall(const struct pt_regs *);
11+
extern asmlinkage long sys_ni_syscall(void);
12+
13+
SYSCALL_DEFINE0(ni_syscall)
14+
{
15+
return sys_ni_syscall();
16+
}
17+
1218
#define __SYSCALL_64(nr, sym, qual) extern asmlinkage long sym(const struct pt_regs *);
1319
#define __SYSCALL_X32(nr, sym, qual) __SYSCALL_64(nr, sym, qual)
1420
#include <asm/syscalls_64.h>
@@ -23,7 +29,7 @@ asmlinkage const sys_call_ptr_t sys_call_table[__NR_syscall_max+1] = {
2329
* Smells like a compiler bug -- it doesn't work
2430
* when the & below is removed.
2531
*/
26-
[0 ... __NR_syscall_max] = &sys_ni_syscall,
32+
[0 ... __NR_syscall_max] = &__x64_sys_ni_syscall,
2733
#include <asm/syscalls_64.h>
2834
};
2935

@@ -40,7 +46,7 @@ asmlinkage const sys_call_ptr_t x32_sys_call_table[__NR_syscall_x32_max+1] = {
4046
* Smells like a compiler bug -- it doesn't work
4147
* when the & below is removed.
4248
*/
43-
[0 ... __NR_syscall_x32_max] = &sys_ni_syscall,
49+
[0 ... __NR_syscall_x32_max] = &__x64_sys_ni_syscall,
4450
#include <asm/syscalls_64.h>
4551
};
4652

arch/x86/entry/syscalls/syscall_32.tbl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@
124124
110 i386 iopl sys_iopl __ia32_sys_iopl
125125
111 i386 vhangup sys_vhangup __ia32_sys_vhangup
126126
112 i386 idle
127-
113 i386 vm86old sys_vm86old sys_ni_syscall
127+
113 i386 vm86old sys_vm86old __ia32_sys_ni_syscall
128128
114 i386 wait4 sys_wait4 __ia32_compat_sys_wait4
129129
115 i386 swapoff sys_swapoff __ia32_sys_swapoff
130130
116 i386 sysinfo sys_sysinfo __ia32_compat_sys_sysinfo
@@ -177,7 +177,7 @@
177177
163 i386 mremap sys_mremap __ia32_sys_mremap
178178
164 i386 setresuid sys_setresuid16 __ia32_sys_setresuid16
179179
165 i386 getresuid sys_getresuid16 __ia32_sys_getresuid16
180-
166 i386 vm86 sys_vm86 sys_ni_syscall
180+
166 i386 vm86 sys_vm86 __ia32_sys_ni_syscall
181181
167 i386 query_module
182182
168 i386 poll sys_poll __ia32_sys_poll
183183
169 i386 nfsservctl

0 commit comments

Comments
 (0)