[GHC] #10155: [PATCH] Possibly incorrect stack pointer usage in StgRun() on x86_64

GHC ghc-devs at haskell.org
Fri Mar 13 13:37:17 UTC 2015


#10155: [PATCH] Possibly incorrect stack pointer usage in StgRun() on x86_64
-------------------------------------+-------------------------------------
              Reporter:  stengel     |             Owner:  simonmar
                  Type:  bug         |            Status:  new
              Priority:  normal      |         Milestone:
             Component:  Runtime     |           Version:  7.8.1
  System                             |  Operating System:  Unknown/Multiple
              Keywords:              |   Type of failure:  Other
          Architecture:  x86_64      |        Blocked By:
  (amd64)                            |   Related Tickets:
             Test Case:              |
              Blocking:              |
Differential Revisions:              |
-------------------------------------+-------------------------------------
 The STG_RETURN code from StgCRun.c is incorrect for x86_64 variants where
 the ABI doesn't impose a mandatory red zone for the stack, like on Windows
 or Xen/HaLVM. The current implementation restores the stack pointer first,
 which effectively marks the area with the saved registers as reusable.
 Later, the CPU registers are restored from this "free" area. This ordering
 happens to work by accident on operating systems that strictly adhere to
 the System V ABI, because any interrupt/signal delivery is guaranteed to
 leave the first 128 bytes past the stack pointer untouched (red zone). On
 other systems this might result in corrupted CPU registers if an
 interruption happens just after restoring the stack pointer. The red zone
 is usually only used by small leaf functions to avoid updates to the stack
 pointer and exploiting it doesn't give us any advantage in this case.

 The attached patch reorders the register access, so that the stack pointer
 is restored last. It's also shorter by one instruction.

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/10155>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list