i386: handle iret faults better
PATCH 1/1 i386: handle iret faults better
A user process can cause a kernel-mode fault in the iret instruction, by setting an invalid %cs and such, via ptrace or sigreturn. The fixup code now calls do_exit(11), so a process will die with SIGSEGV but never generate a core dump. This is vastly more confusing in a multithreaded program, because do_exit just kills that one thread and so it appears to mysteriously disappear when it calls sigreturn.
This patch makes faults in iret produce the normal signals that would result from the same errors when executing some user-mode instruction. It requires some special case hair rather than just better fixup code, because the full trap details that go into the signal info are not available to the fixup code.
Thanks,
Roland
arch/i386/kernel/entry.S +16 -7
@@ -254,14 +253,23 @@ restore_nocheck: RESTORE_REGS addl $4, %esp 1: iret + /* + * Traps in iret mean that userland tried to restore a bogus + * cs, eip, ss, esp, or eflags. Some kinds of bogosity just cause + * a trap after the iret returns, but some will cause a trap in + * iret itself. We want to treat those as if the restored user + * state is what caused that trap, i.e. produce the appropriate signal. + * Since normal .fixup code doesn't have access to the trap info, + * traps.c has a special case for iret. It's already generated the + * signal before we resume at iret_exc. Now we just need to recover + * the whole frame we were trying to restore, so it can be seen on + * our stack by the debugger. + */ .section .fixup,"ax" -iret_exc: - sti - movl $__USER_DS, %edx - movl %edx, %ds - movl %edx, %es - movl $11,%eax - call do_exit +ENTRY(iret_exc) + pushl $0 # orig_eax was lost + SAVE_ALL + jmp ret_from_exception .previous .section __ex_table,"a" .align 4
arch/i386/kernel/traps.c +57 -1
88 lines not on this page · raw message