Skip to content

Commit 59be5c3

Browse files
xry111tsbogend
authored andcommitted
mips: Call lose_fpu(0) before initializing fcr31 in mips_set_personality_nan
If we still own the FPU after initializing fcr31, when we are preempted the dirty value in the FPU will be read out and stored into fcr31, clobbering our setting. This can cause an improper floating-point environment after execve(). For example: zsh% cat measure.c #include <fenv.h> int main() { return fetestexcept(FE_INEXACT); } zsh% cc measure.c -o measure -lm zsh% echo $((1.0/3)) # raising FE_INEXACT 0.33333333333333331 zsh% while ./measure; do ; done (stopped in seconds) Call lose_fpu(0) before setting fcr31 to prevent this. Closes: https://lore.kernel.org/linux-mips/7a6aa1bbdbbe2e63ae96ff163fab0349f58f1b9e.camel@xry111.site/ Fixes: 9b26616 ("MIPS: Respect the ISA level in FCSR handling") Cc: stable@vger.kernel.org Signed-off-by: Xi Ruoyao <xry111@xry111.site> Signed-off-by: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
1 parent 822df31 commit 59be5c3

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

arch/mips/kernel/elf.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include <asm/cpu-features.h>
1313
#include <asm/cpu-info.h>
14+
#include <asm/fpu.h>
1415

1516
#ifdef CONFIG_MIPS_FP_SUPPORT
1617

@@ -309,6 +310,11 @@ void mips_set_personality_nan(struct arch_elf_state *state)
309310
struct cpuinfo_mips *c = &boot_cpu_data;
310311
struct task_struct *t = current;
311312

313+
/* Do this early so t->thread.fpu.fcr31 won't be clobbered in case
314+
* we are preempted before the lose_fpu(0) in start_thread.
315+
*/
316+
lose_fpu(0);
317+
312318
t->thread.fpu.fcr31 = c->fpu_csr31;
313319
switch (state->nan_2008) {
314320
case 0:

0 commit comments

Comments
 (0)