use struct pt_regs based syscall calling for x86-64
Subsystems (4)
cover use struct pt_regs based syscall calling for x86-64
Ingo,
On top of all the patches which remove in-kernel calls to syscall functions merged in commit 642e7fd23353, it now becomes easy for achitectures to re-define the syscall calling convention. For x86, this may be used to merely decode those entries from struct pt_regs which are needed for a specific syscall.
This approach avoids leaking random user-provided register content down the call chain. Therefore, the seventh patch of this series extends the register clearing in the entry path to a few more registers.
To exemplify: sys_recv() is a classic 4-parameter syscall. For this syscall, the DEFINE_SYSCALL macro creates the following stub:
asmlinkage long sys_recv(struct pt_regs *regs)
{
return SyS_recv(regs->di, regs->si, regs->dx, regs->r10);
}The assembly of that function then becomes, in slightly reordered fashion:
<sys_recv>: callq <__fentry__> /* decode regs->di, ->si, ->dx and ->r10 */ mov 0x70(%rdi),%rdi mov 0x68(%rdi),%rsi mov 0x60(%rdi),%rdx mov 0x38(%rdi),%rcx [ SyS_recv() is inlined here by the compiler, as it is tiny ] /* clear %r9 and %r8, the 5th and 6th args */ xor %r9d,%r9d xor %r8d,%r8d /* do the actual work */ callq __sys_recvfrom /* cleanup and return */ cltq retq
For IA32_EMULATION and X32, additional care needs to be taken as they use different registers to pass parameters to syscalls; vsyscalls need to be modified to use this new calling convention as well.
This actual conversion of x86 syscalls is heavily based on a proof-of-concept by Linus[*]. This patchset here differs, for example, as it provides a generic config symbol ARCH_HAS_SYSCALL_WRAPPER, introduces <asm/syscall_wrapper.h>, splits up the patch into several parts, and adds the actual register clearing.
[*] Accessible at
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git WIP-syscall It contains an additional patch
x86: avoid per-cpu system call trampoline
which is not included in my series as it addresses a different issue, but may be of interest to the x86 maintainers as well.
Compared to v4.16-rc5 baseline and on a random kernel config, these patches (in combination with the large do-not-call-syscalls-in-the-kernel series) lead to a minisculue increase in text (+0.005%) and data (+0.11%) size on a pure 64bit system,
text data bss dec hex filename 18853337 9535476 938380 29327193 1bf7f59 vmlinux-orig 18854227 9546100 938380 29338707 1bfac53 vmlinux,
with IA32_EMULATION and X32 enabled, the situation is just a little bit worse for text size (+0.009%) and data (+0.38%) size.
text data bss dec hex filename 18902496 9603676 938444 29444616 1c14a08 vmlinux-orig 18904136 9640604 938444 29483184 1c1e0b0 vmlinux.
The 64bit part of this series has worked flawlessly on my local system for a few weeks. IA32_EMULATION and x32 has passed some basic testing as well, but has not yet been tested as extensively as x86-64. Pure i386 kernels are left as-is, as they use a different asmlinkage anyway.
Changes since the series sent out to linux-kernel on March 30th:
all patches:
- rebase on top of commit 642e7fd23353
several patches:
- further extend and fix commentary; spelling fixes (e.g., nospec, 64-bit, 32-bit)
patch 3:
- do not clobber regs->dx on sys_getcpu() vsyscall
patch 5:
- rename __sys32_ia32_*() stubs to __sys_ia32_*()
- do not generate __sys_ia32_*() syscall table entries automatically, but have them explicitely in arch/x86/entry/syscalls/syscall_32.tbl
- this means that there is no need to redefine SYSCALL_DEFINE0
- rename compat_sys_*() to __compat_sys_ia32_*(), as the calling convention is different to "generic" compat_sys_*() [but see below]
patch 8: (your call...)
- introduce new patch 8: rename sys_*() to __sys_x86_*() -- while this avoids symbol space overlap per your request, it doesn't improve the code readibility by much. Moreover, if other architectures switch to this syscall calling convention, there is no real "default" calling convention any more. Therefore, I'd suggest *NOT* to apply this patch.
Thanks,
Dominik
Dominik Brodowski (7):
syscalls: introduce CONFIG_ARCH_HAS_SYSCALL_WRAPPER syscalls/x86: use struct pt_regs based syscall calling for 64-bit
syscalls
syscalls: prepare ARCH_HAS_SYSCALL_WRAPPER for compat syscalls syscalls/x86: use struct pt_regs based syscall calling for
IA32_EMULATION and x32
syscalls/x86: unconditionally enable struct pt_regs based syscalls on
x86_64
x86/entry/64: extend register clearing on syscall entry to lower
registers
syscalls/x86: rename struct pt_regs-based sys_*() to __sys_x86_*()
Linus Torvalds (1):
x86: don't pointlessly reload the system call number
arch/x86/Kconfig | 1 + arch/x86/entry/calling.h | 2 + arch/x86/entry/common.c | 20 +- arch/x86/entry/entry_64.S | 3 +- arch/x86/entry/entry_64_compat.S | 6 + arch/x86/entry/syscall_32.c | 15 +- arch/x86/entry/syscall_64.c | 6 +- arch/x86/entry/syscalls/syscall_32.tbl | 724 +++++++++++++++++---------------- arch/x86/entry/syscalls/syscall_64.tbl | 712 ++++++++++++++++---------------- arch/x86/entry/vsyscall/vsyscall_64.c | 18 +- arch/x86/include/asm/syscall.h | 4 + arch/x86/include/asm/syscall_wrapper.h | 197 +++++++++ arch/x86/include/asm/syscalls.h | 17 +- include/linux/compat.h | 22 + include/linux/syscalls.h | 25 +- init/Kconfig | 10 + kernel/sys_ni.c | 10 + kernel/time/posix-stubs.c | 10 + 18 files changed, 1054 insertions(+), 748 deletions(-) create mode 100644 arch/x86/include/asm/syscall_wrapper.h
Signature · 1 line
2.16.3
PATCH 1/8 x86: don't pointlessly reload the system call number
From: Linus Torvalds <[email protected]>
We have it in a register in the low-level asm, just pass it in as an argument rather than have do_syscall_64() load it back in from the ptregs pointer.
--- arch/x86/entry/common.c | 12 ++++++------ arch/x86/entry/entry_64.S | 3 ++- 2 files changed, 8 insertions(+), 7 deletions(-)
arch/x86/entry/common.c +6 -6
@@ -266,14 +266,13 @@ __visible inline void syscall_return_slowpath(struct pt_regs *regs) }#ifdef CONFIG_X86_64 -__visible void do_syscall_64(struct pt_regs *regs) +__visible void do_syscall_64(unsigned long nr, struct pt_regs *regs) { -struct thread_info *ti =current_thread_info (); -unsigned long nr = regs->orig_ax; +struct thread_info *ti;enter_from_user_mode ();local_irq_enable (); - + ti =current_thread_info ();if (READ_ONCE (ti->flags) & _TIF_WORK_SYSCALL_ENTRY) nr =syscall_trace_enter (regs);
@@ -282,8 +281,9 @@ __visible void do_syscall_64(struct pt_regs *regs)* table. The only functional difference is the x32 bit in * regs->orig_ax, which changes the behavior of some syscalls. */ -if (likely ((nr & __SYSCALL_MASK) < NR_syscalls)) { - nr =array_index_nospec (nr & __SYSCALL_MASK, NR_syscalls); + nr &= __SYSCALL_MASK; +if (likely (nr < NR_syscalls)) { + nr =array_index_nospec (nr, NR_syscalls); regs->ax = sys_call_table[nr]( regs->di, regs->si, regs->dx, regs->r10, regs->r8, regs->r9);
arch/x86/entry/entry_64.S +2 -1
@@ -233,7 +233,8 @@ GLOBAL(entry_SYSCALL_64_after_hwframe) TRACE_IRQS_OFF /* IRQs are off. */ - movq %rsp, %rdi + movq %rax, %rdi + movq %rsp, %rsi call do_syscall_64 /* returns with IRQs disabled */ TRACE_IRQS_IRETQ /* we're about to change IF */
Signature · 1 line
2.16.3
tip-bot for Linus Torvalds
merge bot[tip:x86/asm] x86/syscalls: Don't pointlessly reload the system call number
x86/syscalls: Don't pointlessly reload the system call number
Commit-ID: dfe64506c01e57159a4c550fe537c13a317ff01b Gitweb: https://git.kernel.org/tip/dfe64506c01e57159a4c550fe537c13a317ff01b Author: Linus Torvalds <[email protected]> AuthorDate: Thu, 5 Apr 2018 11:53:00 +0200 Committer: Ingo Molnar <[email protected]> CommitDate: Thu, 5 Apr 2018 16:59:24 +0200
x86/syscalls: Don't pointlessly reload the system call number
We have it in a register in the low-level asm, just pass it in as an argument rather than have do_syscall_64() load it back in from the ptregs pointer.
--- arch/x86/entry/common.c | 12 ++++++------ arch/x86/entry/entry_64.S | 3 ++- 2 files changed, 8 insertions(+), 7 deletions(-)
arch/x86/entry/common.c +6 -6
@@ -266,14 +266,13 @@ __visible inline void syscall_return_slowpath(struct pt_regs *regs) }#ifdef CONFIG_X86_64 -__visible void do_syscall_64(struct pt_regs *regs) +__visible void do_syscall_64(unsigned long nr, struct pt_regs *regs) { -struct thread_info *ti =current_thread_info (); -unsigned long nr = regs->orig_ax; +struct thread_info *ti;enter_from_user_mode ();local_irq_enable (); - + ti =current_thread_info ();if (READ_ONCE (ti->flags) & _TIF_WORK_SYSCALL_ENTRY) nr =syscall_trace_enter (regs);
@@ -282,8 +281,9 @@ __visible void do_syscall_64(struct pt_regs *regs)* table. The only functional difference is the x32 bit in * regs->orig_ax, which changes the behavior of some syscalls. */ -if (likely ((nr & __SYSCALL_MASK) < NR_syscalls)) { - nr =array_index_nospec (nr & __SYSCALL_MASK, NR_syscalls); + nr &= __SYSCALL_MASK; +if (likely (nr < NR_syscalls)) { + nr =array_index_nospec (nr, NR_syscalls); regs->ax = sys_call_table[nr]( regs->di, regs->si, regs->dx, regs->r10, regs->r8, regs->r9);
arch/x86/entry/entry_64.S +2 -1
@@ -233,7 +233,8 @@ GLOBAL(entry_SYSCALL_64_after_hwframe) TRACE_IRQS_OFF /* IRQs are off. */ - movq %rsp, %rdi + movq %rax, %rdi + movq %rsp, %rsi call do_syscall_64 /* returns with IRQs disabled */ TRACE_IRQS_IRETQ /* we're about to change IF */
PATCH 2/8 syscalls: introduce CONFIG_ARCH_HAS_SYSCALL_WRAPPER
In reply to Dominik BrodowskiIt may be useful for an architecture to override the definitions of the SYSCALL_DEFINE0() and __SYSCALL_DEFINEx() macros in <linux/syscalls.h>, in particular to use a different calling convention for syscalls.
This patch provides a mechanism to do so: It introduces CONFIG_ARCH_HAS_SYSCALL_WRAPPER. If it is enabled, <asm/sycall_wrapper.h> is included in <linux/syscalls.h> and may be used to define the macros mentioned above. Moreover, as the syscall calling convention may be different if CONFIG_ARCH_HAS_SYSCALL_WRAPPER is set, the syscall function prototypes in <linux/syscalls.h> are #ifndef'd out in that case.
--- include/linux/syscalls.h | 23 +++++++++++++++++++++++ init/Kconfig | 7 +++++++ 2 files changed, 30 insertions(+)
include/linux/syscalls.h +23 -0
@@ -81,6 +81,17 @@ union bpf_attr;#include <linux/key.h> #include <trace/syscall.h> +#ifdef CONFIG_ARCH_HAS_SYSCALL_WRAPPER +/* +* It may be useful for an architecture to override the definitions of the +* SYSCALL_DEFINE0() and __SYSCALL_DEFINEx() macros, in particular to use a +* different calling convention for syscalls. To allow for that, the prototypes +* for the sys_*() functions below will *not* be included if +* CONFIG_ARCH_HAS_SYSCALL_WRAPPER is enabled. +*/ +#include <asm/syscall_wrapper.h> +#endif /* CONFIG_ARCH_HAS_SYSCALL_WRAPPER */ +/* * __MAP - apply a macro to syscall arguments * __MAP(n, m, t1, a1, t2, a2, ..., tn, an) will expand to
@@ -189,11 +200,13 @@ static inline int is_syscall_trace_event(struct trace_event_call *tp_event) }#endif +#ifndef SYSCALL_DEFINE0 #define SYSCALL_DEFINE0 (sname) \ SYSCALL_METADATA(_##sname, 0); \ asmlinkage long sys_##sname(void); \ ALLOW_ERROR_INJECTION(sys_##sname, ERRNO); \ asmlinkage long sys_##sname(void) +#endif /* SYSCALL_DEFINE0 */ #define SYSCALL_DEFINE1 (name, ...) SYSCALL_DEFINEx(1, _##name, __VA_ARGS__)#define SYSCALL_DEFINE2 (name, ...) SYSCALL_DEFINEx(2, _##name, __VA_ARGS__)
@@ -209,6 +222,8 @@ static inline int is_syscall_trace_event(struct trace_event_call *tp_event) __SYSCALL_DEFINEx(x, sname, __VA_ARGS__)#define __PROTECT (...) asmlinkage_protect(__VA_ARGS__) + +#ifndef __SYSCALL_DEFINEx#define __SYSCALL_DEFINEx (x, name, ...) \ asmlinkage long sys##name(__MAP(x,__SC_DECL,__VA_ARGS__)) \ __attribute__((alias(__stringify(SyS##name)))); \
@@ -223,6 +238,7 @@ static inline int is_syscall_trace_event(struct trace_event_call *tp_event)return ret; \ } \ static inline long SYSC##name(__MAP(x,__SC_DECL,__VA_ARGS__)) +#endif /* __SYSCALL_DEFINEx */ /* * Called before coming back to user-mode. Returning to user-mode with an
@@ -252,7 +268,12 @@ static inline void addr_limit_user_check(void)* Please note that these prototypes here are only provided for information * purposes, for static analysis, and for linking from the syscall table. * These functions should not be called elsewhere from kernel code. +* +* As the syscall calling convention may be different from the default +* for architectures overriding the syscall calling convention, do not +* include the prototypes if CONFIG_ARCH_HAS_SYSCALL_WRAPPER is enabled. */ +#ifndef CONFIG_ARCH_HAS_SYSCALL_WRAPPER asmlinkage long sys_io_setup (unsigned nr_reqs,aio_context_t __user *ctx);asmlinkage long sys_io_destroy (aio_context_t ctx); asmlinkage long sys_io_submit(aio_context_t, long,
@@ -1076,6 +1097,8 @@ asmlinkage long sys_old_mmap(struct mmap_arg_struct __user *arg);*/ asmlinkage long sys_ni_syscall (void ); +#endif /* CONFIG_ARCH_HAS_SYSCALL_WRAPPER */ +/* * Kernel code should not call syscalls (i.e., sys_xyzyyz()) directly.
init/Kconfig +7 -0
@@ -1923,3 +1923,10 @@ source "kernel/Kconfig.locks" config ARCH_HAS_SYNC_CORE_BEFORE_USERMODE bool + +# It may be useful for an architecture to override the definitions of the +# SYSCALL_DEFINE() and __SYSCALL_DEFINEx() macros in <linux/syscalls.h>, +# in particular to use a different calling convention for syscalls. +config ARCH_HAS_SYSCALL_WRAPPER + def_bool n + depends on !COMPAT
Signature · 1 line
2.16.3
tip-bot for Dominik Brodowski
merge bot[tip:x86/asm] syscalls/core: Introduce CONFIG_ARCH_HAS_SYSCALL_WRAPPER=y
syscalls/core: Introduce CONFIG_ARCH_HAS_SYSCALL_WRAPPER=y
Commit-ID: 1bd21c6c21e848996339508d3ffb106d505256a8 Gitweb: https://git.kernel.org/tip/1bd21c6c21e848996339508d3ffb106d505256a8 Author: Dominik Brodowski <[email protected]> AuthorDate: Thu, 5 Apr 2018 11:53:01 +0200 Committer: Ingo Molnar <[email protected]> CommitDate: Thu, 5 Apr 2018 16:59:25 +0200
syscalls/core: Introduce CONFIG_ARCH_HAS_SYSCALL_WRAPPER=y
It may be useful for an architecture to override the definitions of the SYSCALL_DEFINE0() and __SYSCALL_DEFINEx() macros in <linux/syscalls.h>, in particular to use a different calling convention for syscalls.
This patch provides a mechanism to do so: It introduces CONFIG_ARCH_HAS_SYSCALL_WRAPPER. If it is enabled, <asm/sycall_wrapper.h> is included in <linux/syscalls.h> and may be used to define the macros mentioned above. Moreover, as the syscall calling convention may be different if CONFIG_ARCH_HAS_SYSCALL_WRAPPER is set, the syscall function prototypes in <linux/syscalls.h> are #ifndef'd out in that case.
--- include/linux/syscalls.h | 23 +++++++++++++++++++++++ init/Kconfig | 7 +++++++ 2 files changed, 30 insertions(+)
include/linux/syscalls.h +23 -0
@@ -81,6 +81,17 @@ union bpf_attr;#include <linux/key.h> #include <trace/syscall.h> +#ifdef CONFIG_ARCH_HAS_SYSCALL_WRAPPER +/* +* It may be useful for an architecture to override the definitions of the +* SYSCALL_DEFINE0() and __SYSCALL_DEFINEx() macros, in particular to use a +* different calling convention for syscalls. To allow for that, the prototypes +* for the sys_*() functions below will *not* be included if +* CONFIG_ARCH_HAS_SYSCALL_WRAPPER is enabled. +*/ +#include <asm/syscall_wrapper.h> +#endif /* CONFIG_ARCH_HAS_SYSCALL_WRAPPER */ +/* * __MAP - apply a macro to syscall arguments * __MAP(n, m, t1, a1, t2, a2, ..., tn, an) will expand to
@@ -189,11 +200,13 @@ static inline int is_syscall_trace_event(struct trace_event_call *tp_event) }#endif +#ifndef SYSCALL_DEFINE0 #define SYSCALL_DEFINE0 (sname) \ SYSCALL_METADATA(_##sname, 0); \ asmlinkage long sys_##sname(void); \ ALLOW_ERROR_INJECTION(sys_##sname, ERRNO); \ asmlinkage long sys_##sname(void) +#endif /* SYSCALL_DEFINE0 */ #define SYSCALL_DEFINE1 (name, ...) SYSCALL_DEFINEx(1, _##name, __VA_ARGS__)#define SYSCALL_DEFINE2 (name, ...) SYSCALL_DEFINEx(2, _##name, __VA_ARGS__)
@@ -209,6 +222,8 @@ static inline int is_syscall_trace_event(struct trace_event_call *tp_event) __SYSCALL_DEFINEx(x, sname, __VA_ARGS__)#define __PROTECT (...) asmlinkage_protect(__VA_ARGS__) + +#ifndef __SYSCALL_DEFINEx#define __SYSCALL_DEFINEx (x, name, ...) \ asmlinkage long sys##name(__MAP(x,__SC_DECL,__VA_ARGS__)) \ __attribute__((alias(__stringify(SyS##name)))); \
@@ -223,6 +238,7 @@ static inline int is_syscall_trace_event(struct trace_event_call *tp_event)return ret; \ } \ static inline long SYSC##name(__MAP(x,__SC_DECL,__VA_ARGS__)) +#endif /* __SYSCALL_DEFINEx */ /* * Called before coming back to user-mode. Returning to user-mode with an
@@ -252,7 +268,12 @@ static inline void addr_limit_user_check(void)* Please note that these prototypes here are only provided for information * purposes, for static analysis, and for linking from the syscall table. * These functions should not be called elsewhere from kernel code. +* +* As the syscall calling convention may be different from the default +* for architectures overriding the syscall calling convention, do not +* include the prototypes if CONFIG_ARCH_HAS_SYSCALL_WRAPPER is enabled. */ +#ifndef CONFIG_ARCH_HAS_SYSCALL_WRAPPER asmlinkage long sys_io_setup (unsigned nr_reqs,aio_context_t __user *ctx);asmlinkage long sys_io_destroy (aio_context_t ctx); asmlinkage long sys_io_submit(aio_context_t, long,
@@ -1076,6 +1097,8 @@ asmlinkage long sys_old_mmap(struct mmap_arg_struct __user *arg);*/ asmlinkage long sys_ni_syscall (void ); +#endif /* CONFIG_ARCH_HAS_SYSCALL_WRAPPER */ +/* * Kernel code should not call syscalls (i.e., sys_xyzyyz()) directly.
init/Kconfig +7 -0
@@ -1923,3 +1923,10 @@ source "kernel/Kconfig.locks" config ARCH_HAS_SYNC_CORE_BEFORE_USERMODE bool + +# It may be useful for an architecture to override the definitions of the +# SYSCALL_DEFINE() and __SYSCALL_DEFINEx() macros in <linux/syscalls.h>, +# in particular to use a different calling convention for syscalls. +config ARCH_HAS_SYSCALL_WRAPPER + def_bool n + depends on !COMPAT
PATCH 3/8 syscalls/x86: use struct pt_regs based syscall calling for 64-bit syscalls
In reply to Dominik BrodowskiLet's make use of ARCH_HAS_SYSCALL_WRAPPER on pure 64-bit x86-64 systems:
Each syscall defines a stub which takes struct pt_regs as its only argument. It decodes just those parameters it needs, e.g:
asmlinkage long sys_xyzzy(const struct pt_regs *regs)
{
return SyS_xyzzy(regs->di, regs->si, regs->dx);
}This approach avoids leaking random user-provided register content down the call chain.
For example, for sys_recv() which is a 4-parameter syscall, the assembly now is (in slightly reordered fashion):
<sys_recv>: callq <__fentry__> /* decode regs->di, ->si, ->dx and ->r10 */ mov 0x70(%rdi),%rdi mov 0x68(%rdi),%rsi mov 0x60(%rdi),%rdx mov 0x38(%rdi),%rcx [ SyS_recv() is automatically inlined by the compiler, as it is not [yet] used anywhere else ] /* clear %r9 and %r8, the 5th and 6th args */ xor %r9d,%r9d xor %r8d,%r8d /* do the actual work */ callq __sys_recvfrom /* cleanup and return */ cltq retq
The only valid place in an x86-64 kernel which rightfully calls a syscall function on its own -- vsyscall -- needs to be modified to pass struct pt_regs onwards as well.
To keep the syscall table generation working independent of SYSCALL_PTREGS being enabled, the stubs are named the same as the "original" syscall stubs, i.e. sys_*().
This patch is based on an original proof-of-concept
From: Linus Torvalds <[email protected]>
and was split up and heavily modified by me, in particular to base it on ARCH_HAS_SYSCALL_WRAPPER, to limit it to 64-bit-only for the time being, and to update the vsyscall to the new calling convention.
--- arch/x86/Kconfig | 5 +++ arch/x86/entry/common.c | 4 ++ arch/x86/entry/syscall_64.c | 9 ++++- arch/x86/entry/vsyscall/vsyscall_64.c | 22 +++++++++++ arch/x86/include/asm/syscall.h | 4 ++ arch/x86/include/asm/syscall_wrapper.h | 70 ++++++++++++++++++++++++++++++++++ arch/x86/include/asm/syscalls.h | 7 ++++ include/linux/syscalls.h | 2 +- 8 files changed, 120 insertions(+), 3 deletions(-) create mode 100644 arch/x86/include/asm/syscall_wrapper.h
arch/x86/Kconfig +5 -0
@@ -2954,3 +2954,8 @@ source "crypto/Kconfig" source "arch/x86/kvm/Kconfig" source "lib/Kconfig" + +config SYSCALL_PTREGS + def_bool y + depends on X86_64 && !COMPAT + select ARCH_HAS_SYSCALL_WRAPPER
arch/x86/entry/common.c +4 -0
@@ -284,9 +284,13 @@ __visible void do_syscall_64(unsigned long nr, struct pt_regs *regs) nr &= __SYSCALL_MASK;if (likely (nr < NR_syscalls)) { nr =array_index_nospec (nr, NR_syscalls); +#ifdef CONFIG_SYSCALL_PTREGS + regs->ax = sys_call_table[nr](regs); +#else regs->ax = sys_call_table[nr]( regs->di, regs->si, regs->dx, regs->r10, regs->r8, regs->r9); +#endif }syscall_return_slowpath (regs);
arch/x86/entry/syscall_64.c +7 -2
@@ -7,14 +7,19 @@#include <asm/asm-offsets.h> #include <asm/syscall.h> +#ifdef CONFIG_SYSCALL_PTREGS +/* 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 *); +#else /* CONFIG_SYSCALL_PTREGS */ +extern asmlinkage long sys_ni_syscall (unsigned long ,unsigned long ,unsigned long ,unsigned long ,unsigned long ,unsigned long );#define __SYSCALL_64 (nr, sym, qual) extern asmlinkage long sym(unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, unsigned long); +#endif /* CONFIG_SYSCALL_PTREGS */ #include <asm/syscalls_64.h> #undef __SYSCALL_64#define __SYSCALL_64 (nr, sym, qual) [nr] = sym, -extern long sys_ni_syscall (unsigned long ,unsigned long ,unsigned long ,unsigned long ,unsigned long ,unsigned long ); - asmlinkage const sys_call_ptr_t sys_call_table[__NR_syscall_max+1] = {/* * Smells like a compiler bug -- it doesn't work
arch/x86/entry/vsyscall/vsyscall_64.c +22 -0
@@ -127,6 +127,9 @@ bool emulate_vsyscall(struct pt_regs *regs, unsigned long address)int vsyscall_nr, syscall_nr, tmp;int prev_sig_on_uaccess_err;long ret; +#ifdef CONFIG_SYSCALL_PTREGS +unsigned long orig_dx; +#endif /* * No point in checking CS -- the only way to get here is a user mode
@@ -227,19 +230,38 @@ bool emulate_vsyscall(struct pt_regs *regs, unsigned long address) ret = -EFAULT ;switch (vsyscall_nr) {case 0 : +#ifdef CONFIG_SYSCALL_PTREGS +/* this decodes regs->di and regs->si on its own */ + ret =sys_gettimeofday (regs); +#else ret =sys_gettimeofday ( (struct timeval __user *)regs->di, (struct timezone __user *)regs->si); +#endif /* CONFIG_SYSCALL_PTREGS */ break ;case 1 : +#ifdef CONFIG_SYSCALL_PTREGS +/* this decodes regs->di on its own */ + ret =sys_time (regs); +#else ret =sys_time ((time_t __user *)regs->di); +#endif /* CONFIG_SYSCALL_PTREGS */ break ;case 2 : +#ifdef CONFIG_SYSCALL_PTREGS +/* while we could clobber regs->dx, we didn't in the past... */ + orig_dx = regs->dx; + regs->dx =0 ; +/* this decodes regs->di, regs->si and regs->dx on its own */ + ret =sys_getcpu (regs); + regs->dx = orig_dx; +#else ret =sys_getcpu ((unsigned __user *)regs->di, (unsigned __user *)regs->si,NULL ); +#endif /* CONFIG_SYSCALL_PTREGS */ break ; }
arch/x86/include/asm/syscall.h +4 -0
@@ -20,9 +20,13 @@#include <asm/thread_info.h> /* for TS_COMPAT */ #include <asm/unistd.h> +#ifdef CONFIG_SYSCALL_PTREGS +typedef asmlinkage long (*sys_call_ptr_t )(const struct pt_regs *); +#else typedef asmlinkage long (*sys_call_ptr_t )(unsigned long ,unsigned long ,unsigned long ,unsigned long ,unsigned long ,unsigned long ); +#endif /* CONFIG_SYSCALL_PTREGS */ extern const sys_call_ptr_t sys_call_table[];#if defined(CONFIG_X86_32 )
arch/x86/include/asm/syscall_wrapper.h new file +70 -0
70 lines not on this page · raw message
arch/x86/include/asm/syscalls.h +7 -0
@@ -18,6 +18,12 @@/* Common in X86_32 and X86_64 */ /* kernel/ioport.c */ long ksys_ioperm (unsigned long from,unsigned long num,int turn_on); + +#ifndef CONFIG_SYSCALL_PTREGS +/* +* If CONFIG_SYSCALL_PTREGS is enabled, a different syscall calling convention +* is used. Do not include these -- invalid -- prototypes then +*/ asmlinkage long sys_ioperm (unsigned long ,unsigned long ,int );asmlinkage long sys_iopl (unsigned int );
@@ -53,4 +59,5 @@ asmlinkage long sys_mmap(unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, unsigned long);#endif /* CONFIG_X86_32 */ +#endif /* CONFIG_SYSCALL_PTREGS */ #endif /* _ASM_X86_SYSCALLS_H */
include/linux/syscalls.h +1 -1
@@ -102,7 +102,7 @@ union bpf_attr;* for SYSCALL_DEFINE<n>/COMPAT_SYSCALL_DEFINE<n> */ #define __MAP0 (m,...) -#define __MAP1 (m,t,a) m(t,a) +#define __MAP1 (m,t,a,...) m(t,a)#define __MAP2 (m,t,a,...) m(t,a), __MAP1(m,__VA_ARGS__)#define __MAP3 (m,t,a,...) m(t,a), __MAP2(m,__VA_ARGS__)#define __MAP4 (m,t,a,...) m(t,a), __MAP3(m,__VA_ARGS__)
Signature · 1 line
2.16.3
tip-bot for Dominik Brodowski
merge bot[tip:x86/asm] syscalls/x86: Use 'struct pt_regs' based syscall calling convention for 64-bit syscalls
syscalls/x86: Use 'struct pt_regs' based syscall calling convention for 64-bit syscalls
Commit-ID: fa697140f9a20119a9ec8fd7460cc4314fbdaff3 Gitweb: https://git.kernel.org/tip/fa697140f9a20119a9ec8fd7460cc4314fbdaff3 Author: Dominik Brodowski <[email protected]> AuthorDate: Thu, 5 Apr 2018 11:53:02 +0200 Committer: Ingo Molnar <[email protected]> CommitDate: Thu, 5 Apr 2018 16:59:26 +0200
syscalls/x86: Use 'struct pt_regs' based syscall calling convention for 64-bit syscalls
Let's make use of ARCH_HAS_SYSCALL_WRAPPER=y on pure 64-bit x86-64 systems:
Each syscall defines a stub which takes struct pt_regs as its only argument. It decodes just those parameters it needs, e.g:
asmlinkage long sys_xyzzy(const struct pt_regs *regs)
{
return SyS_xyzzy(regs->di, regs->si, regs->dx);
}This approach avoids leaking random user-provided register content down the call chain.
For example, for sys_recv() which is a 4-parameter syscall, the assembly now is (in slightly reordered fashion):
<sys_recv>: callq <__fentry__> /* decode regs->di, ->si, ->dx and ->r10 */ mov 0x70(%rdi),%rdi mov 0x68(%rdi),%rsi mov 0x60(%rdi),%rdx mov 0x38(%rdi),%rcx [ SyS_recv() is automatically inlined by the compiler, as it is not [yet] used anywhere else ] /* clear %r9 and %r8, the 5th and 6th args */ xor %r9d,%r9d xor %r8d,%r8d /* do the actual work */ callq __sys_recvfrom /* cleanup and return */ cltq retq
The only valid place in an x86-64 kernel which rightfully calls a syscall function on its own -- vsyscall -- needs to be modified to pass struct pt_regs onwards as well.
To keep the syscall table generation working independent of SYSCALL_PTREGS being enabled, the stubs are named the same as the "original" syscall stubs, i.e. sys_*().
This patch is based on an original proof-of-concept
| From: Linus Torvalds <[email protected]> | Signed-off-by: Linus Torvalds <[email protected]>
and was split up and heavily modified by me, in particular to base it on ARCH_HAS_SYSCALL_WRAPPER, to limit it to 64-bit-only for the time being, and to update the vsyscall to the new calling convention.
--- arch/x86/Kconfig | 5 +++ arch/x86/entry/common.c | 4 ++ arch/x86/entry/syscall_64.c | 9 ++++- arch/x86/entry/vsyscall/vsyscall_64.c | 22 +++++++++++ arch/x86/include/asm/syscall.h | 4 ++ arch/x86/include/asm/syscall_wrapper.h | 70 ++++++++++++++++++++++++++++++++++ arch/x86/include/asm/syscalls.h | 7 ++++ include/linux/syscalls.h | 2 +- 8 files changed, 120 insertions(+), 3 deletions(-)
arch/x86/Kconfig +5 -0
@@ -2954,3 +2954,8 @@ source "crypto/Kconfig" source "arch/x86/kvm/Kconfig" source "lib/Kconfig" + +config SYSCALL_PTREGS + def_bool y + depends on X86_64 && !COMPAT + select ARCH_HAS_SYSCALL_WRAPPER
arch/x86/entry/common.c +4 -0
@@ -284,9 +284,13 @@ __visible void do_syscall_64(unsigned long nr, struct pt_regs *regs) nr &= __SYSCALL_MASK;if (likely (nr < NR_syscalls)) { nr =array_index_nospec (nr, NR_syscalls); +#ifdef CONFIG_SYSCALL_PTREGS + regs->ax = sys_call_table[nr](regs); +#else regs->ax = sys_call_table[nr]( regs->di, regs->si, regs->dx, regs->r10, regs->r8, regs->r9); +#endif }syscall_return_slowpath (regs);
arch/x86/entry/syscall_64.c +7 -2
@@ -7,14 +7,19 @@#include <asm/asm-offsets.h> #include <asm/syscall.h> +#ifdef CONFIG_SYSCALL_PTREGS +/* 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 *); +#else /* CONFIG_SYSCALL_PTREGS */ +extern asmlinkage long sys_ni_syscall (unsigned long ,unsigned long ,unsigned long ,unsigned long ,unsigned long ,unsigned long );#define __SYSCALL_64 (nr, sym, qual) extern asmlinkage long sym(unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, unsigned long); +#endif /* CONFIG_SYSCALL_PTREGS */ #include <asm/syscalls_64.h> #undef __SYSCALL_64#define __SYSCALL_64 (nr, sym, qual) [nr] = sym, -extern long sys_ni_syscall (unsigned long ,unsigned long ,unsigned long ,unsigned long ,unsigned long ,unsigned long ); - asmlinkage const sys_call_ptr_t sys_call_table[__NR_syscall_max+1] = {/* * Smells like a compiler bug -- it doesn't work
arch/x86/entry/vsyscall/vsyscall_64.c +22 -0
@@ -127,6 +127,9 @@ bool emulate_vsyscall(struct pt_regs *regs, unsigned long address)int vsyscall_nr, syscall_nr, tmp;int prev_sig_on_uaccess_err;long ret; +#ifdef CONFIG_SYSCALL_PTREGS +unsigned long orig_dx; +#endif /* * No point in checking CS -- the only way to get here is a user mode
@@ -227,19 +230,38 @@ bool emulate_vsyscall(struct pt_regs *regs, unsigned long address) ret = -EFAULT ;switch (vsyscall_nr) {case 0 : +#ifdef CONFIG_SYSCALL_PTREGS +/* this decodes regs->di and regs->si on its own */ + ret =sys_gettimeofday (regs); +#else ret =sys_gettimeofday ( (struct timeval __user *)regs->di, (struct timezone __user *)regs->si); +#endif /* CONFIG_SYSCALL_PTREGS */ break ;case 1 : +#ifdef CONFIG_SYSCALL_PTREGS +/* this decodes regs->di on its own */ + ret =sys_time (regs); +#else ret =sys_time ((time_t __user *)regs->di); +#endif /* CONFIG_SYSCALL_PTREGS */ break ;case 2 : +#ifdef CONFIG_SYSCALL_PTREGS +/* while we could clobber regs->dx, we didn't in the past... */ + orig_dx = regs->dx; + regs->dx =0 ; +/* this decodes regs->di, regs->si and regs->dx on its own */ + ret =sys_getcpu (regs); + regs->dx = orig_dx; +#else ret =sys_getcpu ((unsigned __user *)regs->di, (unsigned __user *)regs->si,NULL ); +#endif /* CONFIG_SYSCALL_PTREGS */ break ; }
arch/x86/include/asm/syscall.h +4 -0
@@ -20,9 +20,13 @@#include <asm/thread_info.h> /* for TS_COMPAT */ #include <asm/unistd.h> +#ifdef CONFIG_SYSCALL_PTREGS +typedef asmlinkage long (*sys_call_ptr_t )(const struct pt_regs *); +#else typedef asmlinkage long (*sys_call_ptr_t )(unsigned long ,unsigned long ,unsigned long ,unsigned long ,unsigned long ,unsigned long ); +#endif /* CONFIG_SYSCALL_PTREGS */ extern const sys_call_ptr_t sys_call_table[];#if defined(CONFIG_X86_32 )
arch/x86/include/asm/syscall_wrapper.h new file +70 -0
70 lines not on this page · raw message
arch/x86/include/asm/syscalls.h +7 -0
@@ -18,6 +18,12 @@/* Common in X86_32 and X86_64 */ /* kernel/ioport.c */ long ksys_ioperm (unsigned long from,unsigned long num,int turn_on); + +#ifndef CONFIG_SYSCALL_PTREGS +/* +* If CONFIG_SYSCALL_PTREGS is enabled, a different syscall calling convention +* is used. Do not include these -- invalid -- prototypes then +*/ asmlinkage long sys_ioperm (unsigned long ,unsigned long ,int );asmlinkage long sys_iopl (unsigned int );
@@ -53,4 +59,5 @@ asmlinkage long sys_mmap(unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, unsigned long);#endif /* CONFIG_X86_32 */ +#endif /* CONFIG_SYSCALL_PTREGS */ #endif /* _ASM_X86_SYSCALLS_H */
include/linux/syscalls.h +1 -1
@@ -102,7 +102,7 @@ union bpf_attr;* for SYSCALL_DEFINE<n>/COMPAT_SYSCALL_DEFINE<n> */ #define __MAP0 (m,...) -#define __MAP1 (m,t,a) m(t,a) +#define __MAP1 (m,t,a,...) m(t,a)#define __MAP2 (m,t,a,...) m(t,a), __MAP1(m,__VA_ARGS__)#define __MAP3 (m,t,a,...) m(t,a), __MAP2(m,__VA_ARGS__)#define __MAP4 (m,t,a,...) m(t,a), __MAP3(m,__VA_ARGS__)
PATCH 4/8 syscalls: prepare ARCH_HAS_SYSCALL_WRAPPER for compat syscalls
In reply to Dominik BrodowskiIt may be useful for an architecture to override the definitions of the COMPAT_SYSCALL_DEFINE0() and __COMPAT_SYSCALL_DEFINEx() macros in <linux/compat.h>, in particular to use a different calling convention for syscalls. This patch provides a mechanism to do so, based on the previously introduced CONFIG_ARCH_HAS_SYSCALL_WRAPPER. If it is enabled, <asm/sycall_wrapper.h> is included in <linux/compat.h> and may be used to define the macros mentioned above. Moreover, as the syscall calling convention may be different if CONFIG_ARCH_HAS_SYSCALL_WRAPPER is set, the compat syscall function prototypes in <linux/compat.h> are #ifndef'd out in that case.
As some of the syscalls and/or compat syscalls may not be present, the COND_SYSCALL() and COND_SYSCALL_COMPAT() macros in kernel/sys_ni.c as well as the SYS_NI() and COMPAT_SYS_NI() macros in kernel/time/posix-stubs.c can be re-defined in <asm/syscall_wrapper.h> iff CONFIG_ARCH_HAS_SYSCALL_WRAPPER is enabled.
--- include/linux/compat.h | 22 ++++++++++++++++++++++ init/Kconfig | 9 ++++++--- kernel/sys_ni.c | 10 ++++++++++ kernel/time/posix-stubs.c | 10 ++++++++++ 4 files changed, 48 insertions(+), 3 deletions(-)
include/linux/compat.h +22 -0
@@ -24,6 +24,17 @@#include <asm/siginfo.h> #include <asm/signal.h> +#ifdef CONFIG_ARCH_HAS_SYSCALL_WRAPPER +/* +* It may be useful for an architecture to override the definitions of the +* COMPAT_SYSCALL_DEFINE0 and COMPAT_SYSCALL_DEFINEx() macros, in particular +* to use a different calling convention for syscalls. To allow for that, ++ the prototypes for the compat_sys_*() functions below will *not* be included +* if CONFIG_ARCH_HAS_SYSCALL_WRAPPER is enabled. +*/ +#include <asm/syscall_wrapper.h> +#endif /* CONFIG_ARCH_HAS_SYSCALL_WRAPPER */ +#ifndef COMPAT_USE_64BIT_TIME #define COMPAT_USE_64BIT_TIME 0#endif
@@ -32,10 +43,12 @@#define __SC_DELOUSE (t,v) ((__force t)(unsigned long)(v))#endif +#ifndef COMPAT_SYSCALL_DEFINE0 #define COMPAT_SYSCALL_DEFINE0 (name) \ asmlinkage long compat_sys_##name(void); \ ALLOW_ERROR_INJECTION(compat_sys_##name, ERRNO); \ asmlinkage long compat_sys_##name(void) +#endif /* COMPAT_SYSCALL_DEFINE0 */ #define COMPAT_SYSCALL_DEFINE1 (name, ...) \ COMPAT_SYSCALL_DEFINEx(1, _##name, __VA_ARGS__)
@@ -50,6 +63,7 @@#define COMPAT_SYSCALL_DEFINE6 (name, ...) \ COMPAT_SYSCALL_DEFINEx(6, _##name, __VA_ARGS__) +#ifndef COMPAT_SYSCALL_DEFINEx#define COMPAT_SYSCALL_DEFINEx (x, name, ...) \ asmlinkage long compat_sys##name(__MAP(x,__SC_DECL,__VA_ARGS__));\ asmlinkage long compat_sys##name(__MAP(x,__SC_DECL,__VA_ARGS__))\
@@ -62,6 +76,7 @@ return C_SYSC##name(__MAP(x,__SC_DELOUSE,__VA_ARGS__)); \ } \ static inline long C_SYSC##name(__MAP(x,__SC_DECL,__VA_ARGS__)) +#endif /* COMPAT_SYSCALL_DEFINEx */ #ifndef compat_user_stack_pointer#define compat_user_stack_pointer () current_user_stack_pointer()
@@ -517,7 +532,12 @@ int __compat_save_altstack(compat_stack_t __user *, unsigned long);* Please note that these prototypes here are only provided for information * purposes, for static analysis, and for linking from the syscall table. * These functions should not be called elsewhere from kernel code. +* +* As the syscall calling convention may be different from the default +* for architectures overriding the syscall calling convention, do not +* include the prototypes if CONFIG_ARCH_HAS_SYSCALL_WRAPPER is enabled. */ +#ifndef CONFIG_ARCH_HAS_SYSCALL_WRAPPER asmlinkage long compat_sys_io_setup (unsigned nr_reqs,u32 __user *ctx32p);asmlinkage long compat_sys_io_submit (compat_aio_context_t ctx_id,int nr,u32 __user *iocb);
@@ -955,6 +975,8 @@ asmlinkage long compat_sys_stime(compat_time_t __user *tptr);/* obsolete: net/socket.c */ asmlinkage long compat_sys_socketcall (int call,u32 __user *args); +#endif /* CONFIG_ARCH_HAS_SYSCALL_WRAPPER */ +/* * For most but not all architectures, "am I in a compat syscall?" and
init/Kconfig +6 -3
@@ -1925,8 +1925,11 @@ config ARCH_HAS_SYNC_CORE_BEFORE_USERMODE bool # It may be useful for an architecture to override the definitions of the -# SYSCALL_DEFINE() and __SYSCALL_DEFINEx() macros in <linux/syscalls.h>, -# in particular to use a different calling convention for syscalls. +# SYSCALL_DEFINE() and __SYSCALL_DEFINEx() macros in <linux/syscalls.h> +# and the COMPAT_ variants in <linux/compat.h>, in particular to use a +# different calling convention for syscalls. They can also override the +# macros for not-implemented syscalls in kernel/sys_ni.c and +# kernel/time/posix-stubs.c. All these overrides need to be available in +# <asm/syscall_wrapper.h>. config ARCH_HAS_SYSCALL_WRAPPER def_bool n - depends on !COMPAT
kernel/sys_ni.c +10 -0
@@ -5,6 +5,11 @@#include <asm/unistd.h> +#ifdef CONFIG_ARCH_HAS_SYSCALL_WRAPPER +/* Architectures may override COND_SYSCALL and COND_SYSCALL_COMPAT */ +#include <asm/syscall_wrapper.h> +#endif /* CONFIG_ARCH_HAS_SYSCALL_WRAPPER */ +/* we can't #include <linux/syscalls.h> here, but tell gcc to not warn with -Wmissing-prototypes */ asmlinkage long sys_ni_syscall (void );
@@ -17,8 +22,13 @@ asmlinkage long sys_ni_syscall(void)return -ENOSYS ; } +#ifndef COND_SYSCALL #define COND_SYSCALL (name) cond_syscall(sys_##name) +#endif /* COND_SYSCALL */ + +#ifndef COND_SYSCALL_COMPAT #define COND_SYSCALL_COMPAT (name) cond_syscall(compat_sys_##name) +#endif /* COND_SYSCALL_COMPAT */ /* * This list is kept in the same order as include/uapi/asm-generic/unistd.h.
kernel/time/posix-stubs.c +10 -0
@@ -19,6 +19,11 @@#include <linux/posix-timers.h> #include <linux/compat.h> +#ifdef CONFIG_ARCH_HAS_SYSCALL_WRAPPER +/* Architectures may override SYS_NI and COMPAT_SYS_NI */ +#include <asm/syscall_wrapper.h> +#endif +asmlinkage long sys_ni_posix_timers (void ) { pr_err_once("process %d (%s) attempted a POSIX timer syscall "
@@ -27,8 +32,13 @@ asmlinkage long sys_ni_posix_timers(void)return -ENOSYS ; } +#ifndef SYS_NI #define SYS_NI (name) SYSCALL_ALIAS(sys_##name, sys_ni_posix_timers) +#endif + +#ifndef COMPAT_SYS_NI #define COMPAT_SYS_NI (name) SYSCALL_ALIAS(compat_sys_##name, sys_ni_posix_timers) +#endif SYS_NI (timer_create);SYS_NI (timer_gettime);
Signature · 1 line
2.16.3
tip-bot for Dominik Brodowski
merge bot[tip:x86/asm] syscalls/core: Prepare CONFIG_ARCH_HAS_SYSCALL_WRAPPER=y for compat syscalls
syscalls/core: Prepare CONFIG_ARCH_HAS_SYSCALL_WRAPPER=y for compat syscalls
Commit-ID: 7303e30ec1d8fb5ca1f07c92d069241c32b2ee1b Gitweb: https://git.kernel.org/tip/7303e30ec1d8fb5ca1f07c92d069241c32b2ee1b Author: Dominik Brodowski <[email protected]> AuthorDate: Thu, 5 Apr 2018 11:53:03 +0200 Committer: Ingo Molnar <[email protected]> CommitDate: Thu, 5 Apr 2018 16:59:38 +0200
syscalls/core: Prepare CONFIG_ARCH_HAS_SYSCALL_WRAPPER=y for compat syscalls
It may be useful for an architecture to override the definitions of the COMPAT_SYSCALL_DEFINE0() and __COMPAT_SYSCALL_DEFINEx() macros in <linux/compat.h>, in particular to use a different calling convention for syscalls. This patch provides a mechanism to do so, based on the previously introduced CONFIG_ARCH_HAS_SYSCALL_WRAPPER. If it is enabled, <asm/sycall_wrapper.h> is included in <linux/compat.h> and may be used to define the macros mentioned above. Moreover, as the syscall calling convention may be different if CONFIG_ARCH_HAS_SYSCALL_WRAPPER is set, the compat syscall function prototypes in <linux/compat.h> are #ifndef'd out in that case.
As some of the syscalls and/or compat syscalls may not be present, the COND_SYSCALL() and COND_SYSCALL_COMPAT() macros in kernel/sys_ni.c as well as the SYS_NI() and COMPAT_SYS_NI() macros in kernel/time/posix-stubs.c can be re-defined in <asm/syscall_wrapper.h> iff CONFIG_ARCH_HAS_SYSCALL_WRAPPER is enabled.
--- include/linux/compat.h | 22 ++++++++++++++++++++++ init/Kconfig | 9 ++++++--- kernel/sys_ni.c | 10 ++++++++++ kernel/time/posix-stubs.c | 10 ++++++++++ 4 files changed, 48 insertions(+), 3 deletions(-)
include/linux/compat.h +22 -0
@@ -24,6 +24,17 @@#include <asm/siginfo.h> #include <asm/signal.h> +#ifdef CONFIG_ARCH_HAS_SYSCALL_WRAPPER +/* +* It may be useful for an architecture to override the definitions of the +* COMPAT_SYSCALL_DEFINE0 and COMPAT_SYSCALL_DEFINEx() macros, in particular +* to use a different calling convention for syscalls. To allow for that, ++ the prototypes for the compat_sys_*() functions below will *not* be included +* if CONFIG_ARCH_HAS_SYSCALL_WRAPPER is enabled. +*/ +#include <asm/syscall_wrapper.h> +#endif /* CONFIG_ARCH_HAS_SYSCALL_WRAPPER */ +#ifndef COMPAT_USE_64BIT_TIME #define COMPAT_USE_64BIT_TIME 0#endif
@@ -32,10 +43,12 @@#define __SC_DELOUSE (t,v) ((__force t)(unsigned long)(v))#endif +#ifndef COMPAT_SYSCALL_DEFINE0 #define COMPAT_SYSCALL_DEFINE0 (name) \ asmlinkage long compat_sys_##name(void); \ ALLOW_ERROR_INJECTION(compat_sys_##name, ERRNO); \ asmlinkage long compat_sys_##name(void) +#endif /* COMPAT_SYSCALL_DEFINE0 */ #define COMPAT_SYSCALL_DEFINE1 (name, ...) \ COMPAT_SYSCALL_DEFINEx(1, _##name, __VA_ARGS__)
@@ -50,6 +63,7 @@#define COMPAT_SYSCALL_DEFINE6 (name, ...) \ COMPAT_SYSCALL_DEFINEx(6, _##name, __VA_ARGS__) +#ifndef COMPAT_SYSCALL_DEFINEx#define COMPAT_SYSCALL_DEFINEx (x, name, ...) \ asmlinkage long compat_sys##name(__MAP(x,__SC_DECL,__VA_ARGS__));\ asmlinkage long compat_sys##name(__MAP(x,__SC_DECL,__VA_ARGS__))\
@@ -62,6 +76,7 @@ return C_SYSC##name(__MAP(x,__SC_DELOUSE,__VA_ARGS__)); \ } \ static inline long C_SYSC##name(__MAP(x,__SC_DECL,__VA_ARGS__)) +#endif /* COMPAT_SYSCALL_DEFINEx */ #ifndef compat_user_stack_pointer#define compat_user_stack_pointer () current_user_stack_pointer()
@@ -517,7 +532,12 @@ int __compat_save_altstack(compat_stack_t __user *, unsigned long);* Please note that these prototypes here are only provided for information * purposes, for static analysis, and for linking from the syscall table. * These functions should not be called elsewhere from kernel code. +* +* As the syscall calling convention may be different from the default +* for architectures overriding the syscall calling convention, do not +* include the prototypes if CONFIG_ARCH_HAS_SYSCALL_WRAPPER is enabled. */ +#ifndef CONFIG_ARCH_HAS_SYSCALL_WRAPPER asmlinkage long compat_sys_io_setup (unsigned nr_reqs,u32 __user *ctx32p);asmlinkage long compat_sys_io_submit (compat_aio_context_t ctx_id,int nr,u32 __user *iocb);
@@ -955,6 +975,8 @@ asmlinkage long compat_sys_stime(compat_time_t __user *tptr);/* obsolete: net/socket.c */ asmlinkage long compat_sys_socketcall (int call,u32 __user *args); +#endif /* CONFIG_ARCH_HAS_SYSCALL_WRAPPER */ +/* * For most but not all architectures, "am I in a compat syscall?" and
init/Kconfig +6 -3
@@ -1925,8 +1925,11 @@ config ARCH_HAS_SYNC_CORE_BEFORE_USERMODE bool # It may be useful for an architecture to override the definitions of the -# SYSCALL_DEFINE() and __SYSCALL_DEFINEx() macros in <linux/syscalls.h>, -# in particular to use a different calling convention for syscalls. +# SYSCALL_DEFINE() and __SYSCALL_DEFINEx() macros in <linux/syscalls.h> +# and the COMPAT_ variants in <linux/compat.h>, in particular to use a +# different calling convention for syscalls. They can also override the +# macros for not-implemented syscalls in kernel/sys_ni.c and +# kernel/time/posix-stubs.c. All these overrides need to be available in +# <asm/syscall_wrapper.h>. config ARCH_HAS_SYSCALL_WRAPPER def_bool n - depends on !COMPAT
kernel/sys_ni.c +10 -0
@@ -5,6 +5,11 @@#include <asm/unistd.h> +#ifdef CONFIG_ARCH_HAS_SYSCALL_WRAPPER +/* Architectures may override COND_SYSCALL and COND_SYSCALL_COMPAT */ +#include <asm/syscall_wrapper.h> +#endif /* CONFIG_ARCH_HAS_SYSCALL_WRAPPER */ +/* we can't #include <linux/syscalls.h> here, but tell gcc to not warn with -Wmissing-prototypes */ asmlinkage long sys_ni_syscall (void );
@@ -17,8 +22,13 @@ asmlinkage long sys_ni_syscall(void)return -ENOSYS ; } +#ifndef COND_SYSCALL #define COND_SYSCALL (name) cond_syscall(sys_##name) +#endif /* COND_SYSCALL */ + +#ifndef COND_SYSCALL_COMPAT #define COND_SYSCALL_COMPAT (name) cond_syscall(compat_sys_##name) +#endif /* COND_SYSCALL_COMPAT */ /* * This list is kept in the same order as include/uapi/asm-generic/unistd.h.
kernel/time/posix-stubs.c +10 -0
@@ -19,6 +19,11 @@#include <linux/posix-timers.h> #include <linux/compat.h> +#ifdef CONFIG_ARCH_HAS_SYSCALL_WRAPPER +/* Architectures may override SYS_NI and COMPAT_SYS_NI */ +#include <asm/syscall_wrapper.h> +#endif +asmlinkage long sys_ni_posix_timers (void ) { pr_err_once("process %d (%s) attempted a POSIX timer syscall "
@@ -27,8 +32,13 @@ asmlinkage long sys_ni_posix_timers(void)return -ENOSYS ; } +#ifndef SYS_NI #define SYS_NI (name) SYSCALL_ALIAS(sys_##name, sys_ni_posix_timers) +#endif + +#ifndef COMPAT_SYS_NI #define COMPAT_SYS_NI (name) SYSCALL_ALIAS(compat_sys_##name, sys_ni_posix_timers) +#endif SYS_NI (timer_create);SYS_NI (timer_gettime);
PATCH 5/8 syscalls/x86: use struct pt_regs based syscall calling for IA32_EMULATION and x32
In reply to Dominik BrodowskiExtend ARCH_HAS_SYSCALL_WRAPPER for i386 emulation and for x32 on 64-bit x86.
For x32, all we need to do is to create an additional stub for each compat syscall which decodes the parameters in x86-64 ordering, e.g.:
asmlinkage long __compat_sys_x32_xyzzy(struct pt_regs *regs)
{
return c_SyS_xyzzy(regs->di, regs->si, regs->dx);
}For i386 emulation, we need to teach compat_sys_*() to take struct pt_regs as its only argument, e.g.:
asmlinkage long __compat_sys_ia32_xyzzy(struct pt_regs *regs)
{
return c_SyS_xyzzy(regs->bx, regs->cx, regs->dx);
}In addition, we need to create additional stubs for common syscalls (that is, for syscalls which have the same parameters on 32-bit and 64-bit), e.g.:
asmlinkage long __sys_ia32_xyzzy(struct pt_regs *regs)
{
return c_sys_xyzzy(regs->bx, regs->cx, regs->dx);
}This approach avoids leaking random user-provided register content down the call chain.
This patch is based on an original proof-of-concept
From: Linus Torvalds <[email protected]>
and was split up and heavily modified by me, in particular to base it on ARCH_HAS_SYSCALL_WRAPPER.
--- arch/x86/Kconfig | 2 +- arch/x86/entry/common.c | 4 + arch/x86/entry/syscall_32.c | 15 +- arch/x86/entry/syscalls/syscall_32.tbl | 677 +++++++++++++++++---------------- arch/x86/entry/syscalls/syscall_64.tbl | 74 ++-- arch/x86/include/asm/syscall_wrapper.h | 117 +++++- 6 files changed, 509 insertions(+), 380 deletions(-)
arch/x86/Kconfig +1 -1
@@ -2957,5 +2957,5 @@ source "lib/Kconfig" config SYSCALL_PTREGS def_bool y - depends on X86_64 && !COMPAT + depends on X86_64 select ARCH_HAS_SYSCALL_WRAPPER
arch/x86/entry/common.c +4 -0
@@ -325,6 +325,9 @@ static __always_inline void do_syscall_32_irqs_on(struct pt_regs *regs)if (likely (nr < IA32_NR_syscalls)) { nr =array_index_nospec (nr, IA32_NR_syscalls); +#ifdef CONFIG_SYSCALL_PTREGS + regs->ax = ia32_sys_call_table[nr](regs); +#else /* * It's possible that a 32-bit syscall implementation * takes a 64-bit parameter but nonetheless assumes that
@@ -335,6 +338,7 @@ static __always_inline void do_syscall_32_irqs_on(struct pt_regs *regs) (unsigned int )regs->bx, (unsigned int )regs->cx, (unsigned int )regs->dx, (unsigned int )regs->si, (unsigned int)regs->di, (unsigned int)regs->bp); +#endif /* CONFIG_SYSCALL_PTREGS */ }syscall_return_slowpath (regs);
arch/x86/entry/syscall_32.c +12 -3
@@ -7,14 +7,23 @@#include <asm/asm-offsets.h> #include <asm/syscall.h> -#define __SYSCALL_I386 (nr, sym, qual) extern asmlinkage long sym(unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, unsigned long) ; +#ifdef CONFIG_SYSCALL_PTREGS +/* On X86_64, we use struct pt_regs * to pass parameters to syscalls */ +#define __SYSCALL_I386 (nr, sym, qual) extern asmlinkage long sym(const struct pt_regs *); + +/* 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 *); + +#else /* CONFIG_SYSCALL_PTREGS */ +#define __SYSCALL_I386 (nr, sym, qual) extern asmlinkage long sym(unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, unsigned long); +extern asmlinkage long sys_ni_syscall (unsigned long ,unsigned long ,unsigned long ,unsigned long ,unsigned long ,unsigned long ); +#endif /* CONFIG_SYSCALL_PTREGS */ +#include <asm/syscalls_32.h> #undef __SYSCALL_I386#define __SYSCALL_I386 (nr, sym, qual) [nr] = sym, -extern asmlinkage long sys_ni_syscall (unsigned long ,unsigned long ,unsigned long ,unsigned long ,unsigned long ,unsigned long ); - __visible const sys_call_ptr_t ia32_sys_call_table[__NR_syscall_compat_max+1] = {/* * Smells like a compiler bug -- it doesn't work
arch/x86/entry/syscalls/syscall_32.tbl +341 -336
731 lines not on this page · raw message
arch/x86/entry/syscalls/syscall_64.tbl +38 -36
79 lines not on this page · raw message
arch/x86/include/asm/syscall_wrapper.h +113 -4
138 lines not on this page · raw message
Signature · 1 line
2.16.3
tip-bot for Dominik Brodowski
merge bot[tip:x86/asm] syscalls/x86: Use 'struct pt_regs' based syscall calling for IA32_EMULATION and x32
syscalls/x86: Use 'struct pt_regs' based syscall calling for IA32_EMULATION and x32
Commit-ID: ebeb8c82ffaf94435806ff0b686fffd41dd410b5 Gitweb: https://git.kernel.org/tip/ebeb8c82ffaf94435806ff0b686fffd41dd410b5 Author: Dominik Brodowski <[email protected]> AuthorDate: Thu, 5 Apr 2018 11:53:04 +0200 Committer: Ingo Molnar <[email protected]> CommitDate: Thu, 5 Apr 2018 16:59:38 +0200
syscalls/x86: Use 'struct pt_regs' based syscall calling for IA32_EMULATION and x32
Extend ARCH_HAS_SYSCALL_WRAPPER for i386 emulation and for x32 on 64-bit x86.
For x32, all we need to do is to create an additional stub for each compat syscall which decodes the parameters in x86-64 ordering, e.g.:
asmlinkage long __compat_sys_x32_xyzzy(struct pt_regs *regs)
{
return c_SyS_xyzzy(regs->di, regs->si, regs->dx);
}For i386 emulation, we need to teach compat_sys_*() to take struct pt_regs as its only argument, e.g.:
asmlinkage long __compat_sys_ia32_xyzzy(struct pt_regs *regs)
{
return c_SyS_xyzzy(regs->bx, regs->cx, regs->dx);
}In addition, we need to create additional stubs for common syscalls (that is, for syscalls which have the same parameters on 32-bit and 64-bit), e.g.:
asmlinkage long __sys_ia32_xyzzy(struct pt_regs *regs)
{
return c_sys_xyzzy(regs->bx, regs->cx, regs->dx);
}This approach avoids leaking random user-provided register content down the call chain.
This patch is based on an original proof-of-concept
| From: Linus Torvalds <[email protected]> | Signed-off-by: Linus Torvalds <[email protected]>
and was split up and heavily modified by me, in particular to base it on ARCH_HAS_SYSCALL_WRAPPER.
--- arch/x86/Kconfig | 2 +- arch/x86/entry/common.c | 4 + arch/x86/entry/syscall_32.c | 15 +- arch/x86/entry/syscalls/syscall_32.tbl | 677 +++++++++++++++++---------------- arch/x86/entry/syscalls/syscall_64.tbl | 74 ++-- arch/x86/include/asm/syscall_wrapper.h | 117 +++++- 6 files changed, 509 insertions(+), 380 deletions(-)
arch/x86/Kconfig +1 -1
@@ -2957,5 +2957,5 @@ source "lib/Kconfig" config SYSCALL_PTREGS def_bool y - depends on X86_64 && !COMPAT + depends on X86_64 select ARCH_HAS_SYSCALL_WRAPPER
arch/x86/entry/common.c +4 -0
@@ -325,6 +325,9 @@ static __always_inline void do_syscall_32_irqs_on(struct pt_regs *regs)if (likely (nr < IA32_NR_syscalls)) { nr =array_index_nospec (nr, IA32_NR_syscalls); +#ifdef CONFIG_SYSCALL_PTREGS + regs->ax = ia32_sys_call_table[nr](regs); +#else /* * It's possible that a 32-bit syscall implementation * takes a 64-bit parameter but nonetheless assumes that
@@ -335,6 +338,7 @@ static __always_inline void do_syscall_32_irqs_on(struct pt_regs *regs) (unsigned int )regs->bx, (unsigned int )regs->cx, (unsigned int )regs->dx, (unsigned int )regs->si, (unsigned int)regs->di, (unsigned int)regs->bp); +#endif /* CONFIG_SYSCALL_PTREGS */ }syscall_return_slowpath (regs);
arch/x86/entry/syscall_32.c +12 -3
@@ -7,14 +7,23 @@#include <asm/asm-offsets.h> #include <asm/syscall.h> -#define __SYSCALL_I386 (nr, sym, qual) extern asmlinkage long sym(unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, unsigned long) ; +#ifdef CONFIG_SYSCALL_PTREGS +/* On X86_64, we use struct pt_regs * to pass parameters to syscalls */ +#define __SYSCALL_I386 (nr, sym, qual) extern asmlinkage long sym(const struct pt_regs *); + +/* 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 *); + +#else /* CONFIG_SYSCALL_PTREGS */ +#define __SYSCALL_I386 (nr, sym, qual) extern asmlinkage long sym(unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, unsigned long); +extern asmlinkage long sys_ni_syscall (unsigned long ,unsigned long ,unsigned long ,unsigned long ,unsigned long ,unsigned long ); +#endif /* CONFIG_SYSCALL_PTREGS */ +#include <asm/syscalls_32.h> #undef __SYSCALL_I386#define __SYSCALL_I386 (nr, sym, qual) [nr] = sym, -extern asmlinkage long sys_ni_syscall (unsigned long ,unsigned long ,unsigned long ,unsigned long ,unsigned long ,unsigned long ); - __visible const sys_call_ptr_t ia32_sys_call_table[__NR_syscall_compat_max+1] = {/* * Smells like a compiler bug -- it doesn't work
arch/x86/entry/syscalls/syscall_32.tbl +341 -336
731 lines not on this page · raw message
arch/x86/entry/syscalls/syscall_64.tbl +38 -36
79 lines not on this page · raw message
arch/x86/include/asm/syscall_wrapper.h +113 -4
138 lines not on this page · raw message
PATCH 6/8 syscalls/x86: unconditionally enable struct pt_regs based syscalls on x86_64
In reply to Dominik BrodowskiRemoving CONFIG_SYSCALL_PTREGS from arch/x86/Kconfig and simply selecting ARCH_HAS_SYSCALL_WRAPPER unconditionally on x86-64 allows us to simplify several codepaths.
--- arch/x86/Kconfig | 6 +----- arch/x86/entry/common.c | 10 ++-------- arch/x86/entry/syscall_32.c | 6 +++--- arch/x86/entry/syscall_64.c | 5 ----- arch/x86/entry/vsyscall/vsyscall_64.c | 18 ------------------ arch/x86/include/asm/syscall.h | 4 ++-- arch/x86/include/asm/syscalls.h | 20 ++++---------------- 7 files changed, 12 insertions(+), 57 deletions(-)
arch/x86/Kconfig +1 -5
@@ -29,6 +29,7 @@ config X86_64 select HAVE_ARCH_SOFT_DIRTY select MODULES_USE_ELF_RELA select X86_DEV_DMA_OPS + select ARCH_HAS_SYSCALL_WRAPPER # # Arch settings
@@ -2954,8 +2955,3 @@ source "crypto/Kconfig" source "arch/x86/kvm/Kconfig" source "lib/Kconfig" - -config SYSCALL_PTREGS - def_bool y - depends on X86_64 - select ARCH_HAS_SYSCALL_WRAPPER
arch/x86/entry/common.c +2 -8
@@ -284,13 +284,7 @@ __visible void do_syscall_64(unsigned long nr, struct pt_regs *regs) nr &= __SYSCALL_MASK;if (likely (nr < NR_syscalls)) { nr =array_index_nospec (nr, NR_syscalls); -#ifdef CONFIG_SYSCALL_PTREGS regs->ax = sys_call_table[nr](regs); -#else - regs->ax = sys_call_table[nr]( - regs->di, regs->si, regs->dx, - regs->r10, regs->r8, regs->r9); -#endif }syscall_return_slowpath (regs);
@@ -325,7 +319,7 @@ static __always_inline void do_syscall_32_irqs_on(struct pt_regs *regs)if (likely (nr < IA32_NR_syscalls)) { nr =array_index_nospec (nr, IA32_NR_syscalls); -#ifdef CONFIG_SYSCALL_PTREGS +#ifdef CONFIG_IA32_EMULATION regs->ax = ia32_sys_call_table[nr](regs);#else /*
@@ -338,7 +332,7 @@ static __always_inline void do_syscall_32_irqs_on(struct pt_regs *regs) (unsigned int )regs->bx, (unsigned int )regs->cx, (unsigned int )regs->dx, (unsigned int )regs->si, (unsigned int)regs->di, (unsigned int)regs->bp); -#endif /* CONFIG_SYSCALL_PTREGS */ +#endif /* CONFIG_IA32_EMULATION */ }syscall_return_slowpath (regs);
arch/x86/entry/syscall_32.c +3 -3
@@ -7,17 +7,17 @@#include <asm/asm-offsets.h> #include <asm/syscall.h> -#ifdef CONFIG_SYSCALL_PTREGS +#ifdef CONFIG_IA32_EMULATION /* On X86_64, we use struct pt_regs * to pass parameters to syscalls */ #define __SYSCALL_I386 (nr, sym, qual) extern asmlinkage long sym(const struct pt_regs *);/* 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 *); -#else /* CONFIG_SYSCALL_PTREGS */ +#else /* CONFIG_IA32_EMULATION */ #define __SYSCALL_I386 (nr, sym, qual) extern asmlinkage long sym(unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, unsigned long);extern asmlinkage long sys_ni_syscall (unsigned long ,unsigned long ,unsigned long ,unsigned long ,unsigned long ,unsigned long ); -#endif /* CONFIG_SYSCALL_PTREGS */ +#endif /* CONFIG_IA32_EMULATION */ #include <asm/syscalls_32.h> #undef __SYSCALL_I386
arch/x86/entry/syscall_64.c +0 -5
@@ -7,14 +7,9 @@#include <asm/asm-offsets.h> #include <asm/syscall.h> -#ifdef CONFIG_SYSCALL_PTREGS /* 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 *); -#else /* CONFIG_SYSCALL_PTREGS */ -extern asmlinkage long sys_ni_syscall (unsigned long ,unsigned long ,unsigned long ,unsigned long ,unsigned long ,unsigned long ); -#define __SYSCALL_64 (nr, sym, qual) extern asmlinkage long sym(unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, unsigned long); -#endif /* CONFIG_SYSCALL_PTREGS */ #include <asm/syscalls_64.h> #undef __SYSCALL_64
arch/x86/entry/vsyscall/vsyscall_64.c +0 -18
@@ -127,9 +127,7 @@ bool emulate_vsyscall(struct pt_regs *regs, unsigned long address)int vsyscall_nr, syscall_nr, tmp;int prev_sig_on_uaccess_err;long ret; -#ifdef CONFIG_SYSCALL_PTREGS unsigned long orig_dx; -#endif /* * No point in checking CS -- the only way to get here is a user mode
@@ -230,38 +228,22 @@ bool emulate_vsyscall(struct pt_regs *regs, unsigned long address) ret = -EFAULT ;switch (vsyscall_nr) {case 0 : -#ifdef CONFIG_SYSCALL_PTREGS /* this decodes regs->di and regs->si on its own */ ret =sys_gettimeofday (regs); -#else - ret =sys_gettimeofday ( - (struct timeval __user *)regs->di, - (struct timezone __user *)regs->si); -#endif /* CONFIG_SYSCALL_PTREGS */ break ;case 1 : -#ifdef CONFIG_SYSCALL_PTREGS /* this decodes regs->di on its own */ ret =sys_time (regs); -#else - ret =sys_time ((time_t __user *)regs->di); -#endif /* CONFIG_SYSCALL_PTREGS */ break ;case 2 : -#ifdef CONFIG_SYSCALL_PTREGS /* while we could clobber regs->dx, we didn't in the past... */ orig_dx = regs->dx; regs->dx =0 ;/* this decodes regs->di, regs->si and regs->dx on its own */ ret =sys_getcpu (regs); regs->dx = orig_dx; -#else - ret =sys_getcpu ((unsigned __user *)regs->di, - (unsigned __user *)regs->si, -NULL ); -#endif /* CONFIG_SYSCALL_PTREGS */ break ; }
arch/x86/include/asm/syscall.h +2 -2
@@ -20,13 +20,13 @@#include <asm/thread_info.h> /* for TS_COMPAT */ #include <asm/unistd.h> -#ifdef CONFIG_SYSCALL_PTREGS +#ifdef CONFIG_X86_64 typedef asmlinkage long (*sys_call_ptr_t )(const struct pt_regs *);#else typedef asmlinkage long (*sys_call_ptr_t )(unsigned long ,unsigned long ,unsigned long ,unsigned long ,unsigned long ,unsigned long ); -#endif /* CONFIG_SYSCALL_PTREGS */ +#endif /* CONFIG_X86_64 */ extern const sys_call_ptr_t sys_call_table[];#if defined(CONFIG_X86_32 )
arch/x86/include/asm/syscalls.h +4 -16
@@ -19,10 +19,10 @@/* kernel/ioport.c */ long ksys_ioperm (unsigned long from,unsigned long num,int turn_on); -#ifndef CONFIG_SYSCALL_PTREGS -/* -* If CONFIG_SYSCALL_PTREGS is enabled, a different syscall calling convention -* is used. Do not include these -- invalid -- prototypes then +#ifdef CONFIG_X86_32 +/* +* These definitions are only valid on pure 32-bit systems; x86-64 uses a +* different syscall calling convention */ asmlinkage long sys_ioperm (unsigned long ,unsigned long ,int );asmlinkage long sys_iopl (unsigned int );
@@ -38,7 +38,6 @@ asmlinkage long sys_set_thread_area(struct user_desc __user *);asmlinkage long sys_get_thread_area (struct user_desc __user *);/* X86_32 only */ -#ifdef CONFIG_X86_32 /* kernel/signal.c */ asmlinkage long sys_sigreturn (void );
@@ -48,16 +47,5 @@ struct vm86_struct;asmlinkage long sys_vm86old (struct vm86_struct __user *);asmlinkage long sys_vm86 (unsigned long ,unsigned long ); -#else /* CONFIG_X86_32 */ - -/* X86_64 only */ -/* kernel/process_64.c */ -asmlinkage long sys_arch_prctl (int ,unsigned long ); - -/* kernel/sys_x86_64.c */ -asmlinkage long sys_mmap (unsigned long ,unsigned long ,unsigned long , -unsigned long ,unsigned long ,unsigned long ); -#endif /* CONFIG_X86_32 */ -#endif /* CONFIG_SYSCALL_PTREGS */ #endif /* _ASM_X86_SYSCALLS_H */
Signature · 1 line
2.16.3
tip-bot for Dominik Brodowski
merge bot[tip:x86/asm] syscalls/x86: Unconditionally enable 'struct pt_regs' based syscalls on x86_64
syscalls/x86: Unconditionally enable 'struct pt_regs' based syscalls on x86_64
Commit-ID: f8781c4a226319fe60e652118b90cf094ccfe747 Gitweb: https://git.kernel.org/tip/f8781c4a226319fe60e652118b90cf094ccfe747 Author: Dominik Brodowski <[email protected]> AuthorDate: Thu, 5 Apr 2018 11:53:05 +0200 Committer: Ingo Molnar <[email protected]> CommitDate: Thu, 5 Apr 2018 16:59:38 +0200
syscalls/x86: Unconditionally enable 'struct pt_regs' based syscalls on x86_64
Removing CONFIG_SYSCALL_PTREGS from arch/x86/Kconfig and simply selecting ARCH_HAS_SYSCALL_WRAPPER unconditionally on x86-64 allows us to simplify several codepaths.
--- arch/x86/Kconfig | 6 +----- arch/x86/entry/common.c | 10 ++-------- arch/x86/entry/syscall_32.c | 6 +++--- arch/x86/entry/syscall_64.c | 5 ----- arch/x86/entry/vsyscall/vsyscall_64.c | 18 ------------------ arch/x86/include/asm/syscall.h | 4 ++-- arch/x86/include/asm/syscalls.h | 20 ++++---------------- 7 files changed, 12 insertions(+), 57 deletions(-)
arch/x86/Kconfig +1 -5
@@ -29,6 +29,7 @@ config X86_64 select HAVE_ARCH_SOFT_DIRTY select MODULES_USE_ELF_RELA select X86_DEV_DMA_OPS + select ARCH_HAS_SYSCALL_WRAPPER # # Arch settings
@@ -2954,8 +2955,3 @@ source "crypto/Kconfig" source "arch/x86/kvm/Kconfig" source "lib/Kconfig" - -config SYSCALL_PTREGS - def_bool y - depends on X86_64 - select ARCH_HAS_SYSCALL_WRAPPER
arch/x86/entry/common.c +2 -8
@@ -284,13 +284,7 @@ __visible void do_syscall_64(unsigned long nr, struct pt_regs *regs) nr &= __SYSCALL_MASK;if (likely (nr < NR_syscalls)) { nr =array_index_nospec (nr, NR_syscalls); -#ifdef CONFIG_SYSCALL_PTREGS regs->ax = sys_call_table[nr](regs); -#else - regs->ax = sys_call_table[nr]( - regs->di, regs->si, regs->dx, - regs->r10, regs->r8, regs->r9); -#endif }syscall_return_slowpath (regs);
@@ -325,7 +319,7 @@ static __always_inline void do_syscall_32_irqs_on(struct pt_regs *regs)if (likely (nr < IA32_NR_syscalls)) { nr =array_index_nospec (nr, IA32_NR_syscalls); -#ifdef CONFIG_SYSCALL_PTREGS +#ifdef CONFIG_IA32_EMULATION regs->ax = ia32_sys_call_table[nr](regs);#else /*
@@ -338,7 +332,7 @@ static __always_inline void do_syscall_32_irqs_on(struct pt_regs *regs) (unsigned int )regs->bx, (unsigned int )regs->cx, (unsigned int )regs->dx, (unsigned int )regs->si, (unsigned int)regs->di, (unsigned int)regs->bp); -#endif /* CONFIG_SYSCALL_PTREGS */ +#endif /* CONFIG_IA32_EMULATION */ }syscall_return_slowpath (regs);
arch/x86/entry/syscall_32.c +3 -3
@@ -7,17 +7,17 @@#include <asm/asm-offsets.h> #include <asm/syscall.h> -#ifdef CONFIG_SYSCALL_PTREGS +#ifdef CONFIG_IA32_EMULATION /* On X86_64, we use struct pt_regs * to pass parameters to syscalls */ #define __SYSCALL_I386 (nr, sym, qual) extern asmlinkage long sym(const struct pt_regs *);/* 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 *); -#else /* CONFIG_SYSCALL_PTREGS */ +#else /* CONFIG_IA32_EMULATION */ #define __SYSCALL_I386 (nr, sym, qual) extern asmlinkage long sym(unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, unsigned long);extern asmlinkage long sys_ni_syscall (unsigned long ,unsigned long ,unsigned long ,unsigned long ,unsigned long ,unsigned long ); -#endif /* CONFIG_SYSCALL_PTREGS */ +#endif /* CONFIG_IA32_EMULATION */ #include <asm/syscalls_32.h> #undef __SYSCALL_I386
arch/x86/entry/syscall_64.c +0 -5
@@ -7,14 +7,9 @@#include <asm/asm-offsets.h> #include <asm/syscall.h> -#ifdef CONFIG_SYSCALL_PTREGS /* 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 *); -#else /* CONFIG_SYSCALL_PTREGS */ -extern asmlinkage long sys_ni_syscall (unsigned long ,unsigned long ,unsigned long ,unsigned long ,unsigned long ,unsigned long ); -#define __SYSCALL_64 (nr, sym, qual) extern asmlinkage long sym(unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, unsigned long); -#endif /* CONFIG_SYSCALL_PTREGS */ #include <asm/syscalls_64.h> #undef __SYSCALL_64
arch/x86/entry/vsyscall/vsyscall_64.c +0 -18
@@ -127,9 +127,7 @@ bool emulate_vsyscall(struct pt_regs *regs, unsigned long address)int vsyscall_nr, syscall_nr, tmp;int prev_sig_on_uaccess_err;long ret; -#ifdef CONFIG_SYSCALL_PTREGS unsigned long orig_dx; -#endif /* * No point in checking CS -- the only way to get here is a user mode
@@ -230,38 +228,22 @@ bool emulate_vsyscall(struct pt_regs *regs, unsigned long address) ret = -EFAULT ;switch (vsyscall_nr) {case 0 : -#ifdef CONFIG_SYSCALL_PTREGS /* this decodes regs->di and regs->si on its own */ ret =sys_gettimeofday (regs); -#else - ret =sys_gettimeofday ( - (struct timeval __user *)regs->di, - (struct timezone __user *)regs->si); -#endif /* CONFIG_SYSCALL_PTREGS */ break ;case 1 : -#ifdef CONFIG_SYSCALL_PTREGS /* this decodes regs->di on its own */ ret =sys_time (regs); -#else - ret =sys_time ((time_t __user *)regs->di); -#endif /* CONFIG_SYSCALL_PTREGS */ break ;case 2 : -#ifdef CONFIG_SYSCALL_PTREGS /* while we could clobber regs->dx, we didn't in the past... */ orig_dx = regs->dx; regs->dx =0 ;/* this decodes regs->di, regs->si and regs->dx on its own */ ret =sys_getcpu (regs); regs->dx = orig_dx; -#else - ret =sys_getcpu ((unsigned __user *)regs->di, - (unsigned __user *)regs->si, -NULL ); -#endif /* CONFIG_SYSCALL_PTREGS */ break ; }
arch/x86/include/asm/syscall.h +2 -2
@@ -20,13 +20,13 @@#include <asm/thread_info.h> /* for TS_COMPAT */ #include <asm/unistd.h> -#ifdef CONFIG_SYSCALL_PTREGS +#ifdef CONFIG_X86_64 typedef asmlinkage long (*sys_call_ptr_t )(const struct pt_regs *);#else typedef asmlinkage long (*sys_call_ptr_t )(unsigned long ,unsigned long ,unsigned long ,unsigned long ,unsigned long ,unsigned long ); -#endif /* CONFIG_SYSCALL_PTREGS */ +#endif /* CONFIG_X86_64 */ extern const sys_call_ptr_t sys_call_table[];#if defined(CONFIG_X86_32 )
arch/x86/include/asm/syscalls.h +4 -16
@@ -19,10 +19,10 @@/* kernel/ioport.c */ long ksys_ioperm (unsigned long from,unsigned long num,int turn_on); -#ifndef CONFIG_SYSCALL_PTREGS -/* -* If CONFIG_SYSCALL_PTREGS is enabled, a different syscall calling convention -* is used. Do not include these -- invalid -- prototypes then +#ifdef CONFIG_X86_32 +/* +* These definitions are only valid on pure 32-bit systems; x86-64 uses a +* different syscall calling convention */ asmlinkage long sys_ioperm (unsigned long ,unsigned long ,int );asmlinkage long sys_iopl (unsigned int );
@@ -38,7 +38,6 @@ asmlinkage long sys_set_thread_area(struct user_desc __user *);asmlinkage long sys_get_thread_area (struct user_desc __user *);/* X86_32 only */ -#ifdef CONFIG_X86_32 /* kernel/signal.c */ asmlinkage long sys_sigreturn (void );
@@ -48,16 +47,5 @@ struct vm86_struct;asmlinkage long sys_vm86old (struct vm86_struct __user *);asmlinkage long sys_vm86 (unsigned long ,unsigned long ); -#else /* CONFIG_X86_32 */ - -/* X86_64 only */ -/* kernel/process_64.c */ -asmlinkage long sys_arch_prctl (int ,unsigned long ); - -/* kernel/sys_x86_64.c */ -asmlinkage long sys_mmap (unsigned long ,unsigned long ,unsigned long , -unsigned long ,unsigned long ,unsigned long ); -#endif /* CONFIG_X86_32 */ -#endif /* CONFIG_SYSCALL_PTREGS */ #endif /* _ASM_X86_SYSCALLS_H */
PATCH 7/8 x86/entry/64: extend register clearing on syscall entry to lower registers
In reply to Dominik BrodowskiTo reduce the chance that random user space content leaks down the call chain in registers, also clear lower registers on syscall entry:
For 64-bit syscalls, extend the register clearing in PUSH_AND_CLEAR_REGS to %dx and %cx. This should not hurt at all, also on the other callers of that macro. We do not need to clear %rdi and %rsi for syscall entry, as those registers are used to pass the parameters to do_syscall_64().
For the 32-bit compat syscalls, do_int80_syscall_32() and do_fast_syscall_32() each only take one parameter. Therefore, extend the register clearing to %dx, %cx, and %si in entry_SYSCALL_compat and entry_INT80_compat.
--- arch/x86/entry/calling.h | 2 ++ arch/x86/entry/entry_64_compat.S | 6 ++++++ 2 files changed, 8 insertions(+)
arch/x86/entry/calling.h +2 -0
@@ -114,7 +114,9 @@ For 32-bit we have the following conventions - kernel is built with pushq %rsi/* pt_regs->si */ .endif pushq \rdx /* pt_regs->dx */ + xorl %edx, %edx /* nospec dx */ pushq %rcx /* pt_regs->cx */ + xorl %ecx, %ecx /* nospec cx */ pushq \rax /* pt_regs->ax */ pushq %r8 /* pt_regs->r8 */ xorl %r8d, %r8d /* nospec r8 */
arch/x86/entry/entry_64_compat.S +6 -0
@@ -220,8 +220,11 @@ GLOBAL(entry_SYSCALL_compat_after_hwframe) pushq %rax /* pt_regs->orig_ax */ pushq %rdi /* pt_regs->di */ pushq %rsi /* pt_regs->si */ + xorl %esi, %esi /* nospec si */ pushq %rdx /* pt_regs->dx */ + xorl %edx, %edx /* nospec dx */ pushq %rbp /* pt_regs->cx (stashed in bp) */ + xorl %ecx, %ecx /* nospec cx */ pushq $-ENOSYS /* pt_regs->ax */ pushq $0 /* pt_regs->r8 = 0 */ xorl %r8d, %r8d /* nospec r8 */
@@ -365,8 +368,11 @@ ENTRY(entry_INT80_compat) pushq (%rdi) /* pt_regs->di */ pushq %rsi /* pt_regs->si */ + xorl %esi, %esi /* nospec si */ pushq %rdx /* pt_regs->dx */ + xorl %edx, %edx /* nospec dx */ pushq %rcx /* pt_regs->cx */ + xorl %ecx, %ecx /* nospec cx */ pushq $-ENOSYS /* pt_regs->ax */ pushq $0 /* pt_regs->r8 = 0 */ xorl %r8d, %r8d /* nospec r8 */
Signature · 1 line
2.16.3
tip-bot for Dominik Brodowski
merge bot[tip:x86/asm] syscalls/x86: Extend register clearing on syscall entry to lower registers
syscalls/x86: Extend register clearing on syscall entry to lower registers
Commit-ID: 6dc936f175cc6d12a8eb14d29b87e9238e460383 Gitweb: https://git.kernel.org/tip/6dc936f175cc6d12a8eb14d29b87e9238e460383 Author: Dominik Brodowski <[email protected]> AuthorDate: Thu, 5 Apr 2018 11:53:06 +0200 Committer: Ingo Molnar <[email protected]> CommitDate: Thu, 5 Apr 2018 16:59:39 +0200
syscalls/x86: Extend register clearing on syscall entry to lower registers
To reduce the chance that random user space content leaks down the call chain in registers, also clear lower registers on syscall entry:
For 64-bit syscalls, extend the register clearing in PUSH_AND_CLEAR_REGS to %dx and %cx. This should not hurt at all, also on the other callers of that macro. We do not need to clear %rdi and %rsi for syscall entry, as those registers are used to pass the parameters to do_syscall_64().
For the 32-bit compat syscalls, do_int80_syscall_32() and do_fast_syscall_32() each only take one parameter. Therefore, extend the register clearing to %dx, %cx, and %si in entry_SYSCALL_compat and entry_INT80_compat.
--- arch/x86/entry/calling.h | 2 ++ arch/x86/entry/entry_64_compat.S | 6 ++++++ 2 files changed, 8 insertions(+)
arch/x86/entry/calling.h +2 -0
@@ -114,7 +114,9 @@ For 32-bit we have the following conventions - kernel is built with pushq %rsi/* pt_regs->si */ .endif pushq \rdx /* pt_regs->dx */ + xorl %edx, %edx /* nospec dx */ pushq %rcx /* pt_regs->cx */ + xorl %ecx, %ecx /* nospec cx */ pushq \rax /* pt_regs->ax */ pushq %r8 /* pt_regs->r8 */ xorl %r8d, %r8d /* nospec r8 */
arch/x86/entry/entry_64_compat.S +6 -0
@@ -220,8 +220,11 @@ GLOBAL(entry_SYSCALL_compat_after_hwframe) pushq %rax /* pt_regs->orig_ax */ pushq %rdi /* pt_regs->di */ pushq %rsi /* pt_regs->si */ + xorl %esi, %esi /* nospec si */ pushq %rdx /* pt_regs->dx */ + xorl %edx, %edx /* nospec dx */ pushq %rbp /* pt_regs->cx (stashed in bp) */ + xorl %ecx, %ecx /* nospec cx */ pushq $-ENOSYS /* pt_regs->ax */ pushq $0 /* pt_regs->r8 = 0 */ xorl %r8d, %r8d /* nospec r8 */
@@ -365,8 +368,11 @@ ENTRY(entry_INT80_compat) pushq (%rdi) /* pt_regs->di */ pushq %rsi /* pt_regs->si */ + xorl %esi, %esi /* nospec si */ pushq %rdx /* pt_regs->dx */ + xorl %edx, %edx /* nospec dx */ pushq %rcx /* pt_regs->cx */ + xorl %ecx, %ecx /* nospec cx */ pushq $-ENOSYS /* pt_regs->ax */ pushq $0 /* pt_regs->r8 = 0 */ xorl %r8d, %r8d /* nospec r8 */
PATCH 8/8 syscalls/x86: rename struct pt_regs-based sys_*() to __sys_x86_*()
In reply to Dominik BrodowskiWhile it may make sense to name different things differently, I am not so sure that the additional code is worth it here...
--- arch/x86/entry/syscalls/syscall_32.tbl | 49 +-- arch/x86/entry/syscalls/syscall_64.tbl | 638 +++++++++++++++++---------------- arch/x86/entry/vsyscall/vsyscall_64.c | 6 +- arch/x86/include/asm/syscall_wrapper.h | 48 ++- 4 files changed, 381 insertions(+), 360 deletions(-)
arch/x86/entry/syscalls/syscall_32.tbl +25 -24
@@ -7,13 +7,14 @@ # The __sys_ia32 and __compat_sys_ia32 stubs are created on-the-fly for # sys_*() system calls and compat_sys_*() compat system calls if # IA32_EMULATION is defined, and expect struct pt_regs *regs as their only -# parameter. +# parameter. The __sys_x86_ stubs below, which are common to x86-64, refer +# solely to 0-parameter syscalls. # # The abi is always "i386" for this file. # -0 i386 restart_syscall sys_restart_syscall +0 i386 restart_syscall sys_restart_syscall __sys_x86_restart_syscall 1 i386 exit sys_exit __sys_ia32_exit -2 i386 fork sys_fork +2 i386 fork sys_fork __sys_x86_fork 3 i386 read sys_read __sys_ia32_read 4 i386 write sys_write __sys_ia32_write 5 i386 open sys_open __compat_sys_ia32_open
@@ -31,23 +32,23 @@ 17 i386 break 18 i386 oldstat sys_stat __sys_ia32_stat 19 i386 lseek sys_lseek __compat_sys_ia32_lseek -20 i386 getpid sys_getpid +20 i386 getpid sys_getpid __sys_x86_getpid 21 i386 mount sys_mount __compat_sys_ia32_mount 22 i386 umount sys_oldumount __sys_ia32_oldumount 23 i386 setuid sys_setuid16 __sys_ia32_setuid16 -24 i386 getuid sys_getuid16 +24 i386 getuid sys_getuid16 __sys_x86_getuid16 25 i386 stime sys_stime __compat_sys_ia32_stime 26 i386 ptrace sys_ptrace __compat_sys_ia32_ptrace 27 i386 alarm sys_alarm __sys_ia32_alarm 28 i386 oldfstat sys_fstat __sys_ia32_fstat -29 i386 pause sys_pause +29 i386 pause sys_pause __sys_x86_pause 30 i386 utime sys_utime __compat_sys_ia32_utime 31 i386 stty 32 i386 gtty 33 i386 access sys_access __sys_ia32_access 34 i386 nice sys_nice __sys_ia32_nice 35 i386 ftime -36 i386 sync sys_sync +36 i386 sync sys_sync __sys_x86_sync 37 i386 kill sys_kill __sys_ia32_kill 38 i386 rename sys_rename __sys_ia32_rename 39 i386 mkdir sys_mkdir __sys_ia32_mkdir
@@ -58,10 +59,10 @@ 44 i386 prof 45 i386 brk sys_brk __sys_ia32_brk 46 i386 setgid sys_setgid16 __sys_ia32_setgid16 -47 i386 getgid sys_getgid16 +47 i386 getgid sys_getgid16 __sys_x86_getgid16 48 i386 signal sys_signal __sys_ia32_signal -49 i386 geteuid sys_geteuid16 -50 i386 getegid sys_getegid16 +49 i386 geteuid sys_geteuid16 __sys_x86_geteuid16 +50 i386 getegid sys_getegid16 __sys_x86_getegid16 51 i386 acct sys_acct __sys_ia32_acct 52 i386 umount2 sys_umount __sys_ia32_umount 53 i386 lock
@@ -75,11 +76,11 @@ 61 i386 chroot sys_chroot __sys_ia32_chroot 62 i386 ustat sys_ustat __compat_sys_ia32_ustat 63 i386 dup2 sys_dup2 __sys_ia32_dup2 -64 i386 getppid sys_getppid -65 i386 getpgrp sys_getpgrp -66 i386 setsid sys_setsid +64 i386 getppid sys_getppid __sys_x86_getppid +65 i386 getpgrp sys_getpgrp __sys_x86_getpgrp +66 i386 setsid sys_setsid __sys_x86_setsid 67 i386 sigaction sys_sigaction __compat_sys_ia32_sigaction -68 i386 sgetmask sys_sgetmask +68 i386 sgetmask sys_sgetmask __sys_x86_sgetmask 69 i386 ssetmask sys_ssetmask __sys_ia32_ssetmask 70 i386 setreuid sys_setreuid16 __sys_ia32_setreuid16 71 i386 setregid sys_setregid16 __sys_ia32_setregid16
@@ -122,7 +123,7 @@ 108 i386 fstat sys_newfstat __compat_sys_ia32_newfstat 109 i386 olduname sys_uname __sys_ia32_uname 110 i386 iopl sys_iopl __sys_ia32_iopl -111 i386 vhangup sys_vhangup +111 i386 vhangup sys_vhangup __sys_x86_vhangup 112 i386 idle 113 i386 vm86old sys_vm86old sys_ni_syscall 114 i386 wait4 sys_wait4 __compat_sys_ia32_wait4
@@ -164,12 +165,12 @@ 150 i386 mlock sys_mlock __sys_ia32_mlock 151 i386 munlock sys_munlock __sys_ia32_munlock 152 i386 mlockall sys_mlockall __sys_ia32_mlockall -153 i386 munlockall sys_munlockall +153 i386 munlockall sys_munlockall __sys_x86_munlockall 154 i386 sched_setparam sys_sched_setparam __sys_ia32_sched_setparam 155 i386 sched_getparam sys_sched_getparam __sys_ia32_sched_getparam 156 i386 sched_setscheduler sys_sched_setscheduler __sys_ia32_sched_setscheduler 157 i386 sched_getscheduler sys_sched_getscheduler __sys_ia32_sched_getscheduler -158 i386 sched_yield sys_sched_yield +158 i386 sched_yield sys_sched_yield __sys_x86_sched_yield 159 i386 sched_get_priority_max sys_sched_get_priority_max __sys_ia32_sched_get_priority_max 160 i386 sched_get_priority_min sys_sched_get_priority_min __sys_ia32_sched_get_priority_min 161 i386 sched_rr_get_interval sys_sched_rr_get_interval __compat_sys_ia32_sched_rr_get_interval
@@ -201,7 +202,7 @@ 187 i386 sendfile sys_sendfile __compat_sys_ia32_sendfile 188 i386 getpmsg 189 i386 putpmsg -190 i386 vfork sys_vfork +190 i386 vfork sys_vfork __sys_x86_vfork 191 i386 ugetrlimit sys_getrlimit __compat_sys_ia32_getrlimit 192 i386 mmap2 sys_mmap_pgoff __sys_ia32_mmap_pgoff 193 i386 truncate64 sys_truncate64 __compat_sys_ia32_x86_truncate64
@@ -210,10 +211,10 @@ 196 i386 lstat64 sys_lstat64 __compat_sys_ia32_x86_lstat64 197 i386 fstat64 sys_fstat64 __compat_sys_ia32_x86_fstat64 198 i386 lchown32 sys_lchown __sys_ia32_lchown -199 i386 getuid32 sys_getuid -200 i386 getgid32 sys_getgid -201 i386 geteuid32 sys_geteuid -202 i386 getegid32 sys_getegid +199 i386 getuid32 sys_getuid __sys_x86_getuid +200 i386 getgid32 sys_getgid __sys_x86_getgid +201 i386 geteuid32 sys_geteuid __sys_x86_geteuid +202 i386 getegid32 sys_getegid __sys_x86_getegid 203 i386 setreuid32 sys_setreuid __sys_ia32_setreuid 204 i386 setregid32 sys_setregid __sys_ia32_setregid 205 i386 getgroups32 sys_getgroups __sys_ia32_getgroups
@@ -235,7 +236,7 @@ 221 i386 fcntl64 sys_fcntl64 __compat_sys_ia32_fcntl64 # 222 is unused # 223 is unused -224 i386 gettid sys_gettid +224 i386 gettid sys_gettid __sys_x86_gettid 225 i386 readahead sys_readahead __compat_sys_ia32_x86_readahead 226 i386 setxattr sys_setxattr __sys_ia32_setxattr 227 i386 lsetxattr sys_lsetxattr __sys_ia32_lsetxattr
@@ -302,7 +303,7 @@ 288 i386 keyctl sys_keyctl __compat_sys_ia32_keyctl 289 i386 ioprio_set sys_ioprio_set __sys_ia32_ioprio_set 290 i386 ioprio_get sys_ioprio_get __sys_ia32_ioprio_get -291 i386 inotify_init sys_inotify_init +291 i386 inotify_init sys_inotify_init __sys_x86_inotify_init 292 i386 inotify_add_watch sys_inotify_add_watch __sys_ia32_inotify_add_watch 293 i386 inotify_rm_watch sys_inotify_rm_watch __sys_ia32_inotify_rm_watch 294 i386 migrate_pages sys_migrate_pages __sys_ia32_migrate_pages
arch/x86/entry/syscalls/syscall_64.tbl +320 -318
661 lines not on this page · raw message
arch/x86/entry/vsyscall/vsyscall_64.c +3 -3
@@ -229,12 +229,12 @@ bool emulate_vsyscall(struct pt_regs *regs, unsigned long address)switch (vsyscall_nr) {case 0 :/* this decodes regs->di and regs->si on its own */ - ret =sys_gettimeofday (regs); + ret =__sys_x86_gettimeofday (regs);break ;case 1 :/* this decodes regs->di on its own */ - ret =sys_time (regs); + ret =__sys_x86_time (regs);break ;case 2 :
@@ -242,7 +242,7 @@ bool emulate_vsyscall(struct pt_regs *regs, unsigned long address) orig_dx = regs->dx; regs->dx =0 ;/* this decodes regs->di, regs->si and regs->dx on its own */ - ret =sys_getcpu (regs); + ret =__sys_x86_getcpu (regs); regs->dx = orig_dx;break ; }
arch/x86/include/asm/syscall_wrapper.h +33 -15
87 lines not on this page · raw message
Signature · 1 line
2.16.3
kbuild test robot
build botRe: [PATCH 8/8] syscalls/x86: rename struct pt_regs-based sys_*() to __sys_x86_*()
I love your patch! Yet something to improve:
Hi Dominik,
I love your patch! Yet something to improve:
[auto build test ERROR on linus/master]
[also build test ERROR on next-20180405]
[cannot apply to tip/x86/core v4.16]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
url: https://github.com/0day-ci/linux/commits/Dominik-Brodowski/use-struct-pt_regs-based-syscall-calling-for-x86-64/20180406-003520
config: um-x86_64_defconfig (attached as .config)
compiler: gcc-7 (Debian 7.3.0-1) 7.3.0 reproduce:
# save the attached .config to linux build tree
make ARCH=um SUBARCH=x86_64All errors (new ones prefixed by >>):
>> arch/x86/um/sys_call_table_64.o:(.rodata+0x0): undefined reference to `__sys_x86_read' >> arch/x86/um/sys_call_table_64.o:(.rodata+0x8): undefined reference to `__sys_x86_write' >> arch/x86/um/sys_call_table_64.o:(.rodata+0x10): undefined reference to `__sys_x86_open' >> arch/x86/um/sys_call_table_64.o:(.rodata+0x18): undefined reference to `__sys_x86_close' >> arch/x86/um/sys_call_table_64.o:(.rodata+0x20): undefined reference to `__sys_x86_newstat' >> arch/x86/um/sys_call_table_64.o:(.rodata+0x28): undefined reference to `__sys_x86_newfstat' >> arch/x86/um/sys_call_table_64.o:(.rodata+0x30): undefined reference to `__sys_x86_newlstat' >> arch/x86/um/sys_call_table_64.o:(.rodata+0x38): undefined reference to `__sys_x86_poll' >> arch/x86/um/sys_call_table_64.o:(.rodata+0x40): undefined reference to `__sys_x86_lseek' >> arch/x86/um/sys_call_table_64.o:(.rodata+0x48): undefined reference to `__sys_x86_mmap' >> arch/x86/um/sys_call_table_64.o:(.rodata+0x50): undefined reference to `__sys_x86_mprotect' >> arch/x86/um/sys_call_table_64.o:(.rodata+0x58): undefined reference to `__sys_x86_munmap' >> arch/x86/um/sys_call_table_64.o:(.rodata+0x60): undefined reference to `__sys_x86_brk' >> arch/x86/um/sys_call_table_64.o:(.rodata+0x68): undefined reference to `__sys_x86_rt_sigaction' >> arch/x86/um/sys_call_table_64.o:(.rodata+0x70): undefined reference to `__sys_x86_rt_sigprocmask' >> arch/x86/um/sys_call_table_64.o:(.rodata+0x78): undefined reference to `__sys_x86_rt_sigreturn' >> arch/x86/um/sys_call_table_64.o:(.rodata+0x80): undefined reference to `__sys_x86_ioctl' >> arch/x86/um/sys_call_table_64.o:(.rodata+0x88): undefined reference to `__sys_x86_pread64' >> arch/x86/um/sys_call_table_64.o:(.rodata+0x90): undefined reference to `__sys_x86_pwrite64' >> arch/x86/um/sys_call_table_64.o:(.rodata+0x98): undefined reference to `__sys_x86_readv'
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
Quoted 28 lines · Dominik Brodowski
Dominik Brodowski (7):
syscalls: introduceCONFIG_ARCH_HAS_SYSCALL_WRAPPERsyscalls/x86: use structpt_regsbased syscall calling for 64-bit
syscalls
syscalls: prepareARCH_HAS_SYSCALL_WRAPPERfor compat syscalls syscalls/x86: use structpt_regsbased syscall calling for
IA32_EMULATIONand x32
syscalls/x86: unconditionally enable structpt_regsbased syscalls onx86_64x86/entry/64: extend register clearing on syscall entry to lower
registers
syscalls/x86: rename struct pt_regs-based sys_*() to __sys_x86_*()Linus Torvalds (1):
x86: don't pointlessly reload the system call numberarch/x86/Kconfig | 1 + arch/x86/entry/calling.h | 2 + arch/x86/entry/common.c | 20 +- arch/x86/entry/entry_64.S | 3 +- arch/x86/entry/entry_64_compat.S | 6 + arch/x86/entry/syscall_32.c | 15 +- arch/x86/entry/syscall_64.c | 6 +- arch/x86/entry/syscalls/syscall_32.tbl | 724 +++++++++++++++++---------------- arch/x86/entry/syscalls/syscall_64.tbl | 712 ++++++++++++++++---------------- arch/x86/entry/vsyscall/vsyscall_64.c | 18 +- arch/x86/include/asm/syscall.h | 4 + arch/x86/include/asm/syscall_wrapper.h | 197 +++++++++
Quoted 8 lines
arch/x86/include/asm/syscalls.h | 17 +- include/linux/compat.h | 22 + include/linux/syscalls.h | 25 +- init/Kconfig | 10 + kernel/sys_ni.c | 10 + kernel/time/posix-stubs.c | 10 + 18 files changed, 1054 insertions(+), 748 deletions(-) create mode 100644 arch/x86/include/asm/syscall_wrapper.h
Ok, this series looks mostly good to me, but AFAICS this breaks the UML build:
make[2]: *** No rule to make target 'archheaders'. Stop. arch/um/Makefile:119: recipe for target 'archheaders' failed make[1]: *** [archheaders] Error 2
make[1]: *** Waiting for unfinished jobs....
Thanks,
Ingo
Quoted 6 lines · Ingo Molnar
Ok, this series looks mostly good to me, but AFAICS this breaks the UML build:
make[2]: *** No rule to make target 'archheaders'. Stop.
arch/um/Makefile:119: recipe for target 'archheaders' failed make[1]: *** [archheaders] Error 2
make[1]: *** Waiting for unfinished jobs....
Ah, that's caused by patch 8/8 which I did and do not like all that much
anyway: UML re-uses syscall_64.tbl which now has x86-specific entries like __sys_x86_pread64, but expects the generic syscall stub sys_pread64 referenced there. Fixup patch below; could be folded with patch 8/8. Or patch 8/8 could simply be dropped from the series altogether...
Thanks,
Dominik
--------------------------------------------------------------------------
Quoted 1 line
From
f5049ea4e1e5e7751e72a22cbc1b3a9389959a04Mon Sep 17 00:00:00 2001
From: Dominik Brodowski <[email protected]>
Date: Thu, 5 Apr 2018 22:16:23 +0200
Subject: [PATCH] syscalls/x86: fix UML syscall table
To differentiate the different calling regime used on x86, the syscall functions received __sys_x86_ as prefix (instead of sys_). This breaks the build of UML on 64-bit x86, as it re-uses the same syscall table.
To fix this, replace the __sys_x86_ prefix with sys_ during the generation of <asm/syscalls_64.h>.
arch/x86/entry/syscalls/syscalltbl.sh +35 -5
@@ -20,17 +20,47 @@ syscall_macro() { echo "__SYSCALL_${abi}($nr, $real_entry, $qualifier)" } -emit() { +emit64() { abi="$1" nr="$2" entry="$3" compat="$4" - if [ "$abi" = "64" -a -n "$compat" ]; then + if [ "$abi" = "I386" ]; then + echo "emit64() called for a 32-bit syscall" >&2 + exit 1 + fi + + if [ -n "$compat" ]; then echo "a compat entry for a 64-bit syscall makes no sense" >&2 exit 1 fi + if [ -n "$entry" ]; then + # For CONFIG_UML, we need to strip the __sys_x86 prefix + if [ "${entry}" = "${entry#__compat_sys}" ]; then + umlentry="sys${entry#__sys_x86}" + fi + + echo "#ifdef CONFIG_X86" + syscall_macro "$abi" "$nr" "$entry" + echo "#else /* CONFIG_UML */" + syscall_macro "$abi" "$nr" "$umlentry" + echo "#endif" + fi +} + +emit32() { + abi="$1" + nr="$2" + entry="$3" + compat="$4" + + if [ "$abi" = "64" ]; then + echo "emit32() called for a 64-bit syscall" >&2 + exit 1 + fi + if [ -z "$compat" ]; then if [ -n "$entry" ]; then syscall_macro "$abi" "$nr" "$entry"
@@ -53,14 +83,14 @@ grep '^[0-9]' "$in" | sort -n | ( # COMMON is the same as 64, except that we don't expect X32 # programs to use it. Our expectation has nothing to do with # any generated code, so treat them the same. - emit 64 "$nr" "$entry" "$compat" + emit64 64 "$nr" "$entry" "$compat" elif [ "$abi" = "X32" ]; then # X32 is equivalent to 64 on an X32-compatible kernel. echo "#ifdef CONFIG_X86_X32_ABI" - emit 64 "$nr" "$entry" "$compat" + emit64 64 "$nr" "$entry" "$compat" echo "#endif" elif [ "$abi" = "I386" ]; then - emit "$abi" "$nr" "$entry" "$compat" + emit32 "$abi" "$nr" "$entry" "$compat" else echo "Unknown abi $abi" >&2 exit 1
Quoted 8 lines · Dominik Brodowski
Quoted 6 lines · Ingo Molnar
Ok, this series looks mostly good to me, but AFAICS this breaks the UML build:
make[2]: *** No rule to make target 'archheaders'. Stop.
arch/um/Makefile:119: recipe for target 'archheaders' failed make[1]: *** [archheaders] Error 2
make[1]: *** Waiting for unfinished jobs....
Quoted 5 lines
Ah, that's caused by patch 8/8 which I did and do not like all that much
anyway: UML re-uses syscall_64.tbl which now has x86-specific entries like__sys_x86_pread64, but expects the generic syscall stubsys_pread64referenced there. Fixup patch below; could be folded with patch 8/8. Or patch 8/8 could simply be dropped from the series altogether...
I still like the 'truth in advertising' aspect. For example if I see this in the syscall table:
10 common mprotect __sys_x86_mprotect
I can immediately find the _real_ syscall entry point:
ffffffff81180a10 <__sys_x86_mprotect>:
ffffffff81180a10: 48 8b 57 60 mov 0x60(%rdi),%rdx ffffffff81180a14: 48 8b 77 68 mov 0x68(%rdi),%rsi ffffffff81180a18: b9 ff ff ff ff mov $0xffffffff,%ecx ffffffff81180a1d: 48 8b 7f 70 mov 0x70(%rdi),%rdi ffffffff81180a21: e8 fa fc ff ff callq ffffffff81180720 <do_mprotect_pkey> ffffffff81180a26: 48 98 cltq ffffffff81180a28: c3 retq ffffffff81180a29: 0f 1f 80 00 00 00 00 nopl 0x0(%rax)
If, on the other hand, I see this entry:
10 common mprotect sys_mprotect
Then, as a first step, no symbol anywhere matches with this:
triton:~/tip> grep sys_mprotect System.map
triton:~/tip>
"sys_mprotect" does not exist in any easily discoverable sense. You have to *know* to replace the sys_ prefix with __sys_x86_ to find it.
Now arguably we could use a __sys_ prefix instead of the grep-barrier __sys_x86 prefix - but that too would be somewhat confusing I think.
I mean, the fact that we are passing in a ptregs pointer is a complexity of the x86 kernel that *exists*, why hide it and make it harder to discover what's happening, for something as important as system calls?
In terms of UML breakage, UML arguably is tightly coupled to its host architecture:
Quoted 1 line
Subject: [PATCH] syscalls/x86: fix UML syscall table
Even with your patch applied I still see build failures:
$ make ARCH=um defconfig
$ make ARCH=um linux
...
arch/um/os-Linux/signal.c: In function ‘hard_handler’:
arch/um/os-Linux/signal.c:163:22: error: dereferencing pointer to incomplete type
‘struct ucontext’
mcontext_t *mc = &uc->uc_mcontext;
^~
scripts/Makefile.build:324: recipe for target 'arch/um/os-Linux/signal.o' failed
make[1]: *** [arch/um/os-Linux/signal.o] Error 1Thanks,
Ingo
Quoted 60 lines · Ingo Molnar
Quoted 8 lines · Dominik Brodowski
Quoted 6 lines · Ingo Molnar
Ok, this series looks mostly good to me, but AFAICS this breaks the UML build:
make[2]: *** No rule to make target 'archheaders'. Stop.
arch/um/Makefile:119: recipe for target 'archheaders' failed make[1]: *** [archheaders] Error 2
make[1]: *** Waiting for unfinished jobs....Quoted 5 lines
Ah, that's caused by patch 8/8 which I did and do not like all that much
anyway: UML re-uses syscall_64.tbl which now has x86-specific entries like__sys_x86_pread64, but expects the generic syscall stubsys_pread64referenced there. Fixup patch below; could be folded with patch 8/8. Or patch 8/8 could simply be dropped from the series altogether...I still like the 'truth in advertising' aspect. For example if I see this in the syscall table:
10 common mprotect
__sys_x86_mprotectI can immediately find the _real_ syscall entry point:
ffffffff81180a10<__sys_x86_mprotect>:ffffffff81180a10: 48 8b 57 60 mov 0x60(%rdi),%rdx ffffffff81180a14: 48 8b 77 68 mov 0x68(%rdi),%rsi ffffffff81180a18: b9 ff ff ff ff mov $0xffffffff,%ecx ffffffff81180a1d: 48 8b 7f 70 mov 0x70(%rdi),%rdi ffffffff81180a21: e8 fa fc ff ff callq ffffffff81180720 <do_mprotect_pkey> ffffffff81180a26: 48 98 cltq ffffffff81180a28: c3 retq ffffffff81180a29: 0f 1f 80 00 00 00 00 nopl 0x0(%rax)If, on the other hand, I see this entry:
10 common mprotect
sys_mprotectThen, as a first step, no symbol anywhere matches with this:
triton:~/tip> grep
sys_mprotectSystem.map
triton:~/tip>"
sys_mprotect" does not exist in any easily discoverable sense. You have to *know* to replace thesys_prefix with__sys_x86_to find it.Now arguably we could use a
__sys_prefix instead of the grep-barrier__sys_x86prefix - but that too would be somewhat confusing I think.I mean, the fact that we are passing in a ptregs pointer is a complexity of the x86 kernel that *exists*, why hide it and make it harder to discover what's happening, for something as important as system calls?
In terms of UML breakage, UML arguably is tightly coupled to its host architecture:
Quoted 1 line
Subject: [PATCH] syscalls/x86: fix UML syscall table
Even with your patch applied I still see build failures:
Quoted 10 lines
$ make ARCH=um defconfig
$ make ARCH=um linux
...
arch/um/os-Linux/signal.c: In function ‘hard_handler’:
arch/um/os-Linux/signal.c:163:22: error: dereferencing pointer to incomplete type
‘struct ucontext’
mcontext_t *mc = &uc->uc_mcontext;
^~
scripts/Makefile.build:324: recipe for target 'arch/um/os-Linux/signal.o' failed
make[1]: *** [arch/um/os-Linux/signal.o] Error 1That build failure is already present in mainline as of 38c23685b273 (when building on Arch / gcc-7.3.1; building on Debian oldstable / gcc-4.9 works fine). And -- just checked -- this build failure also exists for plain v4.16.
Thanks,
Dominik
Quoted 40 lines · Ingo Molnar
Quoted 8 lines · Dominik Brodowski
Quoted 6 lines · Ingo Molnar
Ok, this series looks mostly good to me, but AFAICS this breaks the UML build:
make[2]: *** No rule to make target 'archheaders'. Stop.
arch/um/Makefile:119: recipe for target 'archheaders' failed make[1]: *** [archheaders] Error 2
make[1]: *** Waiting for unfinished jobs....Quoted 5 lines
Ah, that's caused by patch 8/8 which I did and do not like all that much
anyway: UML re-uses syscall_64.tbl which now has x86-specific entries like__sys_x86_pread64, but expects the generic syscall stubsys_pread64referenced there. Fixup patch below; could be folded with patch 8/8. Or patch 8/8 could simply be dropped from the series altogether...I still like the 'truth in advertising' aspect. For example if I see this in the syscall table:
10 common mprotect
__sys_x86_mprotectI can immediately find the _real_ syscall entry point:
ffffffff81180a10<__sys_x86_mprotect>:ffffffff81180a10: 48 8b 57 60 mov 0x60(%rdi),%rdx ffffffff81180a14: 48 8b 77 68 mov 0x68(%rdi),%rsi ffffffff81180a18: b9 ff ff ff ff mov $0xffffffff,%ecx ffffffff81180a1d: 48 8b 7f 70 mov 0x70(%rdi),%rdi ffffffff81180a21: e8 fa fc ff ff callq ffffffff81180720 <do_mprotect_pkey> ffffffff81180a26: 48 98 cltq ffffffff81180a28: c3 retq ffffffff81180a29: 0f 1f 80 00 00 00 00 nopl 0x0(%rax)If, on the other hand, I see this entry:
10 common mprotect
sys_mprotectThen, as a first step, no symbol anywhere matches with this:
Quoted 8 lines
triton:~/tip> grep
sys_mprotectSystem.map
triton:~/tip>"
sys_mprotect" does not exist in any easily discoverable sense. You have to *know* to replace thesys_prefix with__sys_x86_to find it.Now arguably we could use a
__sys_prefix instead of the grep-barrier__sys_x86prefix - but that too would be somewhat confusing I think.
Well, if looking at the ARCH="um" kernel, you won't find the __sys_x86_mprotect there in its System.map -- so we either have to disentangle um and plain x86, or live with some cause for confusion.
__sys_mprotect as prefix won't work by the way, as the double-underscore __sys_ variant is already used in net/* for internal syscall helpers.
Thanks,
Dominik
Quoted 47 lines · Dominik Brodowski
Quoted 46 lines · Ingo Molnar
Quoted 8 lines · Dominik Brodowski
Quoted 6 lines · Ingo Molnar
Ok, this series looks mostly good to me, but AFAICS this breaks the UML build:
make[2]: *** No rule to make target 'archheaders'. Stop.
arch/um/Makefile:119: recipe for target 'archheaders' failed make[1]: *** [archheaders] Error 2
make[1]: *** Waiting for unfinished jobs....Quoted 5 lines
Ah, that's caused by patch 8/8 which I did and do not like all that much
anyway: UML re-uses syscall_64.tbl which now has x86-specific entries like__sys_x86_pread64, but expects the generic syscall stubsys_pread64referenced there. Fixup patch below; could be folded with patch 8/8. Or patch 8/8 could simply be dropped from the series altogether...I still like the 'truth in advertising' aspect. For example if I see this in the syscall table:
10 common mprotect
__sys_x86_mprotectI can immediately find the _real_ syscall entry point:
ffffffff81180a10<__sys_x86_mprotect>:ffffffff81180a10: 48 8b 57 60 mov 0x60(%rdi),%rdx ffffffff81180a14: 48 8b 77 68 mov 0x68(%rdi),%rsi ffffffff81180a18: b9 ff ff ff ff mov $0xffffffff,%ecx ffffffff81180a1d: 48 8b 7f 70 mov 0x70(%rdi),%rdi ffffffff81180a21: e8 fa fc ff ff callq ffffffff81180720 <do_mprotect_pkey> ffffffff81180a26: 48 98 cltq ffffffff81180a28: c3 retq ffffffff81180a29: 0f 1f 80 00 00 00 00 nopl 0x0(%rax)If, on the other hand, I see this entry:
10 common mprotect
sys_mprotectThen, as a first step, no symbol anywhere matches with this:
triton:~/tip> grep
sys_mprotectSystem.map
triton:~/tip>"
sys_mprotect" does not exist in any easily discoverable sense. You have to *know* to replace thesys_prefix with__sys_x86_to find it.
Quoted 6 lines
Quoted 2 lines
Now arguably we could use a
__sys_prefix instead of the grep-barrier__sys_x86prefix - but that too would be somewhat confusing I think.Well, if looking at the ARCH="um" kernel, you won't find the
__sys_x86_mprotectthere in its System.map -- so we either have to disentangle um and plain x86, or live with some cause for confusion.
I'm primarily concerned about everything making sense on x86 - UML is an entirely separate architecture with heavy tradeoffs and kludges.
Quoted 2 lines
__sys_mprotectas prefix won't work by the way, as the double-underscore__sys_variant is already used innet/*for internal syscall helpers.
Ok - then triple underscore - but overall I think it's more confusing.
Btw., what was the problem with calling the x86 ptregs wrapper sys_mprotect?
The only reason I suggested the __sys_x86_ prefix was because you originally suggested that there's symbol name overlap, but I don't think that's the case within the same kernel build, as the regular non-ptregs prototype:
asmlinkage long sys_mprotect(unsigned long start, size_t len, unsigned long prot);
... will only exist on !CONFIG_ARCH_HAS_SYSCALL_WRAPPER kernels.
So maybe that's the simplest and least confusing solution.
Thanks,
Ingo
Quoted 53 lines · Ingo Molnar
Quoted 50 lines · Dominik Brodowski
Quoted 48 lines · Ingo Molnar
Quoted 8 lines · Dominik Brodowski
Quoted 6 lines · Ingo Molnar
Ok, this series looks mostly good to me, but AFAICS this breaks the UML build:
make[2]: *** No rule to make target 'archheaders'. Stop.
arch/um/Makefile:119: recipe for target 'archheaders' failed make[1]: *** [archheaders] Error 2
make[1]: *** Waiting for unfinished jobs....Quoted 5 lines
Ah, that's caused by patch 8/8 which I did and do not like all that much
anyway: UML re-uses syscall_64.tbl which now has x86-specific entries like__sys_x86_pread64, but expects the generic syscall stubsys_pread64referenced there. Fixup patch below; could be folded with patch 8/8. Or patch 8/8 could simply be dropped from the series altogether...I still like the 'truth in advertising' aspect. For example if I see this in the syscall table:
10 common mprotect
__sys_x86_mprotectI can immediately find the _real_ syscall entry point:
ffffffff81180a10<__sys_x86_mprotect>:ffffffff81180a10: 48 8b 57 60 mov 0x60(%rdi),%rdx ffffffff81180a14: 48 8b 77 68 mov 0x68(%rdi),%rsi ffffffff81180a18: b9 ff ff ff ff mov $0xffffffff,%ecx ffffffff81180a1d: 48 8b 7f 70 mov 0x70(%rdi),%rdi ffffffff81180a21: e8 fa fc ff ff callq ffffffff81180720 <do_mprotect_pkey> ffffffff81180a26: 48 98 cltq ffffffff81180a28: c3 retq ffffffff81180a29: 0f 1f 80 00 00 00 00 nopl 0x0(%rax)If, on the other hand, I see this entry:
10 common mprotect
sys_mprotectThen, as a first step, no symbol anywhere matches with this:
triton:~/tip> grep
sys_mprotectSystem.map
triton:~/tip>"
sys_mprotect" does not exist in any easily discoverable sense. You have to *know* to replace thesys_prefix with__sys_x86_to find it.Now arguably we could use a
__sys_prefix instead of the grep-barrier__sys_x86prefix - but that too would be somewhat confusing I think.
Quoted 6 lines
Quoted 3 lines
Well, if looking at the ARCH="um" kernel, you won't find the
__sys_x86_mprotectthere in its System.map -- so we either have to disentangle um and plain x86, or live with some cause for confusion.I'm primarily concerned about everything making sense on x86 - UML is an entirely separate architecture with heavy tradeoffs and kludges.
Agreed.
Quoted 10 lines
Quoted 2 lines
__sys_mprotectas prefix won't work by the way, as the double-underscore__sys_variant is already used innet/*for internal syscall helpers.Ok - then triple underscore - but overall I think it's more confusing.
Btw., what was the problem with calling the x86 ptregs wrapper
sys_mprotect?The only reason I suggested the
__sys_x86_prefix was because you originally suggested that there's symbol name overlap, but I don't think that's the case within the same kernel build, as the regular non-ptregs prototype:
Indeed, there's no symbol name overlap within the same kernel build, but technically different stubs named the same. If that's fine, just drop patch 8/8 (including the UML fixup) and things should be fine, with the stub and the entry in the syscall table both named sys_mprotect.
For IA32_EMULATION, we have __sys_ia32_mprotect as stub for the same syscall, including this name as entry in syscall_32.tbl.
More problematic is the naming for the compat stubs for IA32_EMAULATION and X32, where we have
__compat_sys_ia32_waitid __compat_sys_x32_waitid
for example. We *could* rename one of those to compat_sys_waitid() and levae the other as-is, but actually I prefer it now how it is.
Thanks,
Dominik
Quoted 7 lines · Dominik Brodowski
Quoted 7 lines
Quoted 2 lines
__sys_mprotectas prefix won't work by the way, as the double-underscore__sys_variant is already used innet/*for internal syscall helpers.Ok - then triple underscore - but overall I think it's more confusing.
Btw., what was the problem with calling the x86 ptregs wrapper
sys_mprotect?
Quoted 8 lines
Quoted 3 lines
The only reason I suggested the
__sys_x86_prefix was because you originally suggested that there's symbol name overlap, but I don't think that's the case within the same kernel build, as the regular non-ptregs prototype:Indeed, there's no symbol name overlap within the same kernel build, but technically different stubs named the same. If that's fine, just drop patch 8/8 (including the UML fixup) and things should be fine, with the stub and the entry in the syscall table both named
sys_mprotect.
Ok, I've dropped patch #8.
Quoted 11 lines
For
IA32_EMULATION, we have__sys_ia32_mprotectas stub for the same syscall, including this name as entry in syscall_32.tbl.More problematic is the naming for the compat stubs for
IA32_EMAULATIONand X32, where we have__compat_sys_ia32_waitid __compat_sys_x32_waitidfor example. We *could* rename one of those to
compat_sys_waitid()and levae the other as-is, but actually I prefer it now how it is.
yeah, this is more symmetric I think.
So right now we have these symbols:
triton:~/tip> grep waitid System.map
ffffffff8105f1e0 t kernel_waitid # common C function (64-bit kargs) ffffffff8105f2b0 t SYSC_waitid # 64-bit uaddr args C function 352 bytes ffffffff8105f410 T sys_waitid # 64-bit-ptregs -> C stub, 32 bytes ffffffff8105f430 T __sys_ia32_waitid # 32-bit-ptregs -> C stub, 32 bytes ffffffff8105f450 t C_SYSC_waitid # 32-bit uaddr args C function, 400 bytes ffffffff8105f5e0 T __compat_sys_ia32_waitid # 32-bit-ptregs -> C stub, 32 bytes ffffffff8105f600 T __compat_sys_x32_waitid # 64-bit-ptregs -> C stub, 32 bytes
BTW., what is the role of generating __sys_ia32_waitid()? It seems unused when a syscall has a compat variant otherwise - like here.
Naming wise the odd thumb out is sys_waitid :-/
I'd argue that we should at minimum name it __sys_waitid:
ffffffff8105f1e0 t kernel_waitid # common C function (64-bit kargs) ffffffff8105f2b0 t SYSC_waitid # 64-bit uaddr args C function ffffffff8105f410 T __sys_waitid # 64-bit-ptregs -> C stub ffffffff8105f430 T __sys_ia32_waitid # 32-bit-ptregs -> C stub ffffffff8105f450 t C_SYSC_waitid # 32-bit uaddr args C function ffffffff8105f5e0 T __compat_sys_ia32_waitid # 32-bit-ptregs -> C stub ffffffff8105f600 T __compat_sys_x32_waitid # 64-bit-ptregs -> C stub
because that makes it all organized based on the same principle:
{__compat|_}_sys{_ia32|_x32|}_waittidBut arguably there are a whole lot more naming weirdnesses we could fix:
- I find it somewhat confusing that that 'C' in C_SYSC stands not for a C callign convention, but for 'COMPAT' - i.e. COMPAT_SYSC would be better.
- Another detail is that why is it called 'SYSC', if the other functions use the 'sys' prefix? Wouldn't 'SYS' be more consistent?
- If we introduced a prefix for the regular 64-bit system call format as well, we could have: x64, x32 and ia32.
- And finally, I think the argument format modifiers should be consistently prefixes - right now they are a mixture of pre- and post-fixes.
I.e. I'd generate the names like this:
__{x64,x32,ia32}[_compat]_sys_waittid()The fully consistent nomenclature would be someting like this:
ffffffff8105f1e0 t kernel_waitid # common C function (64-bit kargs) ffffffff8105f2b0 t SYS_waitid # 64-bit uaddr args C function ffffffff8105f410 T __x64_sys_waitid # 64-bit-ptregs -> C stub ffffffff8105f430 T __ia32_sys_waitid # 32-bit-ptregs -> C stub ffffffff8105f450 t COMPAT_SYS_waitid # 32-bit uaddr args C function ffffffff8105f5e0 T __ia32_compat_sys_waitid # 32-bit-ptregs -> C stub ffffffff8105f600 T __x32_compat_sys_waitid # 64-bit-ptregs -> C stub
Looks a lot tidier and a lot more logical, doesn't it?
Makes grepping easier as well, because (case-insensitive) patterns like 'sys_waittid' would identify all the variants.
Personally I'd also do a s/ia32/i32 rename:
ffffffff8105f1e0 t kernel_waitid # common C function (64-bit kargs) ffffffff8105f2b0 t SYS_waitid # 64-bit uaddr args C function ffffffff8105f410 T __x64_sys_waitid # 64-bit-ptregs -> C stub ffffffff8105f430 T __i32_sys_waitid # 32-bit-ptregs -> C stub ffffffff8105f450 t COMPAT_SYS_waitid # 32-bit uaddr args C function ffffffff8105f5e0 T __i32_compat_sys_waitid # 32-bit-ptregs -> C stub ffffffff8105f600 T __x32_compat_sys_waitid # 64-bit-ptregs -> C stub
... but maybe that's too much ;-)
Thanks,
Ingo
Quoted 14 lines · Ingo Molnar
Quoted 11 lines · Dominik Brodowski
Quoted 10 lines
Quoted 2 lines
__sys_mprotectas prefix won't work by the way, as the double-underscore__sys_variant is already used innet/*for internal syscall helpers.Ok - then triple underscore - but overall I think it's more confusing.
Btw., what was the problem with calling the x86 ptregs wrapper
sys_mprotect?The only reason I suggested the
__sys_x86_prefix was because you originally suggested that there's symbol name overlap, but I don't think that's the case within the same kernel build, as the regular non-ptregs prototype:
Quoted 6 lines
Quoted 4 lines
Indeed, there's no symbol name overlap within the same kernel build, but technically different stubs named the same. If that's fine, just drop patch 8/8 (including the UML fixup) and things should be fine, with the stub and the entry in the syscall table both named
sys_mprotect.Ok, I've dropped patch #8.
Thanks!
Quoted 26 lines
Quoted 11 lines
For
IA32_EMULATION, we have__sys_ia32_mprotectas stub for the same syscall, including this name as entry in syscall_32.tbl.More problematic is the naming for the compat stubs for
IA32_EMAULATIONand X32, where we have__compat_sys_ia32_waitid __compat_sys_x32_waitidfor example. We *could* rename one of those to
compat_sys_waitid()and levae the other as-is, but actually I prefer it now how it is.yeah, this is more symmetric I think.
So right now we have these symbols:
triton:~/tip> grep waitid System.map
ffffffff8105f1e0 t kernel_waitid # common C function (64-bit kargs) ffffffff8105f2b0 t SYSC_waitid # 64-bit uaddr args C function 352 bytes ffffffff8105f410 T sys_waitid # 64-bit-ptregs -> C stub, 32 bytes ffffffff8105f430 T __sys_ia32_waitid # 32-bit-ptregs -> C stub, 32 bytes ffffffff8105f450 t C_SYSC_waitid # 32-bit uaddr args C function, 400 bytes ffffffff8105f5e0 T __compat_sys_ia32_waitid # 32-bit-ptregs -> C stub, 32 bytes ffffffff8105f600 T __compat_sys_x32_waitid # 64-bit-ptregs -> C stub, 32 bytes
Quoted 2 lines
BTW., what is the role of generating
__sys_ia32_waitid()? It seems unused when a syscall has a compat variant otherwise - like here.
Indeed it is unused -- but when compiling
SYSCALL_DEFINE5(waitid, ...)
we don't know yet that somewhere else in the kernel there is
COMPAT_SYSCALL_DEFINE5(waitid, ...)
So if we want to compile the __sys_ia32_ stub only iff it is used, we'd need to have different macros for syscalls which have compat variants and for those which do not. Or do you have an idea how we could trick the compiler to do the right thing?
Quoted 3 lines
Naming wise the odd thumb out is
sys_waitid:-/I'd argue that we should at minimum name it
__sys_waitid:
Can't do, as that namespace is already taken.
Quoted 12 lines
ffffffff8105f1e0 t kernel_waitid # common C function (64-bit kargs) ffffffff8105f2b0 t SYSC_waitid # 64-bit uaddr args C function ffffffff8105f410 T __sys_waitid # 64-bit-ptregs -> C stub ffffffff8105f430 T __sys_ia32_waitid # 32-bit-ptregs -> C stub ffffffff8105f450 t C_SYSC_waitid # 32-bit uaddr args C function ffffffff8105f5e0 T __compat_sys_ia32_waitid # 32-bit-ptregs -> C stub ffffffff8105f600 T __compat_sys_x32_waitid # 64-bit-ptregs -> C stubbecause that makes it all organized based on the same principle:
{__compat|_}_sys{_ia32|_x32|}_waittid
Quoted 7 lines
But arguably there are a whole lot more naming weirdnesses we could fix:
- I find it somewhat confusing that that 'C' in
C_SYSCstands not for a C callign convention, but for 'COMPAT' - i.e.COMPAT_SYSCwould be better.- Another detail is that why is it called 'SYSC', if the other functions use the 'sys' prefix? Wouldn't 'SYS' be more consistent?
It sounds totally reasonable to re-name those, but we should do it not only for the x86 case, but in include/linux/syscalls.h as well.
Quoted 20 lines
- If we introduced a prefix for the regular 64-bit system call format as well, we could have: x64, x32 and ia32.
- And finally, I think the argument format modifiers should be consistently prefixes - right now they are a mixture of pre- and post-fixes.
I.e. I'd generate the names like this:
__{x64,x32,ia32}[_compat]_sys_waittid()The fully consistent nomenclature would be someting like this:
ffffffff8105f1e0 t kernel_waitid # common C function (64-bit kargs) ffffffff8105f2b0 t SYS_waitid # 64-bit uaddr args C function ffffffff8105f410 T __x64_sys_waitid # 64-bit-ptregs -> C stub ffffffff8105f430 T __ia32_sys_waitid # 32-bit-ptregs -> C stub ffffffff8105f450 t COMPAT_SYS_waitid # 32-bit uaddr args C function ffffffff8105f5e0 T __ia32_compat_sys_waitid # 32-bit-ptregs -> C stub ffffffff8105f600 T __x32_compat_sys_waitid # 64-bit-ptregs -> C stub
Quoted 1 line
Looks a lot tidier and a lot more logical, doesn't it?
Indeed. Want me to prepare a new patch 8/8 on top which does the renaming (for x86 and for the generic case), or will you do the re-naming while merging my patches yourself?
Quoted 1 line
Personally I'd also do a s/ia32/i32 rename:
Uh, no, please. It makes things align more beautifully, yes, but the 32-bit sub-architecture commonly is referred to as either i386 or ia32...
Thanks,
Dominik
Quoted 14 lines · Dominik Brodowski
Quoted 14 lines
I.e. I'd generate the names like this:
__{x64,x32,ia32}[_compat]_sys_waittid()The fully consistent nomenclature would be someting like this:
ffffffff8105f1e0 t kernel_waitid # common C function (64-bit kargs) ffffffff8105f2b0 t SYS_waitid # 64-bit uaddr args C function ffffffff8105f410 T __x64_sys_waitid # 64-bit-ptregs -> C stub ffffffff8105f430 T __ia32_sys_waitid # 32-bit-ptregs -> C stub ffffffff8105f450 t COMPAT_SYS_waitid # 32-bit uaddr args C function ffffffff8105f5e0 T __ia32_compat_sys_waitid # 32-bit-ptregs -> C stub ffffffff8105f600 T __x32_compat_sys_waitid # 64-bit-ptregs -> C stub
Quoted 5 lines
Quoted 1 line
Looks a lot tidier and a lot more logical, doesn't it?
Indeed. Want me to prepare a new patch 8/8 on top which does the renaming (for x86 and for the generic case), or will you do the re-naming while merging my patches yourself?
Please do an 8/8 patch that does the rename - I'll push out the first 7 patches so they get more testing.
Note, I have not checked the above name space for namespace collisions - but unless we are unlucky it should be fine.
BTW., is there any deep reason why some of these names are capitalized?
I.e. could we use:
ffffffff8105f1e0 t kernel_waitid # common C function (64-bit kargs) ffffffff8105f2b0 t sys_waitid # 64-bit uaddr args C function ffffffff8105f410 T __x64_sys_waitid # 64-bit-ptregs -> C stub ffffffff8105f430 T __ia32_sys_waitid # 32-bit-ptregs -> C stub ffffffff8105f450 t compat_sys_waitid # 32-bit uaddr args C function ffffffff8105f5e0 T __ia32_compat_sys_waitid # 32-bit-ptregs -> C stub ffffffff8105f600 T __x32_compat_sys_waitid # 64-bit-ptregs -> C stub
?
Note how this reduces naming complexity and increases the self-consistency even more.
Thanks,
Ingo