i386: fix incorrect FP signal delivery
Quoted 2 lines · Andi Kleen
How about you describe what you actually changed and why so that not every reviewer has to look up all the bits in the manual?
The patch had a bug anyway, so here's another try. *** Replace
the previous patch with this one. ***
i386 floating-point exception handling has a bug that can cause error code 0 to be sent instead of the proper code during signal delivery. This is caused by unconditionally checking the IS and c1 bits from the FPU status word when they are not always relevant. The IS bit tells whether an exception is a stack fault and is only relevant when the exception is IE (invalid operation.) The C1 bit determines whether a stack fault is overflow or underflow and is only relevant when IS and IE are set.
This bug also exists in the 2.4 kernel and appears to be in the 2.6 x86_64 code as well.
Patch applies with offsets to 2.4.31 and 2.6.13-rc6-mm1.
arch/i386/kernel/traps.c | 18 ++++++++++++++++-- 1 files changed, 16 insertions(+), 2 deletions(-)
arch/i386/kernel/traps.c +16 -2
@@ -778,7 +778,7 @@ void math_error(void __user *eip) {struct task_struct * task;siginfo_t info; -unsigned short cwd, swd; +unsigned short cwd, swd, wd;/* * Save the info for the exception handler and clear the error.
@@ -803,7 +803,21 @@ void math_error(void __user *eip)*/ cwd =get_fpu_cwd (task); swd =get_fpu_swd (task); -switch (((~cwd) & swd &0x3f ) | (swd &0x240 )) { + wd = swd &0x3f & ~cwd; +/* +* If the exception is invalid operation, the IS bit is needed +* to see if it's a stack fault. +*/ +if (wd &1 ) + wd |= swd &0x40 ; +/* +* If it's a stack fault, C1 is needed to see if it's overflow or +* underflow. +*/ +if (wd &0x40 ) + wd |= swd &0x200 ; + +switch (wd) {case 0x000 :default :break ;
__
Chuck
Quoted 3 lines · Chuck Ebbert
i386 floating-point exception handling has a bug that can cause error code 0 to be sent instead of the proper code during signal delivery.
Looking at your patch, I think it's too complicated.
The fact is, none of the "switch()" cases even _care_ about bits "0x240" from swd. The bug itself seems to be that we even look at it.
Wouldn't this simpler patch result in exactly the same behaviour?
Linus
---
arch/i386/kernel/traps.c +3 -4
@@ -803,15 +803,14 @@ void math_error(void __user *eip)*/ cwd =get_fpu_cwd (task); swd =get_fpu_swd (task); -switch (((~cwd) & swd &0x3f ) | (swd &0x240 )) { +switch (swd & ~cwd &0x3f ) {case 0x000 :default :break ;case 0x001 :/* Invalid Op */ -case 0x041 :/* Stack Fault */ -case 0x241 :/* Stack Fault | Direction */ +/* swd & 0x240 == 0x040: Stack Fault */ +/* swd & 0x240 == 0x240: Stack Fault | Direction */ info.si_code =FPE_FLTINV ; -/* Should we clear the SF or let user space do it ???? */ break ;case 0x002 :/* Denormalize */ case 0x010 :/* Underflow */