Skip to content

Commit fc57a7c

Browse files
amlutoKAGA-KOKO
authored andcommitted
x86/paravirt: Replace the paravirt nop with a bona fide empty function
PARAVIRT_ADJUST_EXCEPTION_FRAME generates this code (using nmi as an example, trimmed for readability): ff 15 00 00 00 00 callq *0x0(%rip) # 2796 <nmi+0x6> 2792: R_X86_64_PC32 pv_irq_ops+0x2c That's a call through a function pointer to regular C function that does nothing on native boots, but that function isn't protected against kprobes, isn't marked notrace, and is certainly not guaranteed to preserve any registers if the compiler is feeling perverse. This is bad news for a CLBR_NONE operation. Of course, if everything works correctly, once paravirt ops are patched, it gets nopped out, but what if we hit this code before paravirt ops are patched in? This can potentially cause breakage that is very difficult to debug. A more subtle failure is possible here, too: if _paravirt_nop uses the stack at all (even just to push RBP), it will overwrite the "NMI executing" variable if it's called in the NMI prologue. The Xen case, perhaps surprisingly, is fine, because it's already written in asm. Fix all of the cases that default to paravirt_nop (including adjust_exception_frame) with a big hammer: replace paravirt_nop with an asm function that is just a ret instruction. The Xen case may have other problems, so document them. This is part of a fix for some random crashes that Sasha saw. Reported-and-tested-by: Sasha Levin <sasha.levin@oracle.com> Signed-off-by: Andy Lutomirski <luto@kernel.org> Cc: stable@vger.kernel.org Link: http://lkml.kernel.org/r/8f5d2ba295f9d73751c33d97fda03e0495d9ade0.1442791737.git.luto@kernel.org Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
1 parent 1f93e4a commit fc57a7c

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

arch/x86/entry/entry_64.S

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1128,7 +1128,18 @@ END(error_exit)
11281128

11291129
/* Runs on exception stack */
11301130
ENTRY(nmi)
1131+
/*
1132+
* Fix up the exception frame if we're on Xen.
1133+
* PARAVIRT_ADJUST_EXCEPTION_FRAME is guaranteed to push at most
1134+
* one value to the stack on native, so it may clobber the rdx
1135+
* scratch slot, but it won't clobber any of the important
1136+
* slots past it.
1137+
*
1138+
* Xen is a different story, because the Xen frame itself overlaps
1139+
* the "NMI executing" variable.
1140+
*/
11311141
PARAVIRT_ADJUST_EXCEPTION_FRAME
1142+
11321143
/*
11331144
* We allow breakpoints in NMIs. If a breakpoint occurs, then
11341145
* the iretq it performs will take us out of NMI context.

arch/x86/kernel/paravirt.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,18 @@
4141
#include <asm/timer.h>
4242
#include <asm/special_insns.h>
4343

44-
/* nop stub */
45-
void _paravirt_nop(void)
46-
{
47-
}
44+
/*
45+
* nop stub, which must not clobber anything *including the stack* to
46+
* avoid confusing the entry prologues.
47+
*/
48+
extern void _paravirt_nop(void);
49+
asm (".pushsection .entry.text, \"ax\"\n"
50+
".global _paravirt_nop\n"
51+
"_paravirt_nop:\n\t"
52+
"ret\n\t"
53+
".size _paravirt_nop, . - _paravirt_nop\n\t"
54+
".type _paravirt_nop, @function\n\t"
55+
".popsection");
4856

4957
/* identity function, which can be inlined */
5058
u32 _paravirt_ident_32(u32 x)

0 commit comments

Comments
 (0)