From 69149e6a5fffb8484b93bfd7c40ab2fa4dfbf4f5 Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Fri, 21 Sep 2012 12:43:14 -0700 Subject: [PATCH] --- yaml --- r: 326239 b: refs/heads/master c: 40d3cd6695014bf3c44e2ca66b610b18acaf923d h: refs/heads/master i: 326237: e802d0b7943ca6ba75933cab8d0bc2434a3c8cc2 326235: 400c410ca4bc757c3a6aeed80de742321e1c47a3 326231: a70bbe6b38eeb215a289f9c60f48b3da79515afa 326223: d1cff23a37517bb2948da540736278356e0dcbf4 326207: 3e799828e3fe6acde0ae80ea0bc680d5236009d9 v: v3 --- [refs] | 2 +- trunk/arch/x86/mm/fault.c | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/[refs] b/[refs] index f1ec3a22ecce..86680a0ff867 100644 --- a/[refs] +++ b/[refs] @@ -1,2 +1,2 @@ --- -refs/heads/master: 52b6179ac87d33c2eeaff5292786a10fe98cff64 +refs/heads/master: 40d3cd6695014bf3c44e2ca66b610b18acaf923d diff --git a/trunk/arch/x86/mm/fault.c b/trunk/arch/x86/mm/fault.c index 76dcd9d8e0bc..f2fb75d46b96 100644 --- a/trunk/arch/x86/mm/fault.c +++ b/trunk/arch/x86/mm/fault.c @@ -995,6 +995,17 @@ static int fault_in_kernel_space(unsigned long address) 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, * and the problem, and then passes it off to one of the appropriate @@ -1088,6 +1099,13 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code) if (unlikely(error_code & PF_RSVD)) 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); /*