2005-04-17 06:20:36 +08:00
|
|
|
/*
|
2015-06-05 19:02:28 +08:00
|
|
|
* Compatibility mode system call entry point for x86-64.
|
|
|
|
*
|
2005-04-17 06:20:36 +08:00
|
|
|
* Copyright 2000-2002 Andi Kleen, SuSE Labs.
|
2015-06-05 19:02:28 +08:00
|
|
|
*/
|
2015-06-04 00:29:26 +08:00
|
|
|
#include "calling.h"
|
2005-09-10 03:28:48 +08:00
|
|
|
#include <asm/asm-offsets.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <asm/current.h>
|
|
|
|
#include <asm/errno.h>
|
2015-06-05 19:02:28 +08:00
|
|
|
#include <asm/ia32_unistd.h>
|
|
|
|
#include <asm/thread_info.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <asm/segment.h>
|
2006-07-03 15:24:45 +08:00
|
|
|
#include <asm/irqflags.h>
|
2012-04-21 03:19:50 +08:00
|
|
|
#include <asm/asm.h>
|
2012-09-22 03:43:12 +08:00
|
|
|
#include <asm/smap.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/linkage.h>
|
2012-01-04 03:23:06 +08:00
|
|
|
#include <linux/err.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2011-03-08 02:10:39 +08:00
|
|
|
.section .entry.text, "ax"
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
2015-06-05 19:02:28 +08:00
|
|
|
* 32-bit SYSENTER instruction entry.
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
2015-02-27 06:40:32 +08:00
|
|
|
* SYSENTER loads ss, rsp, cs, and rip from previously programmed MSRs.
|
|
|
|
* IF and VM in rflags are cleared (IOW: interrupts are off).
|
|
|
|
* SYSENTER does not save anything on the stack,
|
|
|
|
* and does not save old rip (!!!) and rflags.
|
|
|
|
*
|
2005-04-17 06:20:36 +08:00
|
|
|
* Arguments:
|
2015-02-27 06:40:32 +08:00
|
|
|
* eax system call number
|
|
|
|
* ebx arg1
|
|
|
|
* ecx arg2
|
|
|
|
* edx arg3
|
|
|
|
* esi arg4
|
|
|
|
* edi arg5
|
|
|
|
* ebp user stack
|
|
|
|
* 0(%ebp) arg6
|
|
|
|
*
|
2005-04-17 06:20:36 +08:00
|
|
|
* This is purely a fast path. For anything complicated we use the int 0x80
|
2015-02-27 06:40:32 +08:00
|
|
|
* path below. We set up a complete hardware stack frame to share code
|
2005-04-17 06:20:36 +08:00
|
|
|
* with the int 0x80 path.
|
2015-02-27 06:40:32 +08:00
|
|
|
*/
|
2015-06-08 14:33:56 +08:00
|
|
|
ENTRY(entry_SYSENTER_compat)
|
2015-10-06 08:47:55 +08:00
|
|
|
/* Interrupts are off on entry. */
|
2015-03-27 18:36:20 +08:00
|
|
|
SWAPGS_UNSAFE_STACK
|
2015-04-24 23:31:35 +08:00
|
|
|
movq PER_CPU_VAR(cpu_current_top_of_stack), %rsp
|
2015-03-27 18:36:20 +08:00
|
|
|
|
2015-10-06 08:48:11 +08:00
|
|
|
/*
|
|
|
|
* User tracing code (ptrace or signal handlers) might assume that
|
|
|
|
* the saved RAX contains a 32-bit number when we're invoking a 32-bit
|
|
|
|
* syscall. Just in case the high bits are nonzero, zero-extend
|
|
|
|
* the syscall number. (This could almost certainly be deleted
|
|
|
|
* with no ill effects.)
|
|
|
|
*/
|
2015-03-27 18:36:21 +08:00
|
|
|
movl %eax, %eax
|
|
|
|
|
2015-04-01 01:00:04 +08:00
|
|
|
/* Construct struct pt_regs on stack */
|
x86/debug: Remove perpetually broken, unmaintainable dwarf annotations
So the dwarf2 annotations in low level assembly code have
become an increasing hindrance: unreadable, messy macros
mixed into some of the most security sensitive code paths
of the Linux kernel.
These debug info annotations don't even buy the upstream
kernel anything: dwarf driven stack unwinding has caused
problems in the past so it's out of tree, and the upstream
kernel only uses the much more robust framepointers based
stack unwinding method.
In addition to that there's a steady, slow bitrot going
on with these annotations, requiring frequent fixups.
There's no tooling and no functionality upstream that
keeps it correct.
So burn down the sick forest, allowing new, healthier growth:
27 files changed, 350 insertions(+), 1101 deletions(-)
Someone who has the willingness and time to do this
properly can attempt to reintroduce dwarf debuginfo in x86
assembly code plus dwarf unwinding from first principles,
with the following conditions:
- it should be maximally readable, and maximally low-key to
'ordinary' code reading and maintenance.
- find a build time method to insert dwarf annotations
automatically in the most common cases, for pop/push
instructions that manipulate the stack pointer. This could
be done for example via a preprocessing step that just
looks for common patterns - plus special annotations for
the few cases where we want to depart from the default.
We have hundreds of CFI annotations, so automating most of
that makes sense.
- it should come with build tooling checks that ensure that
CFI annotations are sensible. We've seen such efforts from
the framepointer side, and there's no reason it couldn't be
done on the dwarf side.
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: Frédéric Weisbecker <fweisbec@gmail.com
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Jan Beulich <JBeulich@suse.com>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2015-05-28 18:21:47 +08:00
|
|
|
pushq $__USER32_DS /* pt_regs->ss */
|
2015-10-06 08:48:11 +08:00
|
|
|
pushq %rcx /* pt_regs->sp */
|
2015-10-06 08:47:55 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Push flags. This is nasty. First, interrupts are currently
|
|
|
|
* off, but we need pt_regs->flags to have IF set. Second, even
|
|
|
|
* if TF was set when SYSENTER started, it's clear by now. We fix
|
|
|
|
* that later using TIF_SINGLESTEP.
|
|
|
|
*/
|
|
|
|
pushfq /* pt_regs->flags (except IF = 0) */
|
|
|
|
orl $X86_EFLAGS_IF, (%rsp) /* Fix saved flags */
|
2015-10-06 08:48:11 +08:00
|
|
|
ASM_CLAC /* Clear AC after saving FLAGS */
|
2015-10-06 08:47:55 +08:00
|
|
|
|
x86/debug: Remove perpetually broken, unmaintainable dwarf annotations
So the dwarf2 annotations in low level assembly code have
become an increasing hindrance: unreadable, messy macros
mixed into some of the most security sensitive code paths
of the Linux kernel.
These debug info annotations don't even buy the upstream
kernel anything: dwarf driven stack unwinding has caused
problems in the past so it's out of tree, and the upstream
kernel only uses the much more robust framepointers based
stack unwinding method.
In addition to that there's a steady, slow bitrot going
on with these annotations, requiring frequent fixups.
There's no tooling and no functionality upstream that
keeps it correct.
So burn down the sick forest, allowing new, healthier growth:
27 files changed, 350 insertions(+), 1101 deletions(-)
Someone who has the willingness and time to do this
properly can attempt to reintroduce dwarf debuginfo in x86
assembly code plus dwarf unwinding from first principles,
with the following conditions:
- it should be maximally readable, and maximally low-key to
'ordinary' code reading and maintenance.
- find a build time method to insert dwarf annotations
automatically in the most common cases, for pop/push
instructions that manipulate the stack pointer. This could
be done for example via a preprocessing step that just
looks for common patterns - plus special annotations for
the few cases where we want to depart from the default.
We have hundreds of CFI annotations, so automating most of
that makes sense.
- it should come with build tooling checks that ensure that
CFI annotations are sensible. We've seen such efforts from
the framepointer side, and there's no reason it couldn't be
done on the dwarf side.
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: Frédéric Weisbecker <fweisbec@gmail.com
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Jan Beulich <JBeulich@suse.com>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2015-05-28 18:21:47 +08:00
|
|
|
pushq $__USER32_CS /* pt_regs->cs */
|
2015-10-06 08:48:11 +08:00
|
|
|
xorq %r8,%r8
|
|
|
|
pushq %r8 /* pt_regs->ip = 0 (placeholder) */
|
x86/debug: Remove perpetually broken, unmaintainable dwarf annotations
So the dwarf2 annotations in low level assembly code have
become an increasing hindrance: unreadable, messy macros
mixed into some of the most security sensitive code paths
of the Linux kernel.
These debug info annotations don't even buy the upstream
kernel anything: dwarf driven stack unwinding has caused
problems in the past so it's out of tree, and the upstream
kernel only uses the much more robust framepointers based
stack unwinding method.
In addition to that there's a steady, slow bitrot going
on with these annotations, requiring frequent fixups.
There's no tooling and no functionality upstream that
keeps it correct.
So burn down the sick forest, allowing new, healthier growth:
27 files changed, 350 insertions(+), 1101 deletions(-)
Someone who has the willingness and time to do this
properly can attempt to reintroduce dwarf debuginfo in x86
assembly code plus dwarf unwinding from first principles,
with the following conditions:
- it should be maximally readable, and maximally low-key to
'ordinary' code reading and maintenance.
- find a build time method to insert dwarf annotations
automatically in the most common cases, for pop/push
instructions that manipulate the stack pointer. This could
be done for example via a preprocessing step that just
looks for common patterns - plus special annotations for
the few cases where we want to depart from the default.
We have hundreds of CFI annotations, so automating most of
that makes sense.
- it should come with build tooling checks that ensure that
CFI annotations are sensible. We've seen such efforts from
the framepointer side, and there's no reason it couldn't be
done on the dwarf side.
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: Frédéric Weisbecker <fweisbec@gmail.com
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Jan Beulich <JBeulich@suse.com>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2015-05-28 18:21:47 +08:00
|
|
|
pushq %rax /* pt_regs->orig_ax */
|
|
|
|
pushq %rdi /* pt_regs->di */
|
|
|
|
pushq %rsi /* pt_regs->si */
|
|
|
|
pushq %rdx /* pt_regs->dx */
|
2015-10-06 08:48:11 +08:00
|
|
|
pushq %rcx /* pt_regs->cx (will be overwritten) */
|
x86/debug: Remove perpetually broken, unmaintainable dwarf annotations
So the dwarf2 annotations in low level assembly code have
become an increasing hindrance: unreadable, messy macros
mixed into some of the most security sensitive code paths
of the Linux kernel.
These debug info annotations don't even buy the upstream
kernel anything: dwarf driven stack unwinding has caused
problems in the past so it's out of tree, and the upstream
kernel only uses the much more robust framepointers based
stack unwinding method.
In addition to that there's a steady, slow bitrot going
on with these annotations, requiring frequent fixups.
There's no tooling and no functionality upstream that
keeps it correct.
So burn down the sick forest, allowing new, healthier growth:
27 files changed, 350 insertions(+), 1101 deletions(-)
Someone who has the willingness and time to do this
properly can attempt to reintroduce dwarf debuginfo in x86
assembly code plus dwarf unwinding from first principles,
with the following conditions:
- it should be maximally readable, and maximally low-key to
'ordinary' code reading and maintenance.
- find a build time method to insert dwarf annotations
automatically in the most common cases, for pop/push
instructions that manipulate the stack pointer. This could
be done for example via a preprocessing step that just
looks for common patterns - plus special annotations for
the few cases where we want to depart from the default.
We have hundreds of CFI annotations, so automating most of
that makes sense.
- it should come with build tooling checks that ensure that
CFI annotations are sensible. We've seen such efforts from
the framepointer side, and there's no reason it couldn't be
done on the dwarf side.
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: Frédéric Weisbecker <fweisbec@gmail.com
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Jan Beulich <JBeulich@suse.com>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2015-05-28 18:21:47 +08:00
|
|
|
pushq $-ENOSYS /* pt_regs->ax */
|
2015-10-06 08:48:11 +08:00
|
|
|
pushq %r8 /* pt_regs->r8 = 0 */
|
|
|
|
pushq %r8 /* pt_regs->r9 = 0 */
|
|
|
|
pushq %r8 /* pt_regs->r10 = 0 */
|
|
|
|
pushq %r8 /* pt_regs->r11 = 0 */
|
|
|
|
pushq %rbx /* pt_regs->rbx */
|
|
|
|
pushq %rbp /* pt_regs->rbp */
|
|
|
|
pushq %r8 /* pt_regs->r12 = 0 */
|
|
|
|
pushq %r8 /* pt_regs->r13 = 0 */
|
|
|
|
pushq %r8 /* pt_regs->r14 = 0 */
|
|
|
|
pushq %r8 /* pt_regs->r15 = 0 */
|
2005-04-17 06:20:36 +08:00
|
|
|
cld
|
2015-04-01 01:00:04 +08:00
|
|
|
|
x86_64, entry: Filter RFLAGS.NT on entry from userspace
The NT flag doesn't do anything in long mode other than causing IRET
to #GP. Oddly, CPL3 code can still set NT using popf.
Entry via hardware or software interrupt clears NT automatically, so
the only relevant entries are fast syscalls.
If user code causes kernel code to run with NT set, then there's at
least some (small) chance that it could cause trouble. For example,
user code could cause a call to EFI code with NT set, and who knows
what would happen? Apparently some games on Wine sometimes do
this (!), and, if an IRET return happens, they will segfault. That
segfault cannot be handled, because signal delivery fails, too.
This patch programs the CPU to clear NT on entry via SYSCALL (both
32-bit and 64-bit, by my reading of the AMD APM), and it clears NT
in software on entry via SYSENTER.
To save a few cycles, this borrows a trick from Jan Beulich in Xen:
it checks whether NT is set before trying to clear it. As a result,
it seems to have very little effect on SYSENTER performance on my
machine.
There's another minor bug fix in here: it looks like the CFI
annotations were wrong if CONFIG_AUDITSYSCALL=n.
Testers beware: on Xen, SYSENTER with NT set turns into a GPF.
I haven't touched anything on 32-bit kernels.
The syscall mask change comes from a variant of this patch by Anish
Bhatt.
Note to stable maintainers: there is no known security issue here.
A misguided program can set NT and cause the kernel to try and fail
to deliver SIGSEGV, crashing the program. This patch fixes Far Cry
on Wine: https://bugs.winehq.org/show_bug.cgi?id=33275
Cc: <stable@vger.kernel.org>
Reported-by: Anish Bhatt <anish@chelsio.com>
Signed-off-by: Andy Lutomirski <luto@amacapital.net>
Link: http://lkml.kernel.org/r/395749a5d39a29bd3e4b35899cf3a3c1340e5595.1412189265.git.luto@amacapital.net
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2014-10-02 02:49:04 +08:00
|
|
|
/*
|
|
|
|
* Sysenter doesn't filter flags, so we need to clear NT
|
|
|
|
* ourselves. To save a few cycles, we can check whether
|
|
|
|
* NT was set instead of doing an unconditional popfq.
|
2015-10-06 08:47:55 +08:00
|
|
|
* This needs to happen before enabling interrupts so that
|
|
|
|
* we don't get preempted with NT set.
|
2015-10-10 01:08:59 +08:00
|
|
|
*
|
|
|
|
* NB.: sysenter_fix_flags is a label with the code under it moved
|
|
|
|
* out-of-line as an optimization: NT is unlikely to be set in the
|
|
|
|
* majority of the cases and instead of polluting the I$ unnecessarily,
|
|
|
|
* we're keeping that code behind a branch which will predict as
|
|
|
|
* not-taken and therefore its instructions won't be fetched.
|
x86_64, entry: Filter RFLAGS.NT on entry from userspace
The NT flag doesn't do anything in long mode other than causing IRET
to #GP. Oddly, CPL3 code can still set NT using popf.
Entry via hardware or software interrupt clears NT automatically, so
the only relevant entries are fast syscalls.
If user code causes kernel code to run with NT set, then there's at
least some (small) chance that it could cause trouble. For example,
user code could cause a call to EFI code with NT set, and who knows
what would happen? Apparently some games on Wine sometimes do
this (!), and, if an IRET return happens, they will segfault. That
segfault cannot be handled, because signal delivery fails, too.
This patch programs the CPU to clear NT on entry via SYSCALL (both
32-bit and 64-bit, by my reading of the AMD APM), and it clears NT
in software on entry via SYSENTER.
To save a few cycles, this borrows a trick from Jan Beulich in Xen:
it checks whether NT is set before trying to clear it. As a result,
it seems to have very little effect on SYSENTER performance on my
machine.
There's another minor bug fix in here: it looks like the CFI
annotations were wrong if CONFIG_AUDITSYSCALL=n.
Testers beware: on Xen, SYSENTER with NT set turns into a GPF.
I haven't touched anything on 32-bit kernels.
The syscall mask change comes from a variant of this patch by Anish
Bhatt.
Note to stable maintainers: there is no known security issue here.
A misguided program can set NT and cause the kernel to try and fail
to deliver SIGSEGV, crashing the program. This patch fixes Far Cry
on Wine: https://bugs.winehq.org/show_bug.cgi?id=33275
Cc: <stable@vger.kernel.org>
Reported-by: Anish Bhatt <anish@chelsio.com>
Signed-off-by: Andy Lutomirski <luto@amacapital.net>
Link: http://lkml.kernel.org/r/395749a5d39a29bd3e4b35899cf3a3c1340e5595.1412189265.git.luto@amacapital.net
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2014-10-02 02:49:04 +08:00
|
|
|
*/
|
2015-06-05 19:02:28 +08:00
|
|
|
testl $X86_EFLAGS_NT, EFLAGS(%rsp)
|
|
|
|
jnz sysenter_fix_flags
|
x86_64, entry: Filter RFLAGS.NT on entry from userspace
The NT flag doesn't do anything in long mode other than causing IRET
to #GP. Oddly, CPL3 code can still set NT using popf.
Entry via hardware or software interrupt clears NT automatically, so
the only relevant entries are fast syscalls.
If user code causes kernel code to run with NT set, then there's at
least some (small) chance that it could cause trouble. For example,
user code could cause a call to EFI code with NT set, and who knows
what would happen? Apparently some games on Wine sometimes do
this (!), and, if an IRET return happens, they will segfault. That
segfault cannot be handled, because signal delivery fails, too.
This patch programs the CPU to clear NT on entry via SYSCALL (both
32-bit and 64-bit, by my reading of the AMD APM), and it clears NT
in software on entry via SYSENTER.
To save a few cycles, this borrows a trick from Jan Beulich in Xen:
it checks whether NT is set before trying to clear it. As a result,
it seems to have very little effect on SYSENTER performance on my
machine.
There's another minor bug fix in here: it looks like the CFI
annotations were wrong if CONFIG_AUDITSYSCALL=n.
Testers beware: on Xen, SYSENTER with NT set turns into a GPF.
I haven't touched anything on 32-bit kernels.
The syscall mask change comes from a variant of this patch by Anish
Bhatt.
Note to stable maintainers: there is no known security issue here.
A misguided program can set NT and cause the kernel to try and fail
to deliver SIGSEGV, crashing the program. This patch fixes Far Cry
on Wine: https://bugs.winehq.org/show_bug.cgi?id=33275
Cc: <stable@vger.kernel.org>
Reported-by: Anish Bhatt <anish@chelsio.com>
Signed-off-by: Andy Lutomirski <luto@amacapital.net>
Link: http://lkml.kernel.org/r/395749a5d39a29bd3e4b35899cf3a3c1340e5595.1412189265.git.luto@amacapital.net
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2014-10-02 02:49:04 +08:00
|
|
|
sysenter_flags_fixed:
|
|
|
|
|
2015-10-06 08:48:11 +08:00
|
|
|
/*
|
|
|
|
* User mode is traced as though IRQs are on, and SYSENTER
|
|
|
|
* turned them off.
|
|
|
|
*/
|
|
|
|
TRACE_IRQS_OFF
|
2015-10-06 08:48:02 +08:00
|
|
|
|
2015-10-06 08:48:11 +08:00
|
|
|
movq %rsp, %rdi
|
|
|
|
call do_fast_syscall_32
|
2015-11-20 05:55:45 +08:00
|
|
|
/* XEN PV guests always use IRET path */
|
|
|
|
ALTERNATIVE "testl %eax, %eax; jz .Lsyscall_32_done", \
|
|
|
|
"jmp .Lsyscall_32_done", X86_FEATURE_XENPV
|
2015-10-06 08:48:12 +08:00
|
|
|
jmp sysret32_from_system_call
|
2005-04-17 06:20:36 +08:00
|
|
|
|
x86_64, entry: Filter RFLAGS.NT on entry from userspace
The NT flag doesn't do anything in long mode other than causing IRET
to #GP. Oddly, CPL3 code can still set NT using popf.
Entry via hardware or software interrupt clears NT automatically, so
the only relevant entries are fast syscalls.
If user code causes kernel code to run with NT set, then there's at
least some (small) chance that it could cause trouble. For example,
user code could cause a call to EFI code with NT set, and who knows
what would happen? Apparently some games on Wine sometimes do
this (!), and, if an IRET return happens, they will segfault. That
segfault cannot be handled, because signal delivery fails, too.
This patch programs the CPU to clear NT on entry via SYSCALL (both
32-bit and 64-bit, by my reading of the AMD APM), and it clears NT
in software on entry via SYSENTER.
To save a few cycles, this borrows a trick from Jan Beulich in Xen:
it checks whether NT is set before trying to clear it. As a result,
it seems to have very little effect on SYSENTER performance on my
machine.
There's another minor bug fix in here: it looks like the CFI
annotations were wrong if CONFIG_AUDITSYSCALL=n.
Testers beware: on Xen, SYSENTER with NT set turns into a GPF.
I haven't touched anything on 32-bit kernels.
The syscall mask change comes from a variant of this patch by Anish
Bhatt.
Note to stable maintainers: there is no known security issue here.
A misguided program can set NT and cause the kernel to try and fail
to deliver SIGSEGV, crashing the program. This patch fixes Far Cry
on Wine: https://bugs.winehq.org/show_bug.cgi?id=33275
Cc: <stable@vger.kernel.org>
Reported-by: Anish Bhatt <anish@chelsio.com>
Signed-off-by: Andy Lutomirski <luto@amacapital.net>
Link: http://lkml.kernel.org/r/395749a5d39a29bd3e4b35899cf3a3c1340e5595.1412189265.git.luto@amacapital.net
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2014-10-02 02:49:04 +08:00
|
|
|
sysenter_fix_flags:
|
2015-10-06 08:47:55 +08:00
|
|
|
pushq $X86_EFLAGS_FIXED
|
x86/debug: Remove perpetually broken, unmaintainable dwarf annotations
So the dwarf2 annotations in low level assembly code have
become an increasing hindrance: unreadable, messy macros
mixed into some of the most security sensitive code paths
of the Linux kernel.
These debug info annotations don't even buy the upstream
kernel anything: dwarf driven stack unwinding has caused
problems in the past so it's out of tree, and the upstream
kernel only uses the much more robust framepointers based
stack unwinding method.
In addition to that there's a steady, slow bitrot going
on with these annotations, requiring frequent fixups.
There's no tooling and no functionality upstream that
keeps it correct.
So burn down the sick forest, allowing new, healthier growth:
27 files changed, 350 insertions(+), 1101 deletions(-)
Someone who has the willingness and time to do this
properly can attempt to reintroduce dwarf debuginfo in x86
assembly code plus dwarf unwinding from first principles,
with the following conditions:
- it should be maximally readable, and maximally low-key to
'ordinary' code reading and maintenance.
- find a build time method to insert dwarf annotations
automatically in the most common cases, for pop/push
instructions that manipulate the stack pointer. This could
be done for example via a preprocessing step that just
looks for common patterns - plus special annotations for
the few cases where we want to depart from the default.
We have hundreds of CFI annotations, so automating most of
that makes sense.
- it should come with build tooling checks that ensure that
CFI annotations are sensible. We've seen such efforts from
the framepointer side, and there's no reason it couldn't be
done on the dwarf side.
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: Frédéric Weisbecker <fweisbec@gmail.com
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Jan Beulich <JBeulich@suse.com>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2015-05-28 18:21:47 +08:00
|
|
|
popfq
|
2015-06-05 19:02:28 +08:00
|
|
|
jmp sysenter_flags_fixed
|
2015-06-08 14:33:56 +08:00
|
|
|
ENDPROC(entry_SYSENTER_compat)
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/*
|
2015-06-05 19:02:28 +08:00
|
|
|
* 32-bit SYSCALL instruction entry.
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
2015-06-05 19:02:28 +08:00
|
|
|
* 32-bit SYSCALL saves rip to rcx, clears rflags.RF, then saves rflags to r11,
|
2015-02-27 06:40:32 +08:00
|
|
|
* then loads new ss, cs, and rip from previously programmed MSRs.
|
|
|
|
* rflags gets masked by a value from another MSR (so CLD and CLAC
|
|
|
|
* are not needed). SYSCALL does not save anything on the stack
|
|
|
|
* and does not change rsp.
|
|
|
|
*
|
|
|
|
* Note: rflags saving+masking-with-MSR happens only in Long mode
|
2015-06-05 19:02:28 +08:00
|
|
|
* (in legacy 32-bit mode, IF, RF and VM bits are cleared and that's it).
|
2015-02-27 06:40:32 +08:00
|
|
|
* Don't get confused: rflags saving+masking depends on Long Mode Active bit
|
|
|
|
* (EFER.LMA=1), NOT on bitness of userspace where SYSCALL executes
|
|
|
|
* or target CS descriptor's L bit (SYSCALL does not read segment descriptors).
|
|
|
|
*
|
2005-04-17 06:20:36 +08:00
|
|
|
* Arguments:
|
2015-02-27 06:40:32 +08:00
|
|
|
* eax system call number
|
|
|
|
* ecx return address
|
|
|
|
* ebx arg1
|
|
|
|
* ebp arg2 (note: not saved in the stack frame, should not be touched)
|
|
|
|
* edx arg3
|
|
|
|
* esi arg4
|
|
|
|
* edi arg5
|
|
|
|
* esp user stack
|
|
|
|
* 0(%esp) arg6
|
|
|
|
*/
|
2015-06-08 14:28:07 +08:00
|
|
|
ENTRY(entry_SYSCALL_compat)
|
2015-10-06 08:48:11 +08:00
|
|
|
/* Interrupts are off on entry. */
|
2008-06-26 22:28:51 +08:00
|
|
|
SWAPGS_UNSAFE_STACK
|
2015-10-06 08:48:02 +08:00
|
|
|
|
2015-10-06 08:48:11 +08:00
|
|
|
/* Stash user ESP and switch to the kernel stack. */
|
2015-06-05 19:02:28 +08:00
|
|
|
movl %esp, %r8d
|
|
|
|
movq PER_CPU_VAR(cpu_current_top_of_stack), %rsp
|
2015-03-27 18:36:20 +08:00
|
|
|
|
2015-03-27 18:36:21 +08:00
|
|
|
/* Zero-extending 32-bit regs, do not remove */
|
2015-06-05 19:02:28 +08:00
|
|
|
movl %eax, %eax
|
2015-03-27 18:36:21 +08:00
|
|
|
|
2015-04-01 01:00:04 +08:00
|
|
|
/* Construct struct pt_regs on stack */
|
x86/debug: Remove perpetually broken, unmaintainable dwarf annotations
So the dwarf2 annotations in low level assembly code have
become an increasing hindrance: unreadable, messy macros
mixed into some of the most security sensitive code paths
of the Linux kernel.
These debug info annotations don't even buy the upstream
kernel anything: dwarf driven stack unwinding has caused
problems in the past so it's out of tree, and the upstream
kernel only uses the much more robust framepointers based
stack unwinding method.
In addition to that there's a steady, slow bitrot going
on with these annotations, requiring frequent fixups.
There's no tooling and no functionality upstream that
keeps it correct.
So burn down the sick forest, allowing new, healthier growth:
27 files changed, 350 insertions(+), 1101 deletions(-)
Someone who has the willingness and time to do this
properly can attempt to reintroduce dwarf debuginfo in x86
assembly code plus dwarf unwinding from first principles,
with the following conditions:
- it should be maximally readable, and maximally low-key to
'ordinary' code reading and maintenance.
- find a build time method to insert dwarf annotations
automatically in the most common cases, for pop/push
instructions that manipulate the stack pointer. This could
be done for example via a preprocessing step that just
looks for common patterns - plus special annotations for
the few cases where we want to depart from the default.
We have hundreds of CFI annotations, so automating most of
that makes sense.
- it should come with build tooling checks that ensure that
CFI annotations are sensible. We've seen such efforts from
the framepointer side, and there's no reason it couldn't be
done on the dwarf side.
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: Frédéric Weisbecker <fweisbec@gmail.com
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Jan Beulich <JBeulich@suse.com>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2015-05-28 18:21:47 +08:00
|
|
|
pushq $__USER32_DS /* pt_regs->ss */
|
|
|
|
pushq %r8 /* pt_regs->sp */
|
|
|
|
pushq %r11 /* pt_regs->flags */
|
|
|
|
pushq $__USER32_CS /* pt_regs->cs */
|
|
|
|
pushq %rcx /* pt_regs->ip */
|
|
|
|
pushq %rax /* pt_regs->orig_ax */
|
|
|
|
pushq %rdi /* pt_regs->di */
|
|
|
|
pushq %rsi /* pt_regs->si */
|
|
|
|
pushq %rdx /* pt_regs->dx */
|
2015-10-06 08:48:11 +08:00
|
|
|
pushq %rcx /* pt_regs->cx (will be overwritten) */
|
x86/debug: Remove perpetually broken, unmaintainable dwarf annotations
So the dwarf2 annotations in low level assembly code have
become an increasing hindrance: unreadable, messy macros
mixed into some of the most security sensitive code paths
of the Linux kernel.
These debug info annotations don't even buy the upstream
kernel anything: dwarf driven stack unwinding has caused
problems in the past so it's out of tree, and the upstream
kernel only uses the much more robust framepointers based
stack unwinding method.
In addition to that there's a steady, slow bitrot going
on with these annotations, requiring frequent fixups.
There's no tooling and no functionality upstream that
keeps it correct.
So burn down the sick forest, allowing new, healthier growth:
27 files changed, 350 insertions(+), 1101 deletions(-)
Someone who has the willingness and time to do this
properly can attempt to reintroduce dwarf debuginfo in x86
assembly code plus dwarf unwinding from first principles,
with the following conditions:
- it should be maximally readable, and maximally low-key to
'ordinary' code reading and maintenance.
- find a build time method to insert dwarf annotations
automatically in the most common cases, for pop/push
instructions that manipulate the stack pointer. This could
be done for example via a preprocessing step that just
looks for common patterns - plus special annotations for
the few cases where we want to depart from the default.
We have hundreds of CFI annotations, so automating most of
that makes sense.
- it should come with build tooling checks that ensure that
CFI annotations are sensible. We've seen such efforts from
the framepointer side, and there's no reason it couldn't be
done on the dwarf side.
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: Frédéric Weisbecker <fweisbec@gmail.com
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Jan Beulich <JBeulich@suse.com>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2015-05-28 18:21:47 +08:00
|
|
|
pushq $-ENOSYS /* pt_regs->ax */
|
2015-10-06 08:48:11 +08:00
|
|
|
xorq %r8,%r8
|
|
|
|
pushq %r8 /* pt_regs->r8 = 0 */
|
|
|
|
pushq %r8 /* pt_regs->r9 = 0 */
|
|
|
|
pushq %r8 /* pt_regs->r10 = 0 */
|
|
|
|
pushq %r8 /* pt_regs->r11 = 0 */
|
|
|
|
pushq %rbx /* pt_regs->rbx */
|
|
|
|
pushq %rbp /* pt_regs->rbp */
|
|
|
|
pushq %r8 /* pt_regs->r12 = 0 */
|
|
|
|
pushq %r8 /* pt_regs->r13 = 0 */
|
|
|
|
pushq %r8 /* pt_regs->r14 = 0 */
|
|
|
|
pushq %r8 /* pt_regs->r15 = 0 */
|
2015-04-01 01:00:04 +08:00
|
|
|
|
2015-10-06 08:48:11 +08:00
|
|
|
/*
|
|
|
|
* User mode is traced as though IRQs are on, and SYSENTER
|
|
|
|
* turned them off.
|
|
|
|
*/
|
|
|
|
TRACE_IRQS_OFF
|
|
|
|
|
|
|
|
movq %rsp, %rdi
|
|
|
|
call do_fast_syscall_32
|
2015-11-20 05:55:45 +08:00
|
|
|
/* XEN PV guests always use IRET path */
|
|
|
|
ALTERNATIVE "testl %eax, %eax; jz .Lsyscall_32_done", \
|
|
|
|
"jmp .Lsyscall_32_done", X86_FEATURE_XENPV
|
2015-10-06 08:48:12 +08:00
|
|
|
|
|
|
|
/* Opportunistic SYSRET */
|
|
|
|
sysret32_from_system_call:
|
|
|
|
TRACE_IRQS_ON /* User mode traces as IRQs on. */
|
|
|
|
movq RBX(%rsp), %rbx /* pt_regs->rbx */
|
|
|
|
movq RBP(%rsp), %rbp /* pt_regs->rbp */
|
|
|
|
movq EFLAGS(%rsp), %r11 /* pt_regs->flags (in r11) */
|
|
|
|
movq RIP(%rsp), %rcx /* pt_regs->ip (in rcx) */
|
|
|
|
addq $RAX, %rsp /* Skip r8-r15 */
|
|
|
|
popq %rax /* pt_regs->rax */
|
|
|
|
popq %rdx /* Skip pt_regs->cx */
|
|
|
|
popq %rdx /* pt_regs->dx */
|
|
|
|
popq %rsi /* pt_regs->si */
|
|
|
|
popq %rdi /* pt_regs->di */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* USERGS_SYSRET32 does:
|
|
|
|
* GSBASE = user's GS base
|
|
|
|
* EIP = ECX
|
|
|
|
* RFLAGS = R11
|
|
|
|
* CS = __USER32_CS
|
|
|
|
* SS = __USER_DS
|
|
|
|
*
|
|
|
|
* ECX will not match pt_regs->cx, but we're returning to a vDSO
|
|
|
|
* trampoline that will fix up RCX, so this is okay.
|
|
|
|
*
|
|
|
|
* R12-R15 are callee-saved, so they contain whatever was in them
|
|
|
|
* when the system call started, which is already known to user
|
|
|
|
* code. We zero R8-R10 to avoid info leaks.
|
|
|
|
*/
|
|
|
|
xorq %r8, %r8
|
|
|
|
xorq %r9, %r9
|
|
|
|
xorq %r10, %r10
|
|
|
|
movq RSP-ORIG_RAX(%rsp), %rsp
|
2015-11-20 05:55:47 +08:00
|
|
|
swapgs
|
|
|
|
sysretl
|
2015-06-08 14:28:07 +08:00
|
|
|
END(entry_SYSCALL_compat)
|
2015-06-05 19:02:28 +08:00
|
|
|
|
2015-02-27 06:40:32 +08:00
|
|
|
/*
|
|
|
|
* Emulated IA32 system calls via int 0x80.
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
2015-02-27 06:40:32 +08:00
|
|
|
* Arguments:
|
|
|
|
* eax system call number
|
|
|
|
* ebx arg1
|
|
|
|
* ecx arg2
|
|
|
|
* edx arg3
|
|
|
|
* esi arg4
|
|
|
|
* edi arg5
|
|
|
|
* ebp arg6 (note: not saved in the stack frame, should not be touched)
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
|
|
|
* Notes:
|
2015-02-27 06:40:32 +08:00
|
|
|
* Uses the same stack frame as the x86-64 version.
|
|
|
|
* All registers except eax must be saved (but ptrace may violate that).
|
2005-04-17 06:20:36 +08:00
|
|
|
* Arguments are zero extended. For system calls that want sign extension and
|
|
|
|
* take long arguments a wrapper is needed. Most calls can just be called
|
|
|
|
* directly.
|
2015-02-27 06:40:32 +08:00
|
|
|
* Assumes it is only called from user space and entered with interrupts off.
|
|
|
|
*/
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2015-06-08 14:28:07 +08:00
|
|
|
ENTRY(entry_INT80_compat)
|
2006-07-03 15:24:45 +08:00
|
|
|
/*
|
2015-03-27 18:36:20 +08:00
|
|
|
* Interrupts are off on entry.
|
2006-07-03 15:24:45 +08:00
|
|
|
*/
|
2015-03-27 18:36:20 +08:00
|
|
|
PARAVIRT_ADJUST_EXCEPTION_FRAME
|
|
|
|
SWAPGS
|
|
|
|
|
2015-10-06 08:48:09 +08:00
|
|
|
/*
|
|
|
|
* User tracing code (ptrace or signal handlers) might assume that
|
|
|
|
* the saved RAX contains a 32-bit number when we're invoking a 32-bit
|
|
|
|
* syscall. Just in case the high bits are nonzero, zero-extend
|
|
|
|
* the syscall number. (This could almost certainly be deleted
|
|
|
|
* with no ill effects.)
|
|
|
|
*/
|
2015-06-05 19:02:28 +08:00
|
|
|
movl %eax, %eax
|
2015-03-27 18:36:21 +08:00
|
|
|
|
2015-04-01 01:00:04 +08:00
|
|
|
/* Construct struct pt_regs on stack (iret frame is already on stack) */
|
x86/debug: Remove perpetually broken, unmaintainable dwarf annotations
So the dwarf2 annotations in low level assembly code have
become an increasing hindrance: unreadable, messy macros
mixed into some of the most security sensitive code paths
of the Linux kernel.
These debug info annotations don't even buy the upstream
kernel anything: dwarf driven stack unwinding has caused
problems in the past so it's out of tree, and the upstream
kernel only uses the much more robust framepointers based
stack unwinding method.
In addition to that there's a steady, slow bitrot going
on with these annotations, requiring frequent fixups.
There's no tooling and no functionality upstream that
keeps it correct.
So burn down the sick forest, allowing new, healthier growth:
27 files changed, 350 insertions(+), 1101 deletions(-)
Someone who has the willingness and time to do this
properly can attempt to reintroduce dwarf debuginfo in x86
assembly code plus dwarf unwinding from first principles,
with the following conditions:
- it should be maximally readable, and maximally low-key to
'ordinary' code reading and maintenance.
- find a build time method to insert dwarf annotations
automatically in the most common cases, for pop/push
instructions that manipulate the stack pointer. This could
be done for example via a preprocessing step that just
looks for common patterns - plus special annotations for
the few cases where we want to depart from the default.
We have hundreds of CFI annotations, so automating most of
that makes sense.
- it should come with build tooling checks that ensure that
CFI annotations are sensible. We've seen such efforts from
the framepointer side, and there's no reason it couldn't be
done on the dwarf side.
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: Frédéric Weisbecker <fweisbec@gmail.com
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Jan Beulich <JBeulich@suse.com>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2015-05-28 18:21:47 +08:00
|
|
|
pushq %rax /* pt_regs->orig_ax */
|
|
|
|
pushq %rdi /* pt_regs->di */
|
|
|
|
pushq %rsi /* pt_regs->si */
|
|
|
|
pushq %rdx /* pt_regs->dx */
|
|
|
|
pushq %rcx /* pt_regs->cx */
|
|
|
|
pushq $-ENOSYS /* pt_regs->ax */
|
2015-10-06 08:48:05 +08:00
|
|
|
xorq %r8,%r8
|
|
|
|
pushq %r8 /* pt_regs->r8 = 0 */
|
|
|
|
pushq %r8 /* pt_regs->r9 = 0 */
|
|
|
|
pushq %r8 /* pt_regs->r10 = 0 */
|
|
|
|
pushq %r8 /* pt_regs->r11 = 0 */
|
|
|
|
pushq %rbx /* pt_regs->rbx */
|
|
|
|
pushq %rbp /* pt_regs->rbp */
|
|
|
|
pushq %r12 /* pt_regs->r12 */
|
|
|
|
pushq %r13 /* pt_regs->r13 */
|
|
|
|
pushq %r14 /* pt_regs->r14 */
|
|
|
|
pushq %r15 /* pt_regs->r15 */
|
2005-04-17 06:20:36 +08:00
|
|
|
cld
|
2015-06-05 19:02:28 +08:00
|
|
|
|
2015-06-03 03:04:02 +08:00
|
|
|
/*
|
2015-10-06 08:48:09 +08:00
|
|
|
* User mode is traced as though IRQs are on, and the interrupt
|
|
|
|
* gate turned them off.
|
2015-06-03 03:04:02 +08:00
|
|
|
*/
|
2015-10-06 08:48:09 +08:00
|
|
|
TRACE_IRQS_OFF
|
|
|
|
|
|
|
|
movq %rsp, %rdi
|
2015-10-17 06:42:54 +08:00
|
|
|
call do_syscall_32_irqs_off
|
2015-10-06 08:48:11 +08:00
|
|
|
.Lsyscall_32_done:
|
2015-10-06 08:48:09 +08:00
|
|
|
|
|
|
|
/* Go back to user mode. */
|
|
|
|
TRACE_IRQS_ON
|
|
|
|
SWAPGS
|
|
|
|
jmp restore_regs_and_iret
|
2015-06-08 14:28:07 +08:00
|
|
|
END(entry_INT80_compat)
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2012-10-23 10:34:11 +08:00
|
|
|
ALIGN
|
|
|
|
GLOBAL(stub32_clone)
|
2015-06-03 21:58:49 +08:00
|
|
|
/*
|
2015-06-03 21:58:50 +08:00
|
|
|
* The 32-bit clone ABI is: clone(..., int tls_val, int *child_tidptr).
|
|
|
|
* The 64-bit clone ABI is: clone(..., int *child_tidptr, int tls_val).
|
|
|
|
*
|
|
|
|
* The native 64-bit kernel's sys_clone() implements the latter,
|
|
|
|
* so we need to swap arguments here before calling it:
|
2015-06-03 21:58:49 +08:00
|
|
|
*/
|
2015-06-03 21:58:50 +08:00
|
|
|
xchg %r8, %rcx
|
2015-10-06 08:48:05 +08:00
|
|
|
jmp sys_clone
|