Skip to content

Commit

Permalink
x86: Barf when vmalloc and kmemcheck faults happen in NMI
Browse files Browse the repository at this point in the history
In x86, faults exit by executing the iret instruction, which then
reenables NMIs if we faulted in NMI context. Then if a fault
happens in NMI, another NMI can nest after the fault exits.

But we don't yet support nested NMIs because we have only one NMI
stack. To prevent from that, check that vmalloc and kmemcheck
faults don't happen in this context. Most of the other kernel faults
in NMIs can be more easily spotted by finding explicit
copy_from,to_user() calls on review.

Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
  • Loading branch information
Frederic Weisbecker committed Oct 14, 2010
1 parent 14cae9b commit ebc8827
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
4 changes: 4 additions & 0 deletions arch/x86/mm/fault.c
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,8 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
if (!(address >= VMALLOC_START && address < VMALLOC_END))
return -1;

WARN_ON_ONCE(in_nmi());

/*
* Synchronize this task's top level page-table
* with the 'reference' page table.
Expand Down Expand Up @@ -369,6 +371,8 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
if (!(address >= VMALLOC_START && address < VMALLOC_END))
return -1;

WARN_ON_ONCE(in_nmi());

/*
* Copy kernel mappings over when needed. This can also
* happen within a race in page table update. In the later
Expand Down
2 changes: 2 additions & 0 deletions arch/x86/mm/kmemcheck/kmemcheck.c
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,8 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
if (!pte)
return false;

WARN_ON_ONCE(in_nmi());

if (error_code & 2)
kmemcheck_access(regs, address, KMEMCHECK_WRITE);
else
Expand Down

0 comments on commit ebc8827

Please sign in to comment.