Also account for an INT3 breakpoint potentially placed (from a kernel debugger) on sysenter_entry, which requires the NMI handler to add one more check. Further, don't discard debug or breakpoint traps/faults happening on this one instruction and their handler getting interrupted by an NMI before being able to fix the stack. From: Jan Beulich --- 2.6.14/arch/i386/kernel/entry.S 2005-10-28 02:02:08.000000000 +0200 +++ 2.6.14-i386-nmi-int3/arch/i386/kernel/entry.S 2005-11-08 17:06:59.000000000 +0100 @@ -178,6 +178,7 @@ need_resched: # sysenter call handler stub ENTRY(sysenter_entry) movl TSS_sysenter_esp0(%esp),%esp +.globl sysenter_past_esp sysenter_past_esp: sti pushl $(__USER_DS) @@ -520,12 +521,12 @@ debug_stack_correct: jmp ret_from_exception .previous .text /* - * NMI is doubly nasty. It can happen _while_ we're handling - * a debug fault, and the debug fault hasn't yet been able to - * clear up the stack. So we first check whether we got an + * NMI is doubly nasty. It can happen _while_ we're handling a debug + * fault or breakpoint trap, and the fault/trap hasn't yet been able + * to clear up the stack. So we first check whether we got an * NMI on the sysenter entry path, but after that we need to - * check whether we got an NMI on the debug path where the debug - * fault happened on the sysenter path. + * check whether we got an NMI on the debug/breakpoint path where the + * fault/trap happened on the sysenter path. */ ENTRY(nmi) pushl %eax @@ -546,6 +547,8 @@ ENTRY(nmi) jae nmi_stack_correct cmpl $sysenter_entry,12(%esp) je nmi_debug_stack_check + cmpl $sysenter_entry+1,12(%esp) + je .Lnmi_int3_stack_check nmi_stack_correct: pushl %eax SAVE_ALL @@ -566,6 +569,21 @@ nmi_debug_stack_check: jle nmi_debug_stack_fixup nmi_debug_stack_fixup: FIX_STACK(24,nmi_stack_correct, 1) + pushfl + pushl $__KERNEL_CS + pushl $debug_stack_correct + jmp nmi_stack_correct +.Lnmi_int3_stack_check: + cmpw $__KERNEL_CS,16(%esp) + jne nmi_stack_correct + cmpl $int3, (%esp) + jb nmi_stack_correct + cmpl $.Lint3_esp_fix_insn, (%esp) + ja nmi_stack_correct + FIX_STACK(24,nmi_stack_correct, 1) + pushfl + pushl $__KERNEL_CS + pushl $.Lint3_stack_correct jmp nmi_stack_correct nmi_16bit_stack: @@ -592,6 +610,10 @@ nmi_16bit_stack: .previous KPROBE_ENTRY(int3) + cmpl $sysenter_entry+1, (%esp) + jne .Lint3_stack_correct + FIX_STACK(12, .Lint3_stack_correct, .Lint3_esp_fix_insn) +.Lint3_stack_correct: pushl $-1 # mark this as an int SAVE_ALL xorl %edx,%edx # zero error code