Re: [RFC] x86: xsave/xrstor support, ucontext_t extensions

!MAILaRCHIVE_VOTE_RePLACE
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: Roland McGrath <roland@...>
Cc: Suresh Siddha <suresh.b.siddha@...>, Mikael Pettersson <mikpe@...>, Andi Kleen <andi@...>, <mingo@...>, <tglx@...>, <torvalds@...>, <akpm@...>, <drepper@...>, <Hongjiu.lu@...>, <linux-kernel@...>, <arjan@...>, <rmk+lkml@...>, <dan@...>, <asit.k.mallick@...>
Date: Friday, May 23, 2008 - 12:57 pm

Roland McGrath wrote:

Okay.  Pretty much what it comes down to is that there is no ideal 
solution.  Thus, we're trying to explore the potential tradeoffs.  The 
scenario you describe above will crash horribly for a non-FXSAVE aware 
application running on an FXSAVE kernel.

Either way, there has been a long time since, and new bad applications 
have obviously emerged, partially "assisted" by our propensity to not 
document, and the deep gulf between our kernel and userspace developers.

Let's try another strawman on for size:

- It is clear it is desirable not just for the frame itself but for the 
fpstate to be self-describing.

- Thus, let's put a magic cookie in one of the reserved fields at the 
end of the FXSAVE region, and make sure it is long enough to be unlikely 
to pop up randomly; as well as another magic cookie outside the FXSAVE 
region.

- The signal delivery code will write the cookie (or zero, for !XSAVE) 
regardless of any crap ptrace might have written into it.

- We will ALSO set bit 0 in uc_flags for RT sigframes as an additional 
assurance.

- We will introduce at least a 32-bit field for future use, to be 
written unconditionally zero for now.  We don't want to have to go 
through this particular torture yet again.

- The XSAVE state beyond the FXSAVE region needs to be self-describing. 
  This may mean adding information not provided by the hardware. 
Furthermore, it must be possible for userspace to know the length of the 
frame, even if it doesn't understand its detailed contents.


None of this is foolproof on older kernels -- there simply *IS* no 
option for older kernels that is 100% guaranteed, thanks to various 
assumptions made and design decisions taken over the years.  There are a 
couple of failure scenarious here:

- XSAVE-aware application running on pre-XSAVE kernel:

   Such an application will be aware that the XSAVE information may not
   exist, but needs to know (with high probability) that it isn't
   present.  We have CPUID.OSXSAVE, the uc_flags bit, and the magic
   cookie to help here.  ptrace can introduce the magic cookie falsely
   into the state, but ptrace can introduce all kinds of failures;
   either way they would (probablistically) not see the *second*
   cookie.

   The fact that 64-bit kernels don't clear the unused fields is of
   less concern, since 64-bit kernels get the uc_flags field.

- Pre-XSAVE application running on XSAVE kernel with XSAVE enabled:

   Here we have the potential for all kinds of corrupt state, including
   userspace trying to save away the state and load it later, not
   knowing the proper size of it.  Worse, some sick person might try to
   save and restore state from different hosts, with potential for
   all kinds of mayhem.

   The saved state, if copied from the original, would contain the first
   cookie but not the second cookie.

   Again, the use of two cookies here adds some amount of assurance;
   but that again amounts to probabilistic failure detection.  However,
   I personally don't see any way to avoid that scenario at all.

	-hpa
--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[RFC] x86: xsave/xrstor support, ucontext_t extensions, Suresh Siddha, (Mon May 12, 9:10 pm)
Re: [RFC] x86: xsave/xrstor support, ucontext_t extensions, Mikael Pettersson, (Fri May 16, 9:26 am)
Re: [RFC] x86: xsave/xrstor support, ucontext_t extensions, Mikael Pettersson, (Mon May 19, 10:52 am)
Re: [RFC] x86: xsave/xrstor support, ucontext_t extensions, H. Peter Anvin, (Tue May 20, 10:55 am)
Re: [RFC] x86: xsave/xrstor support, ucontext_t extensions, Roland McGrath, (Tue May 20, 4:10 pm)
Re: [RFC] x86: xsave/xrstor support, ucontext_t extensions, H. Peter Anvin, (Wed May 21, 8:05 pm)
Re: [RFC] x86: xsave/xrstor support, ucontext_t extensions, Roland McGrath, (Wed May 21, 8:47 pm)
Re: [RFC] x86: xsave/xrstor support, ucontext_t extensions, Mikael Pettersson, (Tue May 20, 9:19 am)
Re: [RFC] x86: xsave/xrstor support, ucontext_t extensions, H. Peter Anvin, (Tue May 20, 10:58 am)
Re: [RFC] x86: xsave/xrstor support, ucontext_t extensions, Mikael Pettersson, (Tue May 20, 11:20 am)
Re: [RFC] x86: xsave/xrstor support, ucontext_t extensions, H. Peter Anvin, (Tue May 20, 1:57 pm)
Re: [RFC] x86: xsave/xrstor support, ucontext_t extensions, H. Peter Anvin, (Wed May 21, 8:28 pm)
Re: [RFC] x86: xsave/xrstor support, ucontext_t extensions, Mikael Pettersson, (Thu May 22, 4:57 am)
Re: [RFC] x86: xsave/xrstor support, ucontext_t extensions, H. Peter Anvin, (Thu May 22, 5:02 pm)
Re: [RFC] x86: xsave/xrstor support, ucontext_t extensions, Mikael Pettersson, (Thu May 22, 6:36 pm)
Re: [RFC] x86: xsave/xrstor support, ucontext_t extensions, H. Peter Anvin, (Thu May 22, 8:33 pm)
Re: [RFC] x86: xsave/xrstor support, ucontext_t extensions, H. Peter Anvin, (Thu May 22, 10:27 pm)
Re: [RFC] x86: xsave/xrstor support, ucontext_t extensions, Roland McGrath, (Thu May 22, 9:33 pm)
Re: [RFC] x86: xsave/xrstor support, ucontext_t extensions, H. Peter Anvin, (Fri May 23, 12:57 pm)
Re: [RFC] x86: xsave/xrstor support, ucontext_t extensions, Mikael Pettersson, (Thu May 22, 6:15 pm)
Re: [RFC] x86: xsave/xrstor support, ucontext_t extensions, H. Peter Anvin, (Thu May 22, 8:32 pm)
Re: [RFC] x86: xsave/xrstor support, ucontext_t extensions, H. Peter Anvin, (Thu May 22, 5:34 pm)
Re: [RFC] x86: xsave/xrstor support, ucontext_t extensions, H. Peter Anvin, (Thu May 22, 10:45 pm)
Re: [RFC] x86: xsave/xrstor support, ucontext_t extensions, Mikael Pettersson, (Fri May 23, 7:46 am)
Re: [RFC] x86: xsave/xrstor support, ucontext_t extensions, Roland McGrath, (Thu May 22, 10:12 pm)
Re: [RFC] x86: xsave/xrstor support, ucontext_t extensions, H. Peter Anvin, (Thu May 22, 10:49 pm)
x86: xsave/xrstor support; ucontext_t extensions, H. Peter Anvin, (Thu Jun 5, 8:28 pm)
Re: x86: xsave/xrstor support; ucontext_t extensions, Suresh Siddha, (Fri Jun 6, 4:14 pm)
Re: x86: xsave/xrstor support; ucontext_t extensions, H. Peter Anvin, (Fri Jun 6, 7:03 pm)
Re: [RFC] x86: xsave/xrstor support, ucontext_t extensions, Mikael Pettersson, (Thu May 22, 6:22 pm)
Re: [RFC] x86: xsave/xrstor support, ucontext_t extensions, Roland McGrath, (Wed May 21, 8:53 pm)
Re: [RFC] x86: xsave/xrstor support, ucontext_t extensions, Mikael Pettersson, (Thu May 22, 4:49 am)
Re: [RFC] x86: xsave/xrstor support, ucontext_t extensions, H. Peter Anvin, (Wed May 21, 9:38 pm)
Re: [RFC] x86: xsave/xrstor support, ucontext_t extensions, Roland McGrath, (Thu May 22, 2:40 am)
Re: [RFC] x86: xsave/xrstor support, ucontext_t extensions, H. Peter Anvin, (Thu May 22, 3:18 am)
Re: [RFC] x86: xsave/xrstor support, ucontext_t extensions, H. Peter Anvin, (Tue May 20, 1:59 pm)
Re: [RFC] x86: xsave/xrstor support, ucontext_t extensions, Mikael Pettersson, (Tue May 20, 4:58 am)
Re: [RFC] x86: xsave/xrstor support, ucontext_t extensions, H. Peter Anvin, (Mon May 19, 12:29 pm)
Re: [RFC] x86: xsave/xrstor support, ucontext_t extensions, Suresh Siddha, (Mon May 19, 12:57 pm)
Re: [RFC] x86: xsave/xrstor support, ucontext_t extensions, H. Peter Anvin, (Mon May 19, 1:45 pm)