x86: kernel-mode faults pollute current->thead
Quoted 3 lines
Yup. How does this patch look to you? We set
error_codeandtrap_nofor userspace faults and kernel faults which calldie(). We don't set them for kernelspace faults which are fixed up.
Actually, after a second round of thinking I believe there's still more to do
- your second patch missed fixing i386's do_trap() similarly to x86-64's and, vice versa, x86-64's do_general_protection() similarly to i386's.
Jan
Quoted 7 lines · Jan Beulich
Quoted 3 lines
Yup. How does this patch look to you? We set
error_codeandtrap_nofor userspace faults and kernel faults which calldie(). We don't set them for kernelspace faults which are fixed up.Actually, after a second round of thinking I believe there's still more to do
- your second patch missed fixing i386'sdo_trap()similarly to x86-64's and, vice versa, x86-64'sdo_general_protection()similarly to i386's.
I dropped the patch for now until that is all worked out
-Andi
Quoted 3 lines · Jan Beulich
Actually, after a second round of thinking I believe there's still more to do
- your second patch missed fixing i386'sdo_trap()similarly to x86-64's and, vice versa, x86-64'sdo_general_protection()similarly to i386's.
Sigh, here's another go at it - the full patch instead of incrementally fixing the old one:
arch/i386/kernel/traps.c +18 -6
@@ -473,8 +473,6 @@ static void __kprobes do_trap(int trapnr siginfo_t *info) {struct task_struct *tsk = current; - tsk->thread.error_code = error_code; - tsk->thread.trap_no = trapnr;if (regs->eflags &VM_MASK ) {if (vm86)
@@ -486,6 +484,9 @@ static void __kprobes do_trap(int trapnr goto kernel_trap; trap_signal: { + tsk->thread.error_code = error_code; + tsk->thread.trap_no = trapnr; +if (info)force_sig_info (signr, info, tsk);else
@@ -494,8 +495,11 @@ static void __kprobes do_trap(int trapnr } kernel_trap: { -if (!fixup_exception (regs)) +if (!fixup_exception (regs)) { + tsk->thread.error_code = error_code; + tsk->thread.trap_no = trapnr;die (str, regs, error_code); + }return ; }
@@ -600,15 +604,21 @@ fastcall void __kprobes do_general_prote }put_cpu (); - current->thread.error_code = error_code; - current->thread.trap_no =13 ; -if (regs->eflags &VM_MASK ) goto gp_in_vm86;if (!user_mode (regs)) goto gp_in_kernel; +/* +* We want error_code and trap_no set for userspace faults and +* kernelspace faults which result in die(), but not +* kernelspace faults which are fixed up. die() gives the +* process no chance to handle the signal and notice the +* kernel fault information, so that won't result in polluting +* the information about previously queued, but not yet +* delivered, fault. +*/ current->thread.error_code = error_code; current->thread.trap_no =13 ;force_sig (SIGSEGV , current);
@@ -621,6 +631,8 @@ gp_in_vm86: gp_in_kernel:if (!fixup_exception (regs)) { + current->thread.error_code = error_code; + current->thread.trap_no =13 ;if (notify_die (DIE_GPF ,"general protection fault" , regs, error_code,13 ,SIGSEGV ) ==NOTIFY_STOP )return ;
arch/x86_64/kernel/traps.c +23 -7
@@ -581,10 +581,19 @@ static void __kprobes do_trap(int trapnr {struct task_struct *tsk = current; - tsk->thread.error_code = error_code; - tsk->thread.trap_no = trapnr; -if (user_mode (regs)) { +/* +* We want error_code and trap_no set for userspace faults +* and kernelspace faults which result in die(), but +* not kernelspace faults which are fixed up. die() +* gives the process no chance to handle the signal +* and notice the kernel fault information, so that +* won't result in polluting the information about +* previously queued, but not yet delivered, fault. +*/ + tsk->thread.error_code = error_code; + tsk->thread.trap_no = trapnr; +if (exception_trace &&unhandled_signal (tsk, signr)) printk(KERN_INFO "%s[%d] trap %s rip:%lx rsp:%lx error:%lx\n",
@@ -605,8 +614,11 @@ static void __kprobes do_trap(int trapnr fixup =search_exception_tables (regs->rip);if (fixup) regs->rip = fixup->fixup; -else +else { + tsk->thread.error_code = error_code; + tsk->thread.trap_no = trapnr;die (str, regs, error_code); + }return ; } }
@@ -682,10 +694,10 @@ asmlinkage void __kprobes do_general_proconditional_sti (regs); - tsk->thread.error_code = error_code; - tsk->thread.trap_no =13 ; -if (user_mode (regs)) { + tsk->thread.error_code = error_code; + tsk->thread.trap_no =13 ; +if (exception_trace &&unhandled_signal (tsk,SIGSEGV )) printk(KERN_INFO "%s[%d] general protection rip:%lx rsp:%lx error:%lx\n",
@@ -704,6 +716,10 @@ asmlinkage void __kprobes do_general_pro regs->rip = fixup->fixup;return ; } + + + tsk->thread.error_code = error_code; + tsk->thread.trap_no =13 ;if (notify_die (DIE_GPF ,"general protection fault" , regs, error_code,13 ,SIGSEGV ) ==NOTIFY_STOP )return ;
Signature · 1 line
Work email - jdike at linux dot intel dot com
Quoted 8 lines
Quoted 1 line
Quoted 1 line
Jeff Dike <[email protected]> 14.02.07 18:51 >>>
Quoted 3 lines · Jan Beulich
Actually, after a second round of thinking I believe there's still more to do
- your second patch missed fixing i386'sdo_trap()similarly to x86-64's and, vice versa, x86-64'sdo_general_protection()similarly to i386's.Sigh, here's another go at it - the full patch instead of incrementally fixing the old one:
Ack.
Quoted 1 line · Jan Beulich
Ack.
Great, thanks for your help.
Jeff
Signature · 1 line
Work email - jdike at linux dot intel dot com