Commit 15385dfe authored by Linus Torvalds's avatar Linus Torvalds

Merge branch 'x86-smap-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip

Pull x86/smap support from Ingo Molnar:
 "This adds support for the SMAP (Supervisor Mode Access Prevention) CPU
  feature on Intel CPUs: a hardware feature that prevents unintended
  user-space data access from kernel privileged code.

  It's turned on automatically when possible.

  This, in combination with SMEP, makes it even harder to exploit kernel
  bugs such as NULL pointer dereferences."

Fix up trivial conflict in arch/x86/kernel/entry_64.S due to newly added
includes right next to each other.

* 'x86-smap-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip:
  x86, smep, smap: Make the switching functions one-way
  x86, suspend: On wakeup always initialize cr4 and EFER
  x86-32: Start out eflags and cr4 clean
  x86, smap: Do not abuse the [f][x]rstor_checking() functions for user space
  x86-32, smap: Add STAC/CLAC instructions to 32-bit kernel entry
  x86, smap: Reduce the SMAP overhead for signal handling
  x86, smap: A page fault due to SMAP is an oops
  x86, smap: Turn on Supervisor Mode Access Prevention
  x86, smap: Add STAC and CLAC instructions to control user space access
  x86, uaccess: Merge prototypes for clear_user/__clear_user
  x86, smap: Add a header file with macros for STAC/CLAC
  x86, alternative: Add header guards to <asm/alternative-asm.h>
  x86, alternative: Use .pushsection/.popsection
  x86, smap: Add CR4 bit for SMAP
  x86-32, mm: The WP test should be done on a kernel page
parents a57d985e b2cc2a07
...@@ -1812,8 +1812,12 @@ bytes respectively. Such letter suffixes can also be entirely omitted. ...@@ -1812,8 +1812,12 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
noexec=on: enable non-executable mappings (default) noexec=on: enable non-executable mappings (default)
noexec=off: disable non-executable mappings noexec=off: disable non-executable mappings
nosmap [X86]
Disable SMAP (Supervisor Mode Access Prevention)
even if it is supported by processor.
nosmep [X86] nosmep [X86]
Disable SMEP (Supervisor Mode Execution Protection) Disable SMEP (Supervisor Mode Execution Prevention)
even if it is supported by processor. even if it is supported by processor.
noexec32 [X86-64] noexec32 [X86-64]
......
...@@ -1493,6 +1493,17 @@ config ARCH_RANDOM ...@@ -1493,6 +1493,17 @@ config ARCH_RANDOM
If supported, this is a high bandwidth, cryptographically If supported, this is a high bandwidth, cryptographically
secure hardware random number generator. secure hardware random number generator.
config X86_SMAP
def_bool y
prompt "Supervisor Mode Access Prevention" if EXPERT
---help---
Supervisor Mode Access Prevention (SMAP) is a security
feature in newer Intel processors. There is a small
performance cost if this enabled and turned on; there is
also a small increase in the kernel size if this is enabled.
If unsure, say Y.
config EFI config EFI
bool "EFI runtime service support" bool "EFI runtime service support"
depends on ACPI depends on ACPI
......
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
#include <asm/sigframe.h> #include <asm/sigframe.h>
#include <asm/sighandling.h> #include <asm/sighandling.h>
#include <asm/sys_ia32.h> #include <asm/sys_ia32.h>
#include <asm/smap.h>
#define FIX_EFLAGS __FIX_EFLAGS #define FIX_EFLAGS __FIX_EFLAGS
...@@ -251,11 +252,12 @@ static int ia32_restore_sigcontext(struct pt_regs *regs, ...@@ -251,11 +252,12 @@ static int ia32_restore_sigcontext(struct pt_regs *regs,
get_user_ex(tmp, &sc->fpstate); get_user_ex(tmp, &sc->fpstate);
buf = compat_ptr(tmp); buf = compat_ptr(tmp);
err |= restore_xstate_sig(buf, 1);
get_user_ex(*pax, &sc->ax); get_user_ex(*pax, &sc->ax);
} get_user_catch(err); } get_user_catch(err);
err |= restore_xstate_sig(buf, 1);
return err; return err;
} }
...@@ -506,7 +508,6 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info, ...@@ -506,7 +508,6 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
put_user_ex(sig, &frame->sig); put_user_ex(sig, &frame->sig);
put_user_ex(ptr_to_compat(&frame->info), &frame->pinfo); put_user_ex(ptr_to_compat(&frame->info), &frame->pinfo);
put_user_ex(ptr_to_compat(&frame->uc), &frame->puc); put_user_ex(ptr_to_compat(&frame->uc), &frame->puc);
err |= copy_siginfo_to_user32(&frame->info, info);
/* Create the ucontext. */ /* Create the ucontext. */
if (cpu_has_xsave) if (cpu_has_xsave)
...@@ -518,9 +519,6 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info, ...@@ -518,9 +519,6 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
put_user_ex(sas_ss_flags(regs->sp), put_user_ex(sas_ss_flags(regs->sp),
&frame->uc.uc_stack.ss_flags); &frame->uc.uc_stack.ss_flags);
put_user_ex(current->sas_ss_size, &frame->uc.uc_stack.ss_size); put_user_ex(current->sas_ss_size, &frame->uc.uc_stack.ss_size);
err |= ia32_setup_sigcontext(&frame->uc.uc_mcontext, fpstate,
regs, set->sig[0]);
err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
if (ka->sa.sa_flags & SA_RESTORER) if (ka->sa.sa_flags & SA_RESTORER)
restorer = ka->sa.sa_restorer; restorer = ka->sa.sa_restorer;
...@@ -536,6 +534,11 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info, ...@@ -536,6 +534,11 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode); put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
} put_user_catch(err); } put_user_catch(err);
err |= copy_siginfo_to_user32(&frame->info, info);
err |= ia32_setup_sigcontext(&frame->uc.uc_mcontext, fpstate,
regs, set->sig[0]);
err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
if (err) if (err)
return -EFAULT; return -EFAULT;
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include <asm/segment.h> #include <asm/segment.h>
#include <asm/irqflags.h> #include <asm/irqflags.h>
#include <asm/asm.h> #include <asm/asm.h>
#include <asm/smap.h>
#include <linux/linkage.h> #include <linux/linkage.h>
#include <linux/err.h> #include <linux/err.h>
...@@ -146,8 +147,10 @@ ENTRY(ia32_sysenter_target) ...@@ -146,8 +147,10 @@ ENTRY(ia32_sysenter_target)
SAVE_ARGS 0,1,0 SAVE_ARGS 0,1,0
/* no need to do an access_ok check here because rbp has been /* no need to do an access_ok check here because rbp has been
32bit zero extended */ 32bit zero extended */
ASM_STAC
1: movl (%rbp),%ebp 1: movl (%rbp),%ebp
_ASM_EXTABLE(1b,ia32_badarg) _ASM_EXTABLE(1b,ia32_badarg)
ASM_CLAC
orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET) orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET) testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
CFI_REMEMBER_STATE CFI_REMEMBER_STATE
...@@ -301,8 +304,10 @@ ENTRY(ia32_cstar_target) ...@@ -301,8 +304,10 @@ ENTRY(ia32_cstar_target)
/* no need to do an access_ok check here because r8 has been /* no need to do an access_ok check here because r8 has been
32bit zero extended */ 32bit zero extended */
/* hardware stack frame is complete now */ /* hardware stack frame is complete now */
ASM_STAC
1: movl (%r8),%r9d 1: movl (%r8),%r9d
_ASM_EXTABLE(1b,ia32_badarg) _ASM_EXTABLE(1b,ia32_badarg)
ASM_CLAC
orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET) orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET) testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
CFI_REMEMBER_STATE CFI_REMEMBER_STATE
...@@ -365,6 +370,7 @@ cstar_tracesys: ...@@ -365,6 +370,7 @@ cstar_tracesys:
END(ia32_cstar_target) END(ia32_cstar_target)
ia32_badarg: ia32_badarg:
ASM_CLAC
movq $-EFAULT,%rax movq $-EFAULT,%rax
jmp ia32_sysret jmp ia32_sysret
CFI_ENDPROC CFI_ENDPROC
......
#ifndef _ASM_X86_ALTERNATIVE_ASM_H
#define _ASM_X86_ALTERNATIVE_ASM_H
#ifdef __ASSEMBLY__ #ifdef __ASSEMBLY__
#include <asm/asm.h> #include <asm/asm.h>
...@@ -5,10 +8,10 @@ ...@@ -5,10 +8,10 @@
#ifdef CONFIG_SMP #ifdef CONFIG_SMP
.macro LOCK_PREFIX .macro LOCK_PREFIX
672: lock 672: lock
.section .smp_locks,"a" .pushsection .smp_locks,"a"
.balign 4 .balign 4
.long 672b - . .long 672b - .
.previous .popsection
.endm .endm
#else #else
.macro LOCK_PREFIX .macro LOCK_PREFIX
...@@ -24,3 +27,5 @@ ...@@ -24,3 +27,5 @@
.endm .endm
#endif /* __ASSEMBLY__ */ #endif /* __ASSEMBLY__ */
#endif /* _ASM_X86_ALTERNATIVE_ASM_H */
...@@ -29,10 +29,10 @@ ...@@ -29,10 +29,10 @@
#ifdef CONFIG_SMP #ifdef CONFIG_SMP
#define LOCK_PREFIX_HERE \ #define LOCK_PREFIX_HERE \
".section .smp_locks,\"a\"\n" \ ".pushsection .smp_locks,\"a\"\n" \
".balign 4\n" \ ".balign 4\n" \
".long 671f - .\n" /* offset */ \ ".long 671f - .\n" /* offset */ \
".previous\n" \ ".popsection\n" \
"671:" "671:"
#define LOCK_PREFIX LOCK_PREFIX_HERE "\n\tlock; " #define LOCK_PREFIX LOCK_PREFIX_HERE "\n\tlock; "
...@@ -99,30 +99,30 @@ static inline int alternatives_text_reserved(void *start, void *end) ...@@ -99,30 +99,30 @@ static inline int alternatives_text_reserved(void *start, void *end)
/* alternative assembly primitive: */ /* alternative assembly primitive: */
#define ALTERNATIVE(oldinstr, newinstr, feature) \ #define ALTERNATIVE(oldinstr, newinstr, feature) \
OLDINSTR(oldinstr) \ OLDINSTR(oldinstr) \
".section .altinstructions,\"a\"\n" \ ".pushsection .altinstructions,\"a\"\n" \
ALTINSTR_ENTRY(feature, 1) \ ALTINSTR_ENTRY(feature, 1) \
".previous\n" \ ".popsection\n" \
".section .discard,\"aw\",@progbits\n" \ ".pushsection .discard,\"aw\",@progbits\n" \
DISCARD_ENTRY(1) \ DISCARD_ENTRY(1) \
".previous\n" \ ".popsection\n" \
".section .altinstr_replacement, \"ax\"\n" \ ".pushsection .altinstr_replacement, \"ax\"\n" \
ALTINSTR_REPLACEMENT(newinstr, feature, 1) \ ALTINSTR_REPLACEMENT(newinstr, feature, 1) \
".previous" ".popsection"
#define ALTERNATIVE_2(oldinstr, newinstr1, feature1, newinstr2, feature2)\ #define ALTERNATIVE_2(oldinstr, newinstr1, feature1, newinstr2, feature2)\
OLDINSTR(oldinstr) \ OLDINSTR(oldinstr) \
".section .altinstructions,\"a\"\n" \ ".pushsection .altinstructions,\"a\"\n" \
ALTINSTR_ENTRY(feature1, 1) \ ALTINSTR_ENTRY(feature1, 1) \
ALTINSTR_ENTRY(feature2, 2) \ ALTINSTR_ENTRY(feature2, 2) \
".previous\n" \ ".popsection\n" \
".section .discard,\"aw\",@progbits\n" \ ".pushsection .discard,\"aw\",@progbits\n" \
DISCARD_ENTRY(1) \ DISCARD_ENTRY(1) \
DISCARD_ENTRY(2) \ DISCARD_ENTRY(2) \
".previous\n" \ ".popsection\n" \
".section .altinstr_replacement, \"ax\"\n" \ ".pushsection .altinstr_replacement, \"ax\"\n" \
ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \ ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \
ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \ ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \
".previous" ".popsection"
/* /*
* This must be included *after* the definition of ALTERNATIVE due to * This must be included *after* the definition of ALTERNATIVE due to
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include <asm/user.h> #include <asm/user.h>
#include <asm/uaccess.h> #include <asm/uaccess.h>
#include <asm/xsave.h> #include <asm/xsave.h>
#include <asm/smap.h>
#ifdef CONFIG_X86_64 #ifdef CONFIG_X86_64
# include <asm/sigcontext32.h> # include <asm/sigcontext32.h>
...@@ -121,6 +122,22 @@ static inline void sanitize_i387_state(struct task_struct *tsk) ...@@ -121,6 +122,22 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
__sanitize_i387_state(tsk); __sanitize_i387_state(tsk);
} }
#define user_insn(insn, output, input...) \
({ \
int err; \
asm volatile(ASM_STAC "\n" \
"1:" #insn "\n\t" \
"2: " ASM_CLAC "\n" \
".section .fixup,\"ax\"\n" \
"3: movl $-1,%[err]\n" \
" jmp 2b\n" \
".previous\n" \
_ASM_EXTABLE(1b, 3b) \
: [err] "=r" (err), output \
: "0"(0), input); \
err; \
})
#define check_insn(insn, output, input...) \ #define check_insn(insn, output, input...) \
({ \ ({ \
int err; \ int err; \
...@@ -138,18 +155,18 @@ static inline void sanitize_i387_state(struct task_struct *tsk) ...@@ -138,18 +155,18 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
static inline int fsave_user(struct i387_fsave_struct __user *fx) static inline int fsave_user(struct i387_fsave_struct __user *fx)
{ {
return check_insn(fnsave %[fx]; fwait, [fx] "=m" (*fx), "m" (*fx)); return user_insn(fnsave %[fx]; fwait, [fx] "=m" (*fx), "m" (*fx));
} }
static inline int fxsave_user(struct i387_fxsave_struct __user *fx) static inline int fxsave_user(struct i387_fxsave_struct __user *fx)
{ {
if (config_enabled(CONFIG_X86_32)) if (config_enabled(CONFIG_X86_32))
return check_insn(fxsave %[fx], [fx] "=m" (*fx), "m" (*fx)); return user_insn(fxsave %[fx], [fx] "=m" (*fx), "m" (*fx));
else if (config_enabled(CONFIG_AS_FXSAVEQ)) else if (config_enabled(CONFIG_AS_FXSAVEQ))
return check_insn(fxsaveq %[fx], [fx] "=m" (*fx), "m" (*fx)); return user_insn(fxsaveq %[fx], [fx] "=m" (*fx), "m" (*fx));
/* See comment in fpu_fxsave() below. */ /* See comment in fpu_fxsave() below. */
return check_insn(rex64/fxsave (%[fx]), "=m" (*fx), [fx] "R" (fx)); return user_insn(rex64/fxsave (%[fx]), "=m" (*fx), [fx] "R" (fx));
} }
static inline int fxrstor_checking(struct i387_fxsave_struct *fx) static inline int fxrstor_checking(struct i387_fxsave_struct *fx)
...@@ -164,11 +181,28 @@ static inline int fxrstor_checking(struct i387_fxsave_struct *fx) ...@@ -164,11 +181,28 @@ static inline int fxrstor_checking(struct i387_fxsave_struct *fx)
"m" (*fx)); "m" (*fx));
} }
static inline int fxrstor_user(struct i387_fxsave_struct __user *fx)
{
if (config_enabled(CONFIG_X86_32))
return user_insn(fxrstor %[fx], "=m" (*fx), [fx] "m" (*fx));
else if (config_enabled(CONFIG_AS_FXSAVEQ))
return user_insn(fxrstorq %[fx], "=m" (*fx), [fx] "m" (*fx));
/* See comment in fpu_fxsave() below. */
return user_insn(rex64/fxrstor (%[fx]), "=m" (*fx), [fx] "R" (fx),
"m" (*fx));
}
static inline int frstor_checking(struct i387_fsave_struct *fx) static inline int frstor_checking(struct i387_fsave_struct *fx)
{ {
return check_insn(frstor %[fx], "=m" (*fx), [fx] "m" (*fx)); return check_insn(frstor %[fx], "=m" (*fx), [fx] "m" (*fx));
} }
static inline int frstor_user(struct i387_fsave_struct __user *fx)
{
return user_insn(frstor %[fx], "=m" (*fx), [fx] "m" (*fx));
}
static inline void fpu_fxsave(struct fpu *fpu) static inline void fpu_fxsave(struct fpu *fpu)
{ {
if (config_enabled(CONFIG_X86_32)) if (config_enabled(CONFIG_X86_32))
......
...@@ -9,10 +9,13 @@ ...@@ -9,10 +9,13 @@
#include <asm/asm.h> #include <asm/asm.h>
#include <asm/errno.h> #include <asm/errno.h>
#include <asm/processor.h> #include <asm/processor.h>
#include <asm/smap.h>
#define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \ #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
asm volatile("1:\t" insn "\n" \ asm volatile("\t" ASM_STAC "\n" \
"2:\t.section .fixup,\"ax\"\n" \ "1:\t" insn "\n" \
"2:\t" ASM_CLAC "\n" \
"\t.section .fixup,\"ax\"\n" \
"3:\tmov\t%3, %1\n" \ "3:\tmov\t%3, %1\n" \
"\tjmp\t2b\n" \ "\tjmp\t2b\n" \
"\t.previous\n" \ "\t.previous\n" \
...@@ -21,12 +24,14 @@ ...@@ -21,12 +24,14 @@
: "i" (-EFAULT), "0" (oparg), "1" (0)) : "i" (-EFAULT), "0" (oparg), "1" (0))
#define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \ #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
asm volatile("1:\tmovl %2, %0\n" \ asm volatile("\t" ASM_STAC "\n" \
"1:\tmovl %2, %0\n" \
"\tmovl\t%0, %3\n" \ "\tmovl\t%0, %3\n" \
"\t" insn "\n" \ "\t" insn "\n" \
"2:\t" LOCK_PREFIX "cmpxchgl %3, %2\n" \ "2:\t" LOCK_PREFIX "cmpxchgl %3, %2\n" \
"\tjnz\t1b\n" \ "\tjnz\t1b\n" \
"3:\t.section .fixup,\"ax\"\n" \ "3:\t" ASM_CLAC "\n" \
"\t.section .fixup,\"ax\"\n" \
"4:\tmov\t%5, %1\n" \ "4:\tmov\t%5, %1\n" \
"\tjmp\t3b\n" \ "\tjmp\t3b\n" \
"\t.previous\n" \ "\t.previous\n" \
...@@ -122,8 +127,10 @@ static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr, ...@@ -122,8 +127,10 @@ static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32))) if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
return -EFAULT; return -EFAULT;
asm volatile("1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n" asm volatile("\t" ASM_STAC "\n"
"2:\t.section .fixup, \"ax\"\n" "1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n"
"2:\t" ASM_CLAC "\n"
"\t.section .fixup, \"ax\"\n"
"3:\tmov %3, %0\n" "3:\tmov %3, %0\n"
"\tjmp 2b\n" "\tjmp 2b\n"
"\t.previous\n" "\t.previous\n"
......
...@@ -65,6 +65,7 @@ ...@@ -65,6 +65,7 @@
#define X86_CR4_PCIDE 0x00020000 /* enable PCID support */ #define X86_CR4_PCIDE 0x00020000 /* enable PCID support */
#define X86_CR4_OSXSAVE 0x00040000 /* enable xsave and xrestore */ #define X86_CR4_OSXSAVE 0x00040000 /* enable xsave and xrestore */
#define X86_CR4_SMEP 0x00100000 /* enable SMEP support */ #define X86_CR4_SMEP 0x00100000 /* enable SMEP support */
#define X86_CR4_SMAP 0x00200000 /* enable SMAP support */
/* /*
* x86-64 Task Priority Register, CR8 * x86-64 Task Priority Register, CR8
......
/*
* Supervisor Mode Access Prevention support
*
* Copyright (C) 2012 Intel Corporation
* Author: H. Peter Anvin <hpa@linux.intel.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; version 2
* of the License.
*/
#ifndef _ASM_X86_SMAP_H
#define _ASM_X86_SMAP_H
#include <linux/stringify.h>
#include <asm/nops.h>
#include <asm/cpufeature.h>
/* "Raw" instruction opcodes */
#define __ASM_CLAC .byte 0x0f,0x01,0xca
#define __ASM_STAC .byte 0x0f,0x01,0xcb
#ifdef __ASSEMBLY__
#include <asm/alternative-asm.h>
#ifdef CONFIG_X86_SMAP
#define ASM_CLAC \
661: ASM_NOP3 ; \
.pushsection .altinstr_replacement, "ax" ; \
662: __ASM_CLAC ; \
.popsection ; \
.pushsection .altinstructions, "a" ; \
altinstruction_entry 661b, 662b, X86_FEATURE_SMAP, 3, 3 ; \
.popsection
#define ASM_STAC \
661: ASM_NOP3 ; \
.pushsection .altinstr_replacement, "ax" ; \
662: __ASM_STAC ; \
.popsection ; \
.pushsection .altinstructions, "a" ; \
altinstruction_entry 661b, 662b, X86_FEATURE_SMAP, 3, 3 ; \
.popsection
#else /* CONFIG_X86_SMAP */
#define ASM_CLAC
#define ASM_STAC
#endif /* CONFIG_X86_SMAP */
#else /* __ASSEMBLY__ */
#include <asm/alternative.h>
#ifdef CONFIG_X86_SMAP
static __always_inline void clac(void)
{
/* Note: a barrier is implicit in alternative() */
alternative(ASM_NOP3, __stringify(__ASM_CLAC), X86_FEATURE_SMAP);
}
static __always_inline void stac(void)
{
/* Note: a barrier is implicit in alternative() */
alternative(ASM_NOP3, __stringify(__ASM_STAC), X86_FEATURE_SMAP);
}
/* These macros can be used in asm() statements */
#define ASM_CLAC \
ALTERNATIVE(ASM_NOP3, __stringify(__ASM_CLAC), X86_FEATURE_SMAP)
#define ASM_STAC \
ALTERNATIVE(ASM_NOP3, __stringify(__ASM_STAC), X86_FEATURE_SMAP)
#else /* CONFIG_X86_SMAP */
static inline void clac(void) { }
static inline void stac(void) { }
#define ASM_CLAC
#define ASM_STAC
#endif /* CONFIG_X86_SMAP */
#endif /* __ASSEMBLY__ */
#endif /* _ASM_X86_SMAP_H */
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include <linux/string.h> #include <linux/string.h>
#include <asm/asm.h> #include <asm/asm.h>
#include <asm/page.h> #include <asm/page.h>
#include <asm/smap.h>
#define VERIFY_READ 0 #define VERIFY_READ 0
#define VERIFY_WRITE 1 #define VERIFY_WRITE 1
...@@ -192,9 +193,10 @@ extern int __get_user_bad(void); ...@@ -192,9 +193,10 @@ extern int __get_user_bad(void);
#ifdef CONFIG_X86_32 #ifdef CONFIG_X86_32
#define __put_user_asm_u64(x, addr, err, errret) \ #define __put_user_asm_u64(x, addr, err, errret) \
asm volatile("1: movl %%eax,0(%2)\n" \ asm volatile(ASM_STAC "\n" \
"1: movl %%eax,0(%2)\n" \
"2: movl %%edx,4(%2)\n" \ "2: movl %%edx,4(%2)\n" \
"3:\n" \ "3: " ASM_CLAC "\n" \
".section .fixup,\"ax\"\n" \ ".section .fixup,\"ax\"\n" \
"4: movl %3,%0\n" \ "4: movl %3,%0\n" \
" jmp 3b\n" \ " jmp 3b\n" \
...@@ -205,9 +207,10 @@ extern int __get_user_bad(void); ...@@ -205,9 +207,10 @@ extern int __get_user_bad(void);
: "A" (x), "r" (addr), "i" (errret), "0" (err)) : "A" (x), "r" (addr), "i" (errret), "0" (err))
#define __put_user_asm_ex_u64(x, addr) \ #define __put_user_asm_ex_u64(x, addr) \
asm volatile("1: movl %%eax,0(%1)\n" \ asm volatile(ASM_STAC "\n" \
"1: movl %%eax,0(%1)\n" \
"2: movl %%edx,4(%1)\n" \ "2: movl %%edx,4(%1)\n" \
"3:\n" \ "3: " ASM_CLAC "\n" \
_ASM_EXTABLE_EX(1b, 2b) \ _ASM_EXTABLE_EX(1b, 2b) \
_ASM_EXTABLE_EX(2b, 3b) \ _ASM_EXTABLE_EX(2b, 3b) \
: : "A" (x), "r" (addr)) : : "A" (x), "r" (addr))
...@@ -379,8 +382,9 @@ do { \ ...@@ -379,8 +382,9 @@ do { \
} while (0) } while (0)
#define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \ #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
asm volatile("1: mov"itype" %2,%"rtype"1\n" \ asm volatile(ASM_STAC "\n" \
"2:\n" \ "1: mov"itype" %2,%"rtype"1\n" \
"2: " ASM_CLAC "\n" \
".section .fixup,\"ax\"\n" \ ".section .fixup,\"ax\"\n" \
"3: mov %3,%0\n" \ "3: mov %3,%0\n" \
" xor"itype" %"rtype"1,%"rtype"1\n" \ " xor"itype" %"rtype"1,%"rtype"1\n" \
...@@ -443,8 +447,9 @@ struct __large_struct { unsigned long buf[100]; }; ...@@ -443,8 +447,9 @@ struct __large_struct { unsigned long buf[100]; };
* aliasing issues. * aliasing issues.
*/ */
#define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \ #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
asm volatile("1: mov"itype" %"rtype"1,%2\n" \ asm volatile(ASM_STAC "\n" \
"2:\n" \ "1: mov"itype" %"rtype"1,%2\n" \
"2: " ASM_CLAC "\n" \
".section .fixup,\"ax\"\n" \ ".section .fixup,\"ax\"\n" \
"3: mov %3,%0\n" \ "3: mov %3,%0\n" \
" jmp 2b\n" \ " jmp 2b\n" \
...@@ -463,13 +468,13 @@ struct __large_struct { unsigned long buf[100]; }; ...@@ -463,13 +468,13 @@ struct __large_struct { unsigned long buf[100]; };
* uaccess_try and catch * uaccess_try and catch
*/ */
#define uaccess_try do { \ #define uaccess_try do { \
int prev_err = current_thread_info()->uaccess_err; \
current_thread_info()->uaccess_err = 0; \ current_thread_info()->uaccess_err = 0; \
stac(); \
barrier(); barrier();
#define uaccess_catch(err) \ #define uaccess_catch(err) \
clac(); \
(err) |= (current_thread_info()->uaccess_err ? -EFAULT : 0); \ (err) |= (current_thread_info()->uaccess_err ? -EFAULT : 0); \
current_thread_info()->uaccess_err = prev_err; \
} while (0) } while (0)
/** /**
...@@ -569,6 +574,9 @@ strncpy_from_user(char *dst, const char __user *src, long count); ...@@ -569,6 +574,9 @@ strncpy_from_user(char *dst, const char __user *src, long count);
extern __must_check long strlen_user(const char __user *str); extern __must_check long strlen_user(const char __user *str);
extern __must_check long strnlen_user(const char __user *str, long n); extern __must_check long strnlen_user(const char __user *str, long n);
unsigned long __must_check clear_user(void __user *mem, unsigned long len);
unsigned long __must_check __clear_user(void __user *mem, unsigned long len);
/* /*
* movsl can be slow when source and dest are not both 8-byte aligned * movsl can be slow when source and dest are not both 8-byte aligned
*/ */
......
...@@ -213,7 +213,4 @@ static inline unsigned long __must_check copy_from_user(void *to, ...@@ -213,7 +213,4 @@ static inline unsigned long __must_check copy_from_user(void *to,
return n; return n;
} }
unsigned long __must_check clear_user(void __user *mem, unsigned long len);
unsigned long __must_check __clear_user(void __user *mem, unsigned long len);
#endif /* _ASM_X86_UACCESS_32_H */ #endif /* _ASM_X86_UACCESS_32_H */
...@@ -217,9 +217,6 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size) ...@@ -217,9 +217,6 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
} }
} }
__must_check unsigned long clear_user(void __user *mem, unsigned long len);
__must_check unsigned long __clear_user(void __user *mem, unsigned long len);
static __must_check __always_inline int static __must_check __always_inline int
__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size) __copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
{ {
......
...@@ -70,8 +70,9 @@ static inline int xsave_user(struct xsave_struct __user *buf) ...@@ -70,8 +70,9 @@ static inline int xsave_user(struct xsave_struct __user *buf)
if (unlikely(err)) if (unlikely(err))
return -EFAULT; return -EFAULT;
__asm__ __volatile__("1: .byte " REX_PREFIX "0x0f,0xae,0x27\n" __asm__ __volatile__(ASM_STAC "\n"
"2:\n" "1: .byte " REX_PREFIX "0x0f,0xae,0x27\n"
"2: " ASM_CLAC "\n"
".section .fixup,\"ax\"\n" ".section .fixup,\"ax\"\n"
"3: movl $-1,%[err]\n" "3: movl $-1,%[err]\n"
" jmp 2b\n" " jmp 2b\n"
...@@ -90,8 +91,9 @@ static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask) ...@@ -90,8 +91,9 @@ static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
u32 lmask = mask; u32 lmask = mask;
u32 hmask = mask >> 32; u32 hmask = mask >> 32;
__asm__ __volatile__("1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n" __asm__ __volatile__(ASM_STAC "\n"
"2:\n" "1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
"2: " ASM_CLAC "\n"
".section .fixup,\"ax\"\n" ".section .fixup,\"ax\"\n"
"3: movl $-1,%[err]\n" "3: movl $-1,%[err]\n"
" jmp 2b\n" " jmp 2b\n"
......
...@@ -43,17 +43,22 @@ int acpi_suspend_lowlevel(void) ...@@ -43,17 +43,22 @@ int acpi_suspend_lowlevel(void)
header->video_mode = saved_video_mode; header->video_mode = saved_video_mode;
header->pmode_behavior = 0;
#ifndef CONFIG_64BIT #ifndef CONFIG_64BIT
store_gdt((struct desc_ptr *)&header->pmode_gdt); store_gdt((struct desc_ptr *)&header->pmode_gdt);
if (rdmsr_safe(MSR_EFER, &header->pmode_efer_low, if (!rdmsr_safe(MSR_EFER,
&header->pmode_efer_high)) &header->pmode_efer_low,
header->pmode_efer_low = header->pmode_efer_high = 0; &header->pmode_efer_high))
header->pmode_behavior |= (1 << WAKEUP_BEHAVIOR_RESTORE_EFER);
#endif /* !CONFIG_64BIT */ #endif /* !CONFIG_64BIT */
header->pmode_cr0 = read_cr0(); header->pmode_cr0 = read_cr0();
header->pmode_cr4 = read_cr4_safe(); if (__this_cpu_read(cpu_info.cpuid_level) >= 0) {
header->pmode_behavior = 0; header->pmode_cr4 = read_cr4();
header->pmode_behavior |= (1 << WAKEUP_BEHAVIOR_RESTORE_CR4);
}
if (!rdmsr_safe(MSR_IA32_MISC_ENABLE, if (!rdmsr_safe(MSR_IA32_MISC_ENABLE,
&header->pmode_misc_en_low, &header->pmode_misc_en_low,
&header->pmode_misc_en_high)) &header->pmode_misc_en_high))
......
...@@ -259,23 +259,36 @@ static inline void squash_the_stupid_serial_number(struct cpuinfo_x86 *c) ...@@ -259,23 +259,36 @@ static inline void squash_the_stupid_serial_number(struct cpuinfo_x86 *c)
} }
#endif #endif
static int disable_smep __cpuinitdata;
static __init int setup_disable_smep(char *arg) static __init int setup_disable_smep(char *arg)
{ {
disable_smep = 1; setup_clear_cpu_cap(X86_FEATURE_SMEP);
return 1; return 1;
} }
__setup("nosmep", setup_disable_smep); __setup("nosmep", setup_disable_smep);
static __cpuinit void setup_smep(struct cpuinfo_x86 *c) static __always_inline void setup_smep(struct cpuinfo_x86 *c)
{ {
if (cpu_has(c, X86_FEATURE_SMEP)) { if (cpu_has(c, X86_FEATURE_SMEP))
if (unlikely(disable_smep)) { set_in_cr4(X86_CR4_SMEP);
setup_clear_cpu_cap(X86_FEATURE_SMEP); }
clear_in_cr4(X86_CR4_SMEP);
} else static __init int setup_disable_smap(char *arg)
set_in_cr4(X86_CR4_SMEP); {
} setup_clear_cpu_cap(X86_FEATURE_SMAP);
return 1;
}
__setup("nosmap", setup_disable_smap);
static __always_inline void setup_smap(struct cpuinfo_x86 *c)
{
unsigned long eflags;
/* This should have been cleared long ago */
raw_local_save_flags(eflags);
BUG_ON(eflags & X86_EFLAGS_AC);
if (cpu_has(c, X86_FEATURE_SMAP))
set_in_cr4(X86_CR4_SMAP);
} }
/* /*
...@@ -712,8 +725,6 @@ static void __init early_identify_cpu(struct cpuinfo_x86 *c) ...@@ -712,8 +725,6 @@ static void __init early_identify_cpu(struct cpuinfo_x86 *c)
c->cpu_index = 0; c->cpu_index = 0;
filter_cpuid_features(c, false); filter_cpuid_features(c, false);
setup_smep(c);
if (this_cpu->c_bsp_init) if (this_cpu->c_bsp_init)
this_cpu->c_bsp_init(c); this_cpu->c_bsp_init(c);
} }
...@@ -798,8 +809,6 @@ static void __cpuinit generic_identify(struct cpuinfo_x86 *c) ...@@ -798,8 +809,6 @@ static void __cpuinit generic_identify(struct cpuinfo_x86 *c)
c->phys_proc_id = c->initial_apicid; c->phys_proc_id = c->initial_apicid;
} }
setup_smep(c);
get_model_name(c); /* Default name */ get_model_name(c); /* Default name */
detect_nopl(c); detect_nopl(c);
...@@ -864,6 +873,10 @@ static void __cpuinit identify_cpu(struct cpuinfo_x86 *c) ...@@ -864,6 +873,10 @@ static void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
/* Disable the PN if appropriate */ /* Disable the PN if appropriate */
squash_the_stupid_serial_number(c); squash_the_stupid_serial_number(c);
/* Set up SMEP/SMAP */
setup_smep(c);
setup_smap(c);
/* /*
* The vendor-specific functions might have changed features. * The vendor-specific functions might have changed features.
* Now we do "generic changes." * Now we do "generic changes."
...@@ -1114,7 +1127,8 @@ void syscall_init(void) ...@@ -1114,7 +1127,8 @@ void syscall_init(void)
/* Flags to clear on syscall */ /* Flags to clear on syscall */
wrmsrl(MSR_SYSCALL_MASK, wrmsrl(MSR_SYSCALL_MASK,
X86_EFLAGS_TF|X86_EFLAGS_DF|X86_EFLAGS_IF|X86_EFLAGS_IOPL); X86_EFLAGS_TF|X86_EFLAGS_DF|X86_EFLAGS_IF|
X86_EFLAGS_IOPL|X86_EFLAGS_AC);
} }
/* /*
......
...@@ -57,6 +57,7 @@ ...@@ -57,6 +57,7 @@
#include <asm/cpufeature.h> #include <asm/cpufeature.h>
#include <asm/alternative-asm.h> #include <asm/alternative-asm.h>
#include <asm/asm.h> #include <asm/asm.h>
#include <asm/smap.h>
/* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */ /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
#include <linux/elf-em.h> #include <linux/elf-em.h>
...@@ -407,7 +408,9 @@ sysenter_past_esp: ...@@ -407,7 +408,9 @@ sysenter_past_esp:
*/ */
cmpl $__PAGE_OFFSET-3,%ebp cmpl $__PAGE_OFFSET-3,%ebp
jae syscall_fault jae syscall_fault
ASM_STAC
1: movl (%ebp),%ebp 1: movl (%ebp),%ebp
ASM_CLAC
movl %ebp,PT_EBP(%esp) movl %ebp,PT_EBP(%esp)
_ASM_EXTABLE(1b,syscall_fault) _ASM_EXTABLE(1b,syscall_fault)
...@@ -488,6 +491,7 @@ ENDPROC(ia32_sysenter_target) ...@@ -488,6 +491,7 @@ ENDPROC(ia32_sysenter_target)
# system call handler stub # system call handler stub
ENTRY(system_call) ENTRY(system_call)
RING0_INT_FRAME # can't unwind into user space anyway RING0_INT_FRAME # can't unwind into user space anyway
ASM_CLAC
pushl_cfi %eax # save orig_eax pushl_cfi %eax # save orig_eax
SAVE_ALL SAVE_ALL
GET_THREAD_INFO(%ebp) GET_THREAD_INFO(%ebp)
...@@ -670,6 +674,7 @@ END(syscall_exit_work) ...@@ -670,6 +674,7 @@ END(syscall_exit_work)
RING0_INT_FRAME # can't unwind into user space anyway RING0_INT_FRAME # can't unwind into user space anyway
syscall_fault: syscall_fault:
ASM_CLAC
GET_THREAD_INFO(%ebp) GET_THREAD_INFO(%ebp)
movl $-EFAULT,PT_EAX(%esp) movl $-EFAULT,PT_EAX(%esp)
jmp resume_userspace jmp resume_userspace
...@@ -825,6 +830,7 @@ END(interrupt) ...@@ -825,6 +830,7 @@ END(interrupt)
*/ */
.p2align CONFIG_X86_L1_CACHE_SHIFT .p2align CONFIG_X86_L1_CACHE_SHIFT
common_interrupt: common_interrupt:
ASM_CLAC
addl $-0x80,(%esp) /* Adjust vector into the [-256,-1] range */ addl $-0x80,(%esp) /* Adjust vector into the [-256,-1] range */
SAVE_ALL SAVE_ALL
TRACE_IRQS_OFF TRACE_IRQS_OFF
...@@ -841,6 +847,7 @@ ENDPROC(common_interrupt) ...@@ -841,6 +847,7 @@ ENDPROC(common_interrupt)
#define BUILD_INTERRUPT3(name, nr, fn) \ #define BUILD_INTERRUPT3(name, nr, fn) \
ENTRY(name) \ ENTRY(name) \
RING0_INT_FRAME; \ RING0_INT_FRAME; \
ASM_CLAC; \
pushl_cfi $~(nr); \ pushl_cfi $~(nr); \
SAVE_ALL; \ SAVE_ALL; \
TRACE_IRQS_OFF \ TRACE_IRQS_OFF \
...@@ -857,6 +864,7 @@ ENDPROC(name) ...@@ -857,6 +864,7 @@ ENDPROC(name)
ENTRY(coprocessor_error) ENTRY(coprocessor_error)
RING0_INT_FRAME RING0_INT_FRAME
ASM_CLAC
pushl_cfi $0 pushl_cfi $0
pushl_cfi $do_coprocessor_error pushl_cfi $do_coprocessor_error
jmp error_code jmp error_code
...@@ -865,6 +873,7 @@ END(coprocessor_error) ...@@ -865,6 +873,7 @@ END(coprocessor_error)
ENTRY(simd_coprocessor_error) ENTRY(simd_coprocessor_error)
RING0_INT_FRAME RING0_INT_FRAME
ASM_CLAC
pushl_cfi $0 pushl_cfi $0
#ifdef CONFIG_X86_INVD_BUG #ifdef CONFIG_X86_INVD_BUG
/* AMD 486 bug: invd from userspace calls exception 19 instead of #GP */ /* AMD 486 bug: invd from userspace calls exception 19 instead of #GP */
...@@ -886,6 +895,7 @@ END(simd_coprocessor_error) ...@@ -886,6 +895,7 @@ END(simd_coprocessor_error)
ENTRY(device_not_available) ENTRY(device_not_available)
RING0_INT_FRAME RING0_INT_FRAME
ASM_CLAC
pushl_cfi $-1 # mark this as an int pushl_cfi $-1 # mark this as an int
pushl_cfi $do_device_not_available pushl_cfi $do_device_not_available
jmp error_code jmp error_code
...@@ -906,6 +916,7 @@ END(native_irq_enable_sysexit) ...@@ -906,6 +916,7 @@ END(native_irq_enable_sysexit)
ENTRY(overflow) ENTRY(overflow)
RING0_INT_FRAME RING0_INT_FRAME
ASM_CLAC
pushl_cfi $0 pushl_cfi $0
pushl_cfi $do_overflow pushl_cfi $do_overflow
jmp error_code jmp error_code
...@@ -914,6 +925,7 @@ END(overflow) ...@@ -914,6 +925,7 @@ END(overflow)
ENTRY(bounds) ENTRY(bounds)
RING0_INT_FRAME RING0_INT_FRAME
ASM_CLAC
pushl_cfi $0 pushl_cfi $0
pushl_cfi $do_bounds pushl_cfi $do_bounds
jmp error_code jmp error_code
...@@ -922,6 +934,7 @@ END(bounds) ...@@ -922,6 +934,7 @@ END(bounds)
ENTRY(invalid_op) ENTRY(invalid_op)
RING0_INT_FRAME RING0_INT_FRAME
ASM_CLAC
pushl_cfi $0 pushl_cfi $0
pushl_cfi $do_invalid_op pushl_cfi $do_invalid_op
jmp error_code jmp error_code
...@@ -930,6 +943,7 @@ END(invalid_op) ...@@ -930,6 +943,7 @@ END(invalid_op)
ENTRY(coprocessor_segment_overrun) ENTRY(coprocessor_segment_overrun)
RING0_INT_FRAME RING0_INT_FRAME
ASM_CLAC
pushl_cfi $0 pushl_cfi $0
pushl_cfi $do_coprocessor_segment_overrun pushl_cfi $do_coprocessor_segment_overrun
jmp error_code jmp error_code
...@@ -938,6 +952,7 @@ END(coprocessor_segment_overrun) ...@@ -938,6 +952,7 @@ END(coprocessor_segment_overrun)
ENTRY(invalid_TSS) ENTRY(invalid_TSS)
RING0_EC_FRAME RING0_EC_FRAME
ASM_CLAC
pushl_cfi $do_invalid_TSS pushl_cfi $do_invalid_TSS
jmp error_code jmp error_code
CFI_ENDPROC CFI_ENDPROC
...@@ -945,6 +960,7 @@ END(invalid_TSS) ...@@ -945,6 +960,7 @@ END(invalid_TSS)
ENTRY(segment_not_present) ENTRY(segment_not_present)
RING0_EC_FRAME RING0_EC_FRAME
ASM_CLAC
pushl_cfi $do_segment_not_present pushl_cfi $do_segment_not_present
jmp error_code jmp error_code
CFI_ENDPROC CFI_ENDPROC
...@@ -952,6 +968,7 @@ END(segment_not_present) ...@@ -952,6 +968,7 @@ END(segment_not_present)
ENTRY(stack_segment) ENTRY(stack_segment)
RING0_EC_FRAME RING0_EC_FRAME
ASM_CLAC
pushl_cfi $do_stack_segment pushl_cfi $do_stack_segment
jmp error_code jmp error_code
CFI_ENDPROC CFI_ENDPROC
...@@ -959,6 +976,7 @@ END(stack_segment) ...@@ -959,6 +976,7 @@ END(stack_segment)
ENTRY(alignment_check) ENTRY(alignment_check)
RING0_EC_FRAME RING0_EC_FRAME
ASM_CLAC
pushl_cfi $do_alignment_check pushl_cfi $do_alignment_check
jmp error_code jmp error_code
CFI_ENDPROC CFI_ENDPROC
...@@ -966,6 +984,7 @@ END(alignment_check) ...@@ -966,6 +984,7 @@ END(alignment_check)
ENTRY(divide_error) ENTRY(divide_error)
RING0_INT_FRAME RING0_INT_FRAME
ASM_CLAC
pushl_cfi $0 # no error code pushl_cfi $0 # no error code
pushl_cfi $do_divide_error pushl_cfi $do_divide_error
jmp error_code jmp error_code
...@@ -975,6 +994,7 @@ END(divide_error) ...@@ -975,6 +994,7 @@ END(divide_error)
#ifdef CONFIG_X86_MCE #ifdef CONFIG_X86_MCE
ENTRY(machine_check) ENTRY(machine_check)
RING0_INT_FRAME RING0_INT_FRAME
ASM_CLAC
pushl_cfi $0 pushl_cfi $0
pushl_cfi machine_check_vector pushl_cfi machine_check_vector
jmp error_code jmp error_code
...@@ -984,6 +1004,7 @@ END(machine_check) ...@@ -984,6 +1004,7 @@ END(machine_check)
ENTRY(spurious_interrupt_bug) ENTRY(spurious_interrupt_bug)
RING0_INT_FRAME RING0_INT_FRAME
ASM_CLAC
pushl_cfi $0 pushl_cfi $0
pushl_cfi $do_spurious_interrupt_bug pushl_cfi $do_spurious_interrupt_bug
jmp error_code jmp error_code
...@@ -1273,6 +1294,7 @@ return_to_handler: ...@@ -1273,6 +1294,7 @@ return_to_handler:
ENTRY(page_fault) ENTRY(page_fault)
RING0_EC_FRAME RING0_EC_FRAME
ASM_CLAC
pushl_cfi $do_page_fault pushl_cfi $do_page_fault
ALIGN ALIGN
error_code: error_code:
...@@ -1345,6 +1367,7 @@ END(page_fault) ...@@ -1345,6 +1367,7 @@ END(page_fault)
ENTRY(debug) ENTRY(debug)
RING0_INT_FRAME RING0_INT_FRAME
ASM_CLAC
cmpl $ia32_sysenter_target,(%esp) cmpl $ia32_sysenter_target,(%esp)
jne debug_stack_correct jne debug_stack_correct
FIX_STACK 12, debug_stack_correct, debug_esp_fix_insn FIX_STACK 12, debug_stack_correct, debug_esp_fix_insn
...@@ -1369,6 +1392,7 @@ END(debug) ...@@ -1369,6 +1392,7 @@ END(debug)
*/ */
ENTRY(nmi) ENTRY(nmi)
RING0_INT_FRAME RING0_INT_FRAME
ASM_CLAC
pushl_cfi %eax pushl_cfi %eax
movl %ss, %eax movl %ss, %eax
cmpw $__ESPFIX_SS, %ax cmpw $__ESPFIX_SS, %ax
...@@ -1439,6 +1463,7 @@ END(nmi) ...@@ -1439,6 +1463,7 @@ END(nmi)
ENTRY(int3) ENTRY(int3)
RING0_INT_FRAME RING0_INT_FRAME
ASM_CLAC
pushl_cfi $-1 # mark this as an int pushl_cfi $-1 # mark this as an int
SAVE_ALL SAVE_ALL
TRACE_IRQS_OFF TRACE_IRQS_OFF
...@@ -1459,6 +1484,7 @@ END(general_protection) ...@@ -1459,6 +1484,7 @@ END(general_protection)
#ifdef CONFIG_KVM_GUEST #ifdef CONFIG_KVM_GUEST
ENTRY(async_page_fault) ENTRY(async_page_fault)
RING0_EC_FRAME RING0_EC_FRAME
ASM_CLAC
pushl_cfi $do_async_page_fault pushl_cfi $do_async_page_fault
jmp error_code jmp error_code
CFI_ENDPROC CFI_ENDPROC
......
...@@ -57,6 +57,7 @@ ...@@ -57,6 +57,7 @@
#include <asm/percpu.h> #include <asm/percpu.h>
#include <asm/asm.h> #include <asm/asm.h>
#include <asm/rcu.h> #include <asm/rcu.h>
#include <asm/smap.h>
#include <linux/err.h> #include <linux/err.h>
/* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */ /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
...@@ -568,7 +569,8 @@ END(ret_from_fork) ...@@ -568,7 +569,8 @@ END(ret_from_fork)
* System call entry. Up to 6 arguments in registers are supported. * System call entry. Up to 6 arguments in registers are supported.
* *
* SYSCALL does not save anything on the stack and does not change the * SYSCALL does not save anything on the stack and does not change the
* stack pointer. * stack pointer. However, it does mask the flags register for us, so
* CLD and CLAC are not needed.
*/ */
/* /*
...@@ -987,6 +989,7 @@ END(interrupt) ...@@ -987,6 +989,7 @@ END(interrupt)
*/ */
.p2align CONFIG_X86_L1_CACHE_SHIFT .p2align CONFIG_X86_L1_CACHE_SHIFT
common_interrupt: common_interrupt:
ASM_CLAC
XCPT_FRAME XCPT_FRAME
addq $-0x80,(%rsp) /* Adjust vector to [-256,-1] range */ addq $-0x80,(%rsp) /* Adjust vector to [-256,-1] range */
interrupt do_IRQ interrupt do_IRQ
...@@ -1126,6 +1129,7 @@ END(common_interrupt) ...@@ -1126,6 +1129,7 @@ END(common_interrupt)
*/ */
.macro apicinterrupt num sym do_sym .macro apicinterrupt num sym do_sym
ENTRY(\sym) ENTRY(\sym)
ASM_CLAC
INTR_FRAME INTR_FRAME
pushq_cfi $~(\num) pushq_cfi $~(\num)
.Lcommon_\sym: .Lcommon_\sym:
...@@ -1180,6 +1184,7 @@ apicinterrupt IRQ_WORK_VECTOR \ ...@@ -1180,6 +1184,7 @@ apicinterrupt IRQ_WORK_VECTOR \
*/ */
.macro zeroentry sym do_sym .macro zeroentry sym do_sym
ENTRY(\sym) ENTRY(\sym)
ASM_CLAC
INTR_FRAME INTR_FRAME
PARAVIRT_ADJUST_EXCEPTION_FRAME PARAVIRT_ADJUST_EXCEPTION_FRAME
pushq_cfi $-1 /* ORIG_RAX: no syscall to restart */ pushq_cfi $-1 /* ORIG_RAX: no syscall to restart */
...@@ -1197,6 +1202,7 @@ END(\sym) ...@@ -1197,6 +1202,7 @@ END(\sym)
.macro paranoidzeroentry sym do_sym .macro paranoidzeroentry sym do_sym
ENTRY(\sym) ENTRY(\sym)
ASM_CLAC
INTR_FRAME INTR_FRAME
PARAVIRT_ADJUST_EXCEPTION_FRAME PARAVIRT_ADJUST_EXCEPTION_FRAME
pushq_cfi $-1 /* ORIG_RAX: no syscall to restart */ pushq_cfi $-1 /* ORIG_RAX: no syscall to restart */
...@@ -1215,6 +1221,7 @@ END(\sym) ...@@ -1215,6 +1221,7 @@ END(\sym)
#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8) #define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
.macro paranoidzeroentry_ist sym do_sym ist .macro paranoidzeroentry_ist sym do_sym ist
ENTRY(\sym) ENTRY(\sym)
ASM_CLAC
INTR_FRAME INTR_FRAME
PARAVIRT_ADJUST_EXCEPTION_FRAME PARAVIRT_ADJUST_EXCEPTION_FRAME
pushq_cfi $-1 /* ORIG_RAX: no syscall to restart */ pushq_cfi $-1 /* ORIG_RAX: no syscall to restart */
...@@ -1234,6 +1241,7 @@ END(\sym) ...@@ -1234,6 +1241,7 @@ END(\sym)
.macro errorentry sym do_sym .macro errorentry sym do_sym
ENTRY(\sym) ENTRY(\sym)
ASM_CLAC
XCPT_FRAME XCPT_FRAME
PARAVIRT_ADJUST_EXCEPTION_FRAME PARAVIRT_ADJUST_EXCEPTION_FRAME
subq $ORIG_RAX-R15, %rsp subq $ORIG_RAX-R15, %rsp
...@@ -1252,6 +1260,7 @@ END(\sym) ...@@ -1252,6 +1260,7 @@ END(\sym)
/* error code is on the stack already */ /* error code is on the stack already */
.macro paranoiderrorentry sym do_sym .macro paranoiderrorentry sym do_sym
ENTRY(\sym) ENTRY(\sym)
ASM_CLAC
XCPT_FRAME XCPT_FRAME
PARAVIRT_ADJUST_EXCEPTION_FRAME PARAVIRT_ADJUST_EXCEPTION_FRAME
subq $ORIG_RAX-R15, %rsp subq $ORIG_RAX-R15, %rsp
......
...@@ -287,27 +287,28 @@ ENTRY(startup_32_smp) ...@@ -287,27 +287,28 @@ ENTRY(startup_32_smp)
leal -__PAGE_OFFSET(%ecx),%esp leal -__PAGE_OFFSET(%ecx),%esp
default_entry: default_entry:
/* /*
* New page tables may be in 4Mbyte page mode and may * New page tables may be in 4Mbyte page mode and may
* be using the global pages. * be using the global pages.
* *
* NOTE! If we are on a 486 we may have no cr4 at all! * NOTE! If we are on a 486 we may have no cr4 at all!
* So we do not try to touch it unless we really have * Specifically, cr4 exists if and only if CPUID exists,
* some bits in it to set. This won't work if the BSP * which in turn exists if and only if EFLAGS.ID exists.
* implements cr4 but this AP does not -- very unlikely
* but be warned! The same applies to the pse feature
* if not equally supported. --macro
*
* NOTE! We have to correct for the fact that we're
* not yet offset PAGE_OFFSET..
*/ */
#define cr4_bits pa(mmu_cr4_features) movl $X86_EFLAGS_ID,%ecx
movl cr4_bits,%edx pushl %ecx
andl %edx,%edx popfl
jz 6f pushfl
movl %cr4,%eax # Turn on paging options (PSE,PAE,..) popl %eax
orl %edx,%eax pushl $0
popfl
pushfl
popl %edx
xorl %edx,%eax
testl %ecx,%eax
jz 6f # No ID flag = no CPUID = no CR4
movl pa(mmu_cr4_features),%eax
movl %eax,%cr4 movl %eax,%cr4
testb $X86_CR4_PAE, %al # check if PAE is enabled testb $X86_CR4_PAE, %al # check if PAE is enabled
......
...@@ -114,11 +114,12 @@ int restore_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc, ...@@ -114,11 +114,12 @@ int restore_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc,
regs->orig_ax = -1; /* disable syscall checks */ regs->orig_ax = -1; /* disable syscall checks */
get_user_ex(buf, &sc->fpstate); get_user_ex(buf, &sc->fpstate);
err |= restore_xstate_sig(buf, config_enabled(CONFIG_X86_32));
get_user_ex(*pax, &sc->ax); get_user_ex(*pax, &sc->ax);
} get_user_catch(err); } get_user_catch(err);
err |= restore_xstate_sig(buf, config_enabled(CONFIG_X86_32));
return err; return err;
} }
...@@ -355,7 +356,6 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info, ...@@ -355,7 +356,6 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
put_user_ex(sig, &frame->sig); put_user_ex(sig, &frame->sig);
put_user_ex(&frame->info, &frame->pinfo); put_user_ex(&frame->info, &frame->pinfo);
put_user_ex(&frame->uc, &frame->puc); put_user_ex(&frame->uc, &frame->puc);
err |= copy_siginfo_to_user(&frame->info, info);
/* Create the ucontext. */ /* Create the ucontext. */
if (cpu_has_xsave) if (cpu_has_xsave)
...@@ -367,9 +367,6 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info, ...@@ -367,9 +367,6 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
put_user_ex(sas_ss_flags(regs->sp), put_user_ex(sas_ss_flags(regs->sp),
&frame->uc.uc_stack.ss_flags); &frame->uc.uc_stack.ss_flags);
put_user_ex(current->sas_ss_size, &frame->uc.uc_stack.ss_size); put_user_ex(current->sas_ss_size, &frame->uc.uc_stack.ss_size);
err |= setup_sigcontext(&frame->uc.uc_mcontext, fpstate,
regs, set->sig[0]);
err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
/* Set up to return from userspace. */ /* Set up to return from userspace. */
restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn); restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
...@@ -386,6 +383,11 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info, ...@@ -386,6 +383,11 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
*/ */
put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode); put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
} put_user_catch(err); } put_user_catch(err);
err |= copy_siginfo_to_user(&frame->info, info);
err |= setup_sigcontext(&frame->uc.uc_mcontext, fpstate,
regs, set->sig[0]);
err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
if (err) if (err)
return -EFAULT; return -EFAULT;
...@@ -434,8 +436,6 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info, ...@@ -434,8 +436,6 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
put_user_ex(sas_ss_flags(regs->sp), put_user_ex(sas_ss_flags(regs->sp),
&frame->uc.uc_stack.ss_flags); &frame->uc.uc_stack.ss_flags);
put_user_ex(me->sas_ss_size, &frame->uc.uc_stack.ss_size); put_user_ex(me->sas_ss_size, &frame->uc.uc_stack.ss_size);
err |= setup_sigcontext(&frame->uc.uc_mcontext, fp, regs, set->sig[0]);
err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
/* Set up to return from userspace. If provided, use a stub /* Set up to return from userspace. If provided, use a stub
already in userspace. */ already in userspace. */
...@@ -448,6 +448,9 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info, ...@@ -448,6 +448,9 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
} }
} put_user_catch(err); } put_user_catch(err);
err |= setup_sigcontext(&frame->uc.uc_mcontext, fp, regs, set->sig[0]);
err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
if (err) if (err)
return -EFAULT; return -EFAULT;
...@@ -504,9 +507,6 @@ static int x32_setup_rt_frame(int sig, struct k_sigaction *ka, ...@@ -504,9 +507,6 @@ static int x32_setup_rt_frame(int sig, struct k_sigaction *ka,
&frame->uc.uc_stack.ss_flags); &frame->uc.uc_stack.ss_flags);
put_user_ex(current->sas_ss_size, &frame->uc.uc_stack.ss_size); put_user_ex(current->sas_ss_size, &frame->uc.uc_stack.ss_size);
put_user_ex(0, &frame->uc.uc__pad0); put_user_ex(0, &frame->uc.uc__pad0);
err |= setup_sigcontext(&frame->uc.uc_mcontext, fpstate,
regs, set->sig[0]);
err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
if (ka->sa.sa_flags & SA_RESTORER) { if (ka->sa.sa_flags & SA_RESTORER) {
restorer = ka->sa.sa_restorer; restorer = ka->sa.sa_restorer;
...@@ -518,6 +518,10 @@ static int x32_setup_rt_frame(int sig, struct k_sigaction *ka, ...@@ -518,6 +518,10 @@ static int x32_setup_rt_frame(int sig, struct k_sigaction *ka,
put_user_ex(restorer, &frame->pretcode); put_user_ex(restorer, &frame->pretcode);
} put_user_catch(err); } put_user_catch(err);
err |= setup_sigcontext(&frame->uc.uc_mcontext, fpstate,
regs, set->sig[0]);
err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
if (err) if (err)
return -EFAULT; return -EFAULT;
......
...@@ -315,7 +315,7 @@ static inline int restore_user_xstate(void __user *buf, u64 xbv, int fx_only) ...@@ -315,7 +315,7 @@ static inline int restore_user_xstate(void __user *buf, u64 xbv, int fx_only)
if ((unsigned long)buf % 64 || fx_only) { if ((unsigned long)buf % 64 || fx_only) {
u64 init_bv = pcntxt_mask & ~XSTATE_FPSSE; u64 init_bv = pcntxt_mask & ~XSTATE_FPSSE;
xrstor_state(init_xstate_buf, init_bv); xrstor_state(init_xstate_buf, init_bv);
return fxrstor_checking((__force void *) buf); return fxrstor_user(buf);
} else { } else {
u64 init_bv = pcntxt_mask & ~xbv; u64 init_bv = pcntxt_mask & ~xbv;
if (unlikely(init_bv)) if (unlikely(init_bv))
...@@ -323,9 +323,9 @@ static inline int restore_user_xstate(void __user *buf, u64 xbv, int fx_only) ...@@ -323,9 +323,9 @@ static inline int restore_user_xstate(void __user *buf, u64 xbv, int fx_only)
return xrestore_user(buf, xbv); return xrestore_user(buf, xbv);
} }
} else if (use_fxsr()) { } else if (use_fxsr()) {
return fxrstor_checking((__force void *) buf); return fxrstor_user(buf);
} else } else
return frstor_checking((__force void *) buf); return frstor_user(buf);
} }
int __restore_xstate_sig(void __user *buf, void __user *buf_fx, int size) int __restore_xstate_sig(void __user *buf, void __user *buf_fx, int size)
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include <asm/cpufeature.h> #include <asm/cpufeature.h>
#include <asm/alternative-asm.h> #include <asm/alternative-asm.h>
#include <asm/asm.h> #include <asm/asm.h>
#include <asm/smap.h>
/* /*
* By placing feature2 after feature1 in altinstructions section, we logically * By placing feature2 after feature1 in altinstructions section, we logically
...@@ -130,6 +131,7 @@ ENDPROC(bad_from_user) ...@@ -130,6 +131,7 @@ ENDPROC(bad_from_user)
*/ */
ENTRY(copy_user_generic_unrolled) ENTRY(copy_user_generic_unrolled)
CFI_STARTPROC CFI_STARTPROC
ASM_STAC
cmpl $8,%edx cmpl $8,%edx
jb 20f /* less then 8 bytes, go to byte copy loop */ jb 20f /* less then 8 bytes, go to byte copy loop */
ALIGN_DESTINATION ALIGN_DESTINATION
...@@ -177,6 +179,7 @@ ENTRY(copy_user_generic_unrolled) ...@@ -177,6 +179,7 @@ ENTRY(copy_user_generic_unrolled)
decl %ecx decl %ecx
jnz 21b jnz 21b
23: xor %eax,%eax 23: xor %eax,%eax
ASM_CLAC
ret ret
.section .fixup,"ax" .section .fixup,"ax"
...@@ -232,6 +235,7 @@ ENDPROC(copy_user_generic_unrolled) ...@@ -232,6 +235,7 @@ ENDPROC(copy_user_generic_unrolled)
*/ */
ENTRY(copy_user_generic_string) ENTRY(copy_user_generic_string)
CFI_STARTPROC CFI_STARTPROC
ASM_STAC
andl %edx,%edx andl %edx,%edx
jz 4f jz 4f
cmpl $8,%edx cmpl $8,%edx
...@@ -246,6 +250,7 @@ ENTRY(copy_user_generic_string) ...@@ -246,6 +250,7 @@ ENTRY(copy_user_generic_string)
3: rep 3: rep
movsb movsb
4: xorl %eax,%eax 4: xorl %eax,%eax
ASM_CLAC
ret ret
.section .fixup,"ax" .section .fixup,"ax"
...@@ -273,12 +278,14 @@ ENDPROC(copy_user_generic_string) ...@@ -273,12 +278,14 @@ ENDPROC(copy_user_generic_string)
*/ */
ENTRY(copy_user_enhanced_fast_string) ENTRY(copy_user_enhanced_fast_string)
CFI_STARTPROC CFI_STARTPROC
ASM_STAC
andl %edx,%edx andl %edx,%edx
jz 2f jz 2f
movl %edx,%ecx movl %edx,%ecx
1: rep 1: rep
movsb movsb
2: xorl %eax,%eax 2: xorl %eax,%eax
ASM_CLAC
ret ret
.section .fixup,"ax" .section .fixup,"ax"
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include <asm/asm-offsets.h> #include <asm/asm-offsets.h>
#include <asm/thread_info.h> #include <asm/thread_info.h>
#include <asm/asm.h> #include <asm/asm.h>
#include <asm/smap.h>
.macro ALIGN_DESTINATION .macro ALIGN_DESTINATION
#ifdef FIX_ALIGNMENT #ifdef FIX_ALIGNMENT
...@@ -48,6 +49,7 @@ ...@@ -48,6 +49,7 @@
*/ */
ENTRY(__copy_user_nocache) ENTRY(__copy_user_nocache)
CFI_STARTPROC CFI_STARTPROC
ASM_STAC
cmpl $8,%edx cmpl $8,%edx
jb 20f /* less then 8 bytes, go to byte copy loop */ jb 20f /* less then 8 bytes, go to byte copy loop */
ALIGN_DESTINATION ALIGN_DESTINATION
...@@ -95,6 +97,7 @@ ENTRY(__copy_user_nocache) ...@@ -95,6 +97,7 @@ ENTRY(__copy_user_nocache)
decl %ecx decl %ecx
jnz 21b jnz 21b
23: xorl %eax,%eax 23: xorl %eax,%eax
ASM_CLAC
sfence sfence
ret ret
......
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#include <asm/asm-offsets.h> #include <asm/asm-offsets.h>
#include <asm/thread_info.h> #include <asm/thread_info.h>
#include <asm/asm.h> #include <asm/asm.h>
#include <asm/smap.h>
.text .text
ENTRY(__get_user_1) ENTRY(__get_user_1)
...@@ -40,8 +41,10 @@ ENTRY(__get_user_1) ...@@ -40,8 +41,10 @@ ENTRY(__get_user_1)
GET_THREAD_INFO(%_ASM_DX) GET_THREAD_INFO(%_ASM_DX)
cmp TI_addr_limit(%_ASM_DX),%_ASM_AX cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
jae bad_get_user jae bad_get_user
ASM_STAC
1: movzb (%_ASM_AX),%edx 1: movzb (%_ASM_AX),%edx
xor %eax,%eax xor %eax,%eax
ASM_CLAC
ret ret
CFI_ENDPROC CFI_ENDPROC
ENDPROC(__get_user_1) ENDPROC(__get_user_1)
...@@ -53,8 +56,10 @@ ENTRY(__get_user_2) ...@@ -53,8 +56,10 @@ ENTRY(__get_user_2)
GET_THREAD_INFO(%_ASM_DX) GET_THREAD_INFO(%_ASM_DX)
cmp TI_addr_limit(%_ASM_DX),%_ASM_AX cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
jae bad_get_user jae bad_get_user
ASM_STAC
2: movzwl -1(%_ASM_AX),%edx 2: movzwl -1(%_ASM_AX),%edx
xor %eax,%eax xor %eax,%eax
ASM_CLAC
ret ret
CFI_ENDPROC CFI_ENDPROC
ENDPROC(__get_user_2) ENDPROC(__get_user_2)
...@@ -66,8 +71,10 @@ ENTRY(__get_user_4) ...@@ -66,8 +71,10 @@ ENTRY(__get_user_4)
GET_THREAD_INFO(%_ASM_DX) GET_THREAD_INFO(%_ASM_DX)
cmp TI_addr_limit(%_ASM_DX),%_ASM_AX cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
jae bad_get_user jae bad_get_user
ASM_STAC
3: mov -3(%_ASM_AX),%edx 3: mov -3(%_ASM_AX),%edx
xor %eax,%eax xor %eax,%eax
ASM_CLAC
ret ret
CFI_ENDPROC CFI_ENDPROC
ENDPROC(__get_user_4) ENDPROC(__get_user_4)
...@@ -80,8 +87,10 @@ ENTRY(__get_user_8) ...@@ -80,8 +87,10 @@ ENTRY(__get_user_8)
GET_THREAD_INFO(%_ASM_DX) GET_THREAD_INFO(%_ASM_DX)
cmp TI_addr_limit(%_ASM_DX),%_ASM_AX cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
jae bad_get_user jae bad_get_user
ASM_STAC
4: movq -7(%_ASM_AX),%_ASM_DX 4: movq -7(%_ASM_AX),%_ASM_DX
xor %eax,%eax xor %eax,%eax
ASM_CLAC
ret ret
CFI_ENDPROC CFI_ENDPROC
ENDPROC(__get_user_8) ENDPROC(__get_user_8)
...@@ -91,6 +100,7 @@ bad_get_user: ...@@ -91,6 +100,7 @@ bad_get_user:
CFI_STARTPROC CFI_STARTPROC
xor %edx,%edx xor %edx,%edx
mov $(-EFAULT),%_ASM_AX mov $(-EFAULT),%_ASM_AX
ASM_CLAC
ret ret
CFI_ENDPROC CFI_ENDPROC
END(bad_get_user) END(bad_get_user)
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include <asm/thread_info.h> #include <asm/thread_info.h>
#include <asm/errno.h> #include <asm/errno.h>
#include <asm/asm.h> #include <asm/asm.h>
#include <asm/smap.h>
/* /*
...@@ -31,7 +32,8 @@ ...@@ -31,7 +32,8 @@
#define ENTER CFI_STARTPROC ; \ #define ENTER CFI_STARTPROC ; \
GET_THREAD_INFO(%_ASM_BX) GET_THREAD_INFO(%_ASM_BX)
#define EXIT ret ; \ #define EXIT ASM_CLAC ; \
ret ; \
CFI_ENDPROC CFI_ENDPROC
.text .text
...@@ -39,6 +41,7 @@ ENTRY(__put_user_1) ...@@ -39,6 +41,7 @@ ENTRY(__put_user_1)
ENTER ENTER
cmp TI_addr_limit(%_ASM_BX),%_ASM_CX cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
jae bad_put_user jae bad_put_user
ASM_STAC
1: movb %al,(%_ASM_CX) 1: movb %al,(%_ASM_CX)
xor %eax,%eax xor %eax,%eax
EXIT EXIT
...@@ -50,6 +53,7 @@ ENTRY(__put_user_2) ...@@ -50,6 +53,7 @@ ENTRY(__put_user_2)
sub $1,%_ASM_BX sub $1,%_ASM_BX
cmp %_ASM_BX,%_ASM_CX cmp %_ASM_BX,%_ASM_CX
jae bad_put_user jae bad_put_user
ASM_STAC
2: movw %ax,(%_ASM_CX) 2: movw %ax,(%_ASM_CX)
xor %eax,%eax xor %eax,%eax
EXIT EXIT
...@@ -61,6 +65,7 @@ ENTRY(__put_user_4) ...@@ -61,6 +65,7 @@ ENTRY(__put_user_4)
sub $3,%_ASM_BX sub $3,%_ASM_BX
cmp %_ASM_BX,%_ASM_CX cmp %_ASM_BX,%_ASM_CX
jae bad_put_user jae bad_put_user
ASM_STAC
3: movl %eax,(%_ASM_CX) 3: movl %eax,(%_ASM_CX)
xor %eax,%eax xor %eax,%eax
EXIT EXIT
...@@ -72,6 +77,7 @@ ENTRY(__put_user_8) ...@@ -72,6 +77,7 @@ ENTRY(__put_user_8)
sub $7,%_ASM_BX sub $7,%_ASM_BX
cmp %_ASM_BX,%_ASM_CX cmp %_ASM_BX,%_ASM_CX
jae bad_put_user jae bad_put_user
ASM_STAC
4: mov %_ASM_AX,(%_ASM_CX) 4: mov %_ASM_AX,(%_ASM_CX)
#ifdef CONFIG_X86_32 #ifdef CONFIG_X86_32
5: movl %edx,4(%_ASM_CX) 5: movl %edx,4(%_ASM_CX)
......
...@@ -42,10 +42,11 @@ do { \ ...@@ -42,10 +42,11 @@ do { \
int __d0; \ int __d0; \
might_fault(); \ might_fault(); \
__asm__ __volatile__( \ __asm__ __volatile__( \
ASM_STAC "\n" \
"0: rep; stosl\n" \ "0: rep; stosl\n" \
" movl %2,%0\n" \ " movl %2,%0\n" \
"1: rep; stosb\n" \ "1: rep; stosb\n" \
"2:\n" \ "2: " ASM_CLAC "\n" \
".section .fixup,\"ax\"\n" \ ".section .fixup,\"ax\"\n" \
"3: lea 0(%2,%0,4),%0\n" \ "3: lea 0(%2,%0,4),%0\n" \
" jmp 2b\n" \ " jmp 2b\n" \
...@@ -626,10 +627,12 @@ unsigned long __copy_to_user_ll(void __user *to, const void *from, ...@@ -626,10 +627,12 @@ unsigned long __copy_to_user_ll(void __user *to, const void *from,
return n; return n;
} }
#endif #endif
stac();
if (movsl_is_ok(to, from, n)) if (movsl_is_ok(to, from, n))
__copy_user(to, from, n); __copy_user(to, from, n);
else else
n = __copy_user_intel(to, from, n); n = __copy_user_intel(to, from, n);
clac();
return n; return n;
} }
EXPORT_SYMBOL(__copy_to_user_ll); EXPORT_SYMBOL(__copy_to_user_ll);
...@@ -637,10 +640,12 @@ EXPORT_SYMBOL(__copy_to_user_ll); ...@@ -637,10 +640,12 @@ EXPORT_SYMBOL(__copy_to_user_ll);
unsigned long __copy_from_user_ll(void *to, const void __user *from, unsigned long __copy_from_user_ll(void *to, const void __user *from,
unsigned long n) unsigned long n)
{ {
stac();
if (movsl_is_ok(to, from, n)) if (movsl_is_ok(to, from, n))
__copy_user_zeroing(to, from, n); __copy_user_zeroing(to, from, n);
else else
n = __copy_user_zeroing_intel(to, from, n); n = __copy_user_zeroing_intel(to, from, n);
clac();
return n; return n;
} }
EXPORT_SYMBOL(__copy_from_user_ll); EXPORT_SYMBOL(__copy_from_user_ll);
...@@ -648,11 +653,13 @@ EXPORT_SYMBOL(__copy_from_user_ll); ...@@ -648,11 +653,13 @@ EXPORT_SYMBOL(__copy_from_user_ll);
unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from, unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
unsigned long n) unsigned long n)
{ {
stac();
if (movsl_is_ok(to, from, n)) if (movsl_is_ok(to, from, n))
__copy_user(to, from, n); __copy_user(to, from, n);
else else
n = __copy_user_intel((void __user *)to, n = __copy_user_intel((void __user *)to,
(const void *)from, n); (const void *)from, n);
clac();
return n; return n;
} }
EXPORT_SYMBOL(__copy_from_user_ll_nozero); EXPORT_SYMBOL(__copy_from_user_ll_nozero);
...@@ -660,6 +667,7 @@ EXPORT_SYMBOL(__copy_from_user_ll_nozero); ...@@ -660,6 +667,7 @@ EXPORT_SYMBOL(__copy_from_user_ll_nozero);
unsigned long __copy_from_user_ll_nocache(void *to, const void __user *from, unsigned long __copy_from_user_ll_nocache(void *to, const void __user *from,
unsigned long n) unsigned long n)
{ {
stac();
#ifdef CONFIG_X86_INTEL_USERCOPY #ifdef CONFIG_X86_INTEL_USERCOPY
if (n > 64 && cpu_has_xmm2) if (n > 64 && cpu_has_xmm2)
n = __copy_user_zeroing_intel_nocache(to, from, n); n = __copy_user_zeroing_intel_nocache(to, from, n);
...@@ -668,6 +676,7 @@ unsigned long __copy_from_user_ll_nocache(void *to, const void __user *from, ...@@ -668,6 +676,7 @@ unsigned long __copy_from_user_ll_nocache(void *to, const void __user *from,
#else #else
__copy_user_zeroing(to, from, n); __copy_user_zeroing(to, from, n);
#endif #endif
clac();
return n; return n;
} }
EXPORT_SYMBOL(__copy_from_user_ll_nocache); EXPORT_SYMBOL(__copy_from_user_ll_nocache);
...@@ -675,6 +684,7 @@ EXPORT_SYMBOL(__copy_from_user_ll_nocache); ...@@ -675,6 +684,7 @@ EXPORT_SYMBOL(__copy_from_user_ll_nocache);
unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *from, unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *from,
unsigned long n) unsigned long n)
{ {
stac();
#ifdef CONFIG_X86_INTEL_USERCOPY #ifdef CONFIG_X86_INTEL_USERCOPY
if (n > 64 && cpu_has_xmm2) if (n > 64 && cpu_has_xmm2)
n = __copy_user_intel_nocache(to, from, n); n = __copy_user_intel_nocache(to, from, n);
...@@ -683,6 +693,7 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr ...@@ -683,6 +693,7 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
#else #else
__copy_user(to, from, n); __copy_user(to, from, n);
#endif #endif
clac();
return n; return n;
} }
EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero); EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
......
...@@ -18,6 +18,7 @@ unsigned long __clear_user(void __user *addr, unsigned long size) ...@@ -18,6 +18,7 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
might_fault(); might_fault();
/* no memory constraint because it doesn't change any memory gcc knows /* no memory constraint because it doesn't change any memory gcc knows
about */ about */
stac();
asm volatile( asm volatile(
" testq %[size8],%[size8]\n" " testq %[size8],%[size8]\n"
" jz 4f\n" " jz 4f\n"
...@@ -40,6 +41,7 @@ unsigned long __clear_user(void __user *addr, unsigned long size) ...@@ -40,6 +41,7 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
: [size8] "=&c"(size), [dst] "=&D" (__d0) : [size8] "=&c"(size), [dst] "=&D" (__d0)
: [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(addr), : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(addr),
[zero] "r" (0UL), [eight] "r" (8UL)); [zero] "r" (0UL), [eight] "r" (8UL));
clac();
return size; return size;
} }
EXPORT_SYMBOL(__clear_user); EXPORT_SYMBOL(__clear_user);
...@@ -82,5 +84,6 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest) ...@@ -82,5 +84,6 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
for (c = 0, zero_len = len; zerorest && zero_len; --zero_len) for (c = 0, zero_len = len; zerorest && zero_len; --zero_len)
if (__put_user_nocheck(c, to++, sizeof(char))) if (__put_user_nocheck(c, to++, sizeof(char)))
break; break;
clac();
return len; return len;
} }
...@@ -996,6 +996,17 @@ static int fault_in_kernel_space(unsigned long address) ...@@ -996,6 +996,17 @@ static int fault_in_kernel_space(unsigned long address)
return address >= TASK_SIZE_MAX; return address >= TASK_SIZE_MAX;
} }
static inline bool smap_violation(int error_code, struct pt_regs *regs)
{
if (error_code & PF_USER)
return false;
if (!user_mode_vm(regs) && (regs->flags & X86_EFLAGS_AC))
return false;
return true;
}
/* /*
* This routine handles page faults. It determines the address, * This routine handles page faults. It determines the address,
* and the problem, and then passes it off to one of the appropriate * and the problem, and then passes it off to one of the appropriate
...@@ -1089,6 +1100,13 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code) ...@@ -1089,6 +1100,13 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
if (unlikely(error_code & PF_RSVD)) if (unlikely(error_code & PF_RSVD))
pgtable_bad(regs, error_code, address); pgtable_bad(regs, error_code, address);
if (static_cpu_has(X86_FEATURE_SMAP)) {
if (unlikely(smap_violation(error_code, regs))) {
bad_area_nosemaphore(regs, error_code, address);
return;
}
}
perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS, 1, regs, address); perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS, 1, regs, address);
/* /*
......
...@@ -709,7 +709,7 @@ static void __init test_wp_bit(void) ...@@ -709,7 +709,7 @@ static void __init test_wp_bit(void)
"Checking if this processor honours the WP bit even in supervisor mode..."); "Checking if this processor honours the WP bit even in supervisor mode...");
/* Any page-aligned address will do, the test is non-destructive */ /* Any page-aligned address will do, the test is non-destructive */
__set_fixmap(FIX_WP_TEST, __pa(&swapper_pg_dir), PAGE_READONLY); __set_fixmap(FIX_WP_TEST, __pa(&swapper_pg_dir), PAGE_KERNEL_RO);
boot_cpu_data.wp_works_ok = do_test_wp_bit(); boot_cpu_data.wp_works_ok = do_test_wp_bit();
clear_fixmap(FIX_WP_TEST); clear_fixmap(FIX_WP_TEST);
......
...@@ -36,5 +36,7 @@ extern struct wakeup_header wakeup_header; ...@@ -36,5 +36,7 @@ extern struct wakeup_header wakeup_header;
/* Wakeup behavior bits */ /* Wakeup behavior bits */
#define WAKEUP_BEHAVIOR_RESTORE_MISC_ENABLE 0 #define WAKEUP_BEHAVIOR_RESTORE_MISC_ENABLE 0
#define WAKEUP_BEHAVIOR_RESTORE_CR4 1
#define WAKEUP_BEHAVIOR_RESTORE_EFER 2
#endif /* ARCH_X86_KERNEL_ACPI_RM_WAKEUP_H */ #endif /* ARCH_X86_KERNEL_ACPI_RM_WAKEUP_H */
...@@ -74,9 +74,18 @@ ENTRY(wakeup_start) ...@@ -74,9 +74,18 @@ ENTRY(wakeup_start)
lidtl wakeup_idt lidtl wakeup_idt
/* Clear the EFLAGS */ /* Clear the EFLAGS but remember if we have EFLAGS.ID */
pushl $0 movl $X86_EFLAGS_ID, %ecx
pushl %ecx
popfl popfl
pushfl
popl %edi
pushl $0
popfl
pushfl
popl %edx
xorl %edx, %edi
andl %ecx, %edi /* %edi is zero iff CPUID & %cr4 are missing */
/* Check header signature... */ /* Check header signature... */
movl signature, %eax movl signature, %eax
...@@ -93,8 +102,8 @@ ENTRY(wakeup_start) ...@@ -93,8 +102,8 @@ ENTRY(wakeup_start)
/* Restore MISC_ENABLE before entering protected mode, in case /* Restore MISC_ENABLE before entering protected mode, in case
BIOS decided to clear XD_DISABLE during S3. */ BIOS decided to clear XD_DISABLE during S3. */
movl pmode_behavior, %eax movl pmode_behavior, %edi
btl $WAKEUP_BEHAVIOR_RESTORE_MISC_ENABLE, %eax btl $WAKEUP_BEHAVIOR_RESTORE_MISC_ENABLE, %edi
jnc 1f jnc 1f
movl pmode_misc_en, %eax movl pmode_misc_en, %eax
...@@ -110,15 +119,15 @@ ENTRY(wakeup_start) ...@@ -110,15 +119,15 @@ ENTRY(wakeup_start)
movl pmode_cr3, %eax movl pmode_cr3, %eax
movl %eax, %cr3 movl %eax, %cr3
movl pmode_cr4, %ecx btl $WAKEUP_BEHAVIOR_RESTORE_CR4, %edi
jecxz 1f jz 1f
movl %ecx, %cr4 movl pmode_cr4, %eax
movl %eax, %cr4
1: 1:
btl $WAKEUP_BEHAVIOR_RESTORE_EFER, %edi
jz 1f
movl pmode_efer, %eax movl pmode_efer, %eax
movl pmode_efer + 4, %edx movl pmode_efer + 4, %edx
movl %eax, %ecx
orl %edx, %ecx
jz 1f
movl $MSR_EFER, %ecx movl $MSR_EFER, %ecx
wrmsr wrmsr
1: 1:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment