Skip to content

Commit

Permalink
x86, smap: smap_violation() is bogus if CONFIG_X86_SMAP is off
Browse files Browse the repository at this point in the history
If CONFIG_X86_SMAP is disabled, smap_violation() tests for conditions
which are incorrect (as the AC flag doesn't matter), causing spurious
faults.

The dynamic disabling of SMAP (nosmap on the command line) is fine
because it disables X86_FEATURE_SMAP, therefore causing the
static_cpu_has() to return false.

Found by Fengguang Wu's test system.

[ v3: move all predicates into smap_violation() ]
[ v2: use IS_ENABLED() instead of #ifdef ]

Reported-by: Fengguang Wu <[email protected]>
Link: http://lkml.kernel.org/r/20140213124550.GA30497@localhost
Signed-off-by: H. Peter Anvin <[email protected]>
Cc: <[email protected]> # v3.7+
  • Loading branch information
H. Peter Anvin committed Feb 13, 2014
1 parent 03bbd59 commit 4640c7e
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions arch/x86/mm/fault.c
Original file line number Diff line number Diff line change
Expand Up @@ -1001,6 +1001,12 @@ static int fault_in_kernel_space(unsigned long address)

static inline bool smap_violation(int error_code, struct pt_regs *regs)
{
if (!IS_ENABLED(CONFIG_X86_SMAP))
return false;

if (!static_cpu_has(X86_FEATURE_SMAP))
return false;

if (error_code & PF_USER)
return false;

Expand Down Expand Up @@ -1087,11 +1093,9 @@ __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;
}
if (unlikely(smap_violation(error_code, regs))) {
bad_area_nosemaphore(regs, error_code, address);
return;
}

/*
Expand Down

0 comments on commit 4640c7e

Please sign in to comment.