[rtems commit] i386: Fix possible race condition on first context restore

Sebastian Huber sebh at rtems.org
Wed Jul 29 09:39:13 UTC 2020


Module:    rtems
Branch:    master
Commit:    21c7e3a41f1590b18c2c3f883e2b63e36cc409aa
Changeset: http://git.rtems.org/rtems/commit/?id=21c7e3a41f1590b18c2c3f883e2b63e36cc409aa

Author:    Jan Sommer <jan.sommer at dlr.de>
Date:      Wed Jul 22 14:41:51 2020 +0200

i386: Fix possible race condition on first context restore

Make sure that the esp is restored before the eflags register.

When the init task is initially restored, system interrupts are activated when the
eflags register is loaded.
If the esp register still points to an address in the interrupt stack
area (from early system initlization) the ISR might overwrite its own
stack.

Closes #4031

---

 cpukit/score/cpu/i386/cpu_asm.S | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/cpukit/score/cpu/i386/cpu_asm.S b/cpukit/score/cpu/i386/cpu_asm.S
index 6031f69..2336095 100644
--- a/cpukit/score/cpu/i386/cpu_asm.S
+++ b/cpukit/score/cpu/i386/cpu_asm.S
@@ -83,9 +83,9 @@ SYM (_CPU_Context_switch):
 .L_restore:
         movl      I386_CONTEXT_CONTROL_ISR_DISPATCH_DISABLE(eax),ecx
         movl      ecx,PER_CPU_ISR_DISPATCH_DISABLE(edx)
+        movl      REG_ESP(eax),esp         /* restore stack pointer */
         pushl     REG_EFLAGS(eax)          /* push eflags */
         popf                               /* restore eflags */
-        movl      REG_ESP(eax),esp         /* restore stack pointer */
         movl      REG_EBP(eax),ebp         /* restore base pointer */
         movl      REG_EBX(eax),ebx         /* restore ebx */
         movl      REG_ESI(eax),esi         /* restore source register */



More information about the vc mailing list