mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2024-12-15 10:56:49 +07:00
6365b842aa
For unfortunate historical reasons, the x32 syscalls and the x86_64 syscalls are not all numbered the same. As an example, ioctl() is nr 16 on x86_64 but 514 on x32. This has potentially nasty consequences, since it means that there are two valid RAX values to do ioctl(2) and two invalid RAX values. The valid values are 16 (i.e. ioctl(2) using the x86_64 ABI) and (514 | 0x40000000) (i.e. ioctl(2) using the x32 ABI). The invalid values are 514 and (16 | 0x40000000). 514 will enter the "COMPAT_SYSCALL_DEFINE3(ioctl, ...)" entry point with in_compat_syscall() and in_x32_syscall() returning false, whereas (16 | 0x40000000) will enter the native entry point with in_compat_syscall() and in_x32_syscall() returning true. Both are bogus, and both will exercise code paths in the kernel and in any running seccomp filters that really ought to be unreachable. Splitting out the x32 syscalls into their own tables, allows both bogus invocations to return -ENOSYS. I've checked glibc, musl, and Bionic, and all of them appear to call syscalls with their correct numbers, so this change should have no effect on them. There is an added benefit going forward: new syscalls that need special handling on x32 can share the same number on x32 and x86_64. This means that the special syscall range 512-547 can be treated as a legacy wart instead of something that may need to be extended in the future. Also add a selftest to verify the new behavior. Signed-off-by: Andy Lutomirski <luto@kernel.org> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Link: https://lkml.kernel.org/r/208024256b764312598f014ebfb0a42472c19354.1562185330.git.luto@kernel.org
51 lines
1.3 KiB
C
51 lines
1.3 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
/* System call table for x86-64. */
|
|
|
|
#include <linux/linkage.h>
|
|
#include <linux/sys.h>
|
|
#include <linux/cache.h>
|
|
#include <asm/asm-offsets.h>
|
|
#include <asm/syscall.h>
|
|
|
|
/* this is a lie, but it does not hurt as sys_ni_syscall just returns -EINVAL */
|
|
extern asmlinkage long sys_ni_syscall(const struct pt_regs *);
|
|
#define __SYSCALL_64(nr, sym, qual) extern asmlinkage long sym(const struct pt_regs *);
|
|
#define __SYSCALL_X32(nr, sym, qual) __SYSCALL_64(nr, sym, qual)
|
|
#include <asm/syscalls_64.h>
|
|
#undef __SYSCALL_64
|
|
#undef __SYSCALL_X32
|
|
|
|
#define __SYSCALL_64(nr, sym, qual) [nr] = sym,
|
|
#define __SYSCALL_X32(nr, sym, qual)
|
|
|
|
asmlinkage const sys_call_ptr_t sys_call_table[__NR_syscall_max+1] = {
|
|
/*
|
|
* Smells like a compiler bug -- it doesn't work
|
|
* when the & below is removed.
|
|
*/
|
|
[0 ... __NR_syscall_max] = &sys_ni_syscall,
|
|
#include <asm/syscalls_64.h>
|
|
};
|
|
|
|
#undef __SYSCALL_64
|
|
#undef __SYSCALL_X32
|
|
|
|
#ifdef CONFIG_X86_X32_ABI
|
|
|
|
#define __SYSCALL_64(nr, sym, qual)
|
|
#define __SYSCALL_X32(nr, sym, qual) [nr] = sym,
|
|
|
|
asmlinkage const sys_call_ptr_t x32_sys_call_table[__NR_syscall_x32_max+1] = {
|
|
/*
|
|
* Smells like a compiler bug -- it doesn't work
|
|
* when the & below is removed.
|
|
*/
|
|
[0 ... __NR_syscall_x32_max] = &sys_ni_syscall,
|
|
#include <asm/syscalls_64.h>
|
|
};
|
|
|
|
#undef __SYSCALL_64
|
|
#undef __SYSCALL_X32
|
|
|
|
#endif
|