mirror of
https://github.com/Divested-Mobile/DivestOS-Build.git
synced 2024-10-01 01:35:54 -04:00
95 lines
3.0 KiB
Diff
95 lines
3.0 KiB
Diff
diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
|
|
index db230f8..1a454d0 100644
|
|
--- a/arch/x86/kernel/entry_64.S
|
|
+++ b/arch/x86/kernel/entry_64.S
|
|
@@ -1068,6 +1068,7 @@
|
|
jnz native_irq_return_ldt
|
|
#endif
|
|
|
|
+.global native_irq_return_iret
|
|
native_irq_return_iret:
|
|
iretq
|
|
_ASM_EXTABLE(native_irq_return_iret, bad_iret)
|
|
@@ -1164,37 +1165,6 @@
|
|
CFI_ENDPROC
|
|
END(common_interrupt)
|
|
|
|
- /*
|
|
- * If IRET takes a fault on the espfix stack, then we
|
|
- * end up promoting it to a doublefault. In that case,
|
|
- * modify the stack to make it look like we just entered
|
|
- * the #GP handler from user space, similar to bad_iret.
|
|
- */
|
|
-#ifdef CONFIG_X86_ESPFIX64
|
|
- ALIGN
|
|
-__do_double_fault:
|
|
- XCPT_FRAME 1 RDI+8
|
|
- movq RSP(%rdi),%rax /* Trap on the espfix stack? */
|
|
- sarq $PGDIR_SHIFT,%rax
|
|
- cmpl $ESPFIX_PGD_ENTRY,%eax
|
|
- jne do_double_fault /* No, just deliver the fault */
|
|
- cmpl $__KERNEL_CS,CS(%rdi)
|
|
- jne do_double_fault
|
|
- movq RIP(%rdi),%rax
|
|
- cmpq $native_irq_return_iret,%rax
|
|
- jne do_double_fault /* This shouldn't happen... */
|
|
- movq PER_CPU_VAR(kernel_stack),%rax
|
|
- subq $(6*8-KERNEL_STACK_OFFSET),%rax /* Reset to original stack */
|
|
- movq %rax,RSP(%rdi)
|
|
- movq $0,(%rax) /* Missing (lost) #GP error code */
|
|
- movq $general_protection,RIP(%rdi)
|
|
- retq
|
|
- CFI_ENDPROC
|
|
-END(__do_double_fault)
|
|
-#else
|
|
-# define __do_double_fault do_double_fault
|
|
-#endif
|
|
-
|
|
/*
|
|
* End of kprobes section
|
|
*/
|
|
@@ -1363,7 +1333,7 @@
|
|
zeroentry bounds do_bounds
|
|
zeroentry invalid_op do_invalid_op
|
|
zeroentry device_not_available do_device_not_available
|
|
-paranoiderrorentry double_fault __do_double_fault
|
|
+paranoiderrorentry double_fault do_double_fault
|
|
zeroentry coprocessor_segment_overrun do_coprocessor_segment_overrun
|
|
errorentry invalid_TSS do_invalid_TSS
|
|
errorentry segment_not_present do_segment_not_present
|
|
diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
|
|
index 772e2a8..74e0801 100644
|
|
--- a/arch/x86/kernel/traps.c
|
|
+++ b/arch/x86/kernel/traps.c
|
|
@@ -247,6 +247,30 @@
|
|
static const char str[] = "double fault";
|
|
struct task_struct *tsk = current;
|
|
|
|
+#ifdef CONFIG_X86_ESPFIX64
|
|
+ extern unsigned char native_irq_return_iret[];
|
|
+
|
|
+ /*
|
|
+ * If IRET takes a non-IST fault on the espfix64 stack, then we
|
|
+ * end up promoting it to a doublefault. In that case, modify
|
|
+ * the stack to make it look like we just entered the #GP
|
|
+ * handler from user space, similar to bad_iret.
|
|
+ */
|
|
+ if (((long)regs->sp >> PGDIR_SHIFT) == ESPFIX_PGD_ENTRY &&
|
|
+ regs->cs == __KERNEL_CS &&
|
|
+ regs->ip == (unsigned long)native_irq_return_iret)
|
|
+ {
|
|
+ struct pt_regs *normal_regs = task_pt_regs(current);
|
|
+
|
|
+ /* Fake a #GP(0) from userspace. */
|
|
+ memmove(&normal_regs->ip, (void *)regs->sp, 5*8);
|
|
+ normal_regs->orig_ax = 0; /* Missing (lost) #GP error code */
|
|
+ regs->ip = (unsigned long)general_protection;
|
|
+ regs->sp = (unsigned long)&normal_regs->orig_ax;
|
|
+ return;
|
|
+ }
|
|
+#endif
|
|
+
|
|
exception_enter();
|
|
/* Return not checked because double check cannot be ignored */
|
|
notify_die(DIE_TRAP, str, regs, error_code, X86_TRAP_DF, SIGSEGV);
|