Skip to content

Commit 55617fb

Browse files
KAGA-KOKOhansendc
authored andcommitted
x86/entry: Do not allow external 0x80 interrupts
The INT 0x80 instruction is used for 32-bit x86 Linux syscalls. The kernel expects to receive a software interrupt as a result of the INT 0x80 instruction. However, an external interrupt on the same vector also triggers the same codepath. An external interrupt on vector 0x80 will currently be interpreted as a 32-bit system call, and assuming that it was a user context. Panic on external interrupts on the vector. To distinguish software interrupts from external ones, the kernel checks the APIC ISR bit relevant to the 0x80 vector. For software interrupts, this bit will be 0. Signed-off-by: Thomas Gleixner <[email protected]> Signed-off-by: Kirill A. Shutemov <[email protected]> Signed-off-by: Dave Hansen <[email protected]> Reviewed-by: Borislav Petkov (AMD) <[email protected]> Cc: <[email protected]> # v6.0+
1 parent be5341e commit 55617fb

File tree

1 file changed

+36
-1
lines changed

1 file changed

+36
-1
lines changed

arch/x86/entry/common.c

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <xen/events.h>
2727
#endif
2828

29+
#include <asm/apic.h>
2930
#include <asm/desc.h>
3031
#include <asm/traps.h>
3132
#include <asm/vdso.h>
@@ -168,6 +169,25 @@ static __always_inline void do_syscall_32_irqs_on(struct pt_regs *regs, int nr)
168169
}
169170

170171
#ifdef CONFIG_IA32_EMULATION
172+
static __always_inline bool int80_is_external(void)
173+
{
174+
const unsigned int offs = (0x80 / 32) * 0x10;
175+
const u32 bit = BIT(0x80 % 32);
176+
177+
/* The local APIC on XENPV guests is fake */
178+
if (cpu_feature_enabled(X86_FEATURE_XENPV))
179+
return false;
180+
181+
/*
182+
* If vector 0x80 is set in the APIC ISR then this is an external
183+
* interrupt. Either from broken hardware or injected by a VMM.
184+
*
185+
* Note: In guest mode this is only valid for secure guests where
186+
* the secure module fully controls the vAPIC exposed to the guest.
187+
*/
188+
return apic_read(APIC_ISR + offs) & bit;
189+
}
190+
171191
/**
172192
* int80_emulation - 32-bit legacy syscall entry
173193
*
@@ -191,12 +211,27 @@ DEFINE_IDTENTRY_RAW(int80_emulation)
191211
{
192212
int nr;
193213

194-
/* Establish kernel context. */
214+
/* Kernel does not use INT $0x80! */
215+
if (unlikely(!user_mode(regs))) {
216+
irqentry_enter(regs);
217+
instrumentation_begin();
218+
panic("Unexpected external interrupt 0x80\n");
219+
}
220+
221+
/*
222+
* Establish kernel context for instrumentation, including for
223+
* int80_is_external() below which calls into the APIC driver.
224+
* Identical for soft and external interrupts.
225+
*/
195226
enter_from_user_mode(regs);
196227

197228
instrumentation_begin();
198229
add_random_kstack_offset();
199230

231+
/* Validate that this is a soft interrupt to the extent possible */
232+
if (unlikely(int80_is_external()))
233+
panic("Unexpected external interrupt 0x80\n");
234+
200235
/*
201236
* The low level idtentry code pushed -1 into regs::orig_ax
202237
* and regs::ax contains the syscall number.

0 commit comments

Comments
 (0)