aboutsummaryrefslogtreecommitdiffstats
path: root/arch/x86/ia32/ia32entry.S
diff options
context:
space:
mode:
authorAndy Lutomirski <luto@amacapital.net>2014-10-01 14:49:04 -0400
committerH. Peter Anvin <hpa@zytor.com>2014-10-06 13:53:26 -0400
commit8c7aa698baca5e8f1ba9edb68081f1e7a1abf455 (patch)
tree296b6b8df27b007dd70b56c42832720c365d224d /arch/x86/ia32/ia32entry.S
parent20cc28882bf4a8c9a2605a9a76a7952e696aaece (diff)
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>
Diffstat (limited to 'arch/x86/ia32/ia32entry.S')
-rw-r--r--arch/x86/ia32/ia32entry.S18
1 files changed, 17 insertions, 1 deletions
diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
index 4299eb05023c..711de084ab57 100644
--- a/arch/x86/ia32/ia32entry.S
+++ b/arch/x86/ia32/ia32entry.S
@@ -151,6 +151,16 @@ ENTRY(ia32_sysenter_target)
1511: movl (%rbp),%ebp 1511: movl (%rbp),%ebp
152 _ASM_EXTABLE(1b,ia32_badarg) 152 _ASM_EXTABLE(1b,ia32_badarg)
153 ASM_CLAC 153 ASM_CLAC
154
155 /*
156 * Sysenter doesn't filter flags, so we need to clear NT
157 * ourselves. To save a few cycles, we can check whether
158 * NT was set instead of doing an unconditional popfq.
159 */
160 testl $X86_EFLAGS_NT,EFLAGS(%rsp) /* saved EFLAGS match cpu */
161 jnz sysenter_fix_flags
162sysenter_flags_fixed:
163
154 orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET) 164 orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
155 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET) 165 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
156 CFI_REMEMBER_STATE 166 CFI_REMEMBER_STATE
@@ -184,6 +194,8 @@ sysexit_from_sys_call:
184 TRACE_IRQS_ON 194 TRACE_IRQS_ON
185 ENABLE_INTERRUPTS_SYSEXIT32 195 ENABLE_INTERRUPTS_SYSEXIT32
186 196
197 CFI_RESTORE_STATE
198
187#ifdef CONFIG_AUDITSYSCALL 199#ifdef CONFIG_AUDITSYSCALL
188 .macro auditsys_entry_common 200 .macro auditsys_entry_common
189 movl %esi,%r9d /* 6th arg: 4th syscall arg */ 201 movl %esi,%r9d /* 6th arg: 4th syscall arg */
@@ -226,7 +238,6 @@ sysexit_from_sys_call:
226 .endm 238 .endm
227 239
228sysenter_auditsys: 240sysenter_auditsys:
229 CFI_RESTORE_STATE
230 auditsys_entry_common 241 auditsys_entry_common
231 movl %ebp,%r9d /* reload 6th syscall arg */ 242 movl %ebp,%r9d /* reload 6th syscall arg */
232 jmp sysenter_dispatch 243 jmp sysenter_dispatch
@@ -235,6 +246,11 @@ sysexit_audit:
235 auditsys_exit sysexit_from_sys_call 246 auditsys_exit sysexit_from_sys_call
236#endif 247#endif
237 248
249sysenter_fix_flags:
250 pushq_cfi $(X86_EFLAGS_IF|X86_EFLAGS_FIXED)
251 popfq_cfi
252 jmp sysenter_flags_fixed
253
238sysenter_tracesys: 254sysenter_tracesys:
239#ifdef CONFIG_AUDITSYSCALL 255#ifdef CONFIG_AUDITSYSCALL
240 testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET) 256 testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)