[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Setting constant-time mode CPU flag


  • To: Demi Marie Obenour <demi@xxxxxxxxxxxxxxxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Wed, 14 Sep 2022 08:44:25 +0200
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=HYaNcawrhpuZ47FaJSjbasxEWLPRosz4mIU8FFPRdNk=; b=BHqXAAEhVzTsHSL5te+hK0td2LG8oEGWKaqZuq21ewH4qx1Nkc2O5BAjqPw9sEUX4XOUVfr/rs9FRpSnbEKsVRWE8Njs7JJZdmyj+LQbHCs/wYJu79/R6e14iRmf9XZYGAr/SS/H8m46RMXcklPCya5JjGZtb4edDeVH/6ukK4XI6CJ5SCXf6hZLS/bQXojnWzEBvtj3lIrcDBDE9EVqzJuBWz3/qbcAB6briep8mbNRTDVWeWfCzFp4D9W9Sqp+/HQpcqvINeaR4ZL5liSzS9LrneHTrkpv5NVn/Qe33hNYHlM6Q3HKk12XfpXrhIcbIv3sDuUUGBfpravhVC0acA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=efQVeguR8UUiN4yv05XBSv6+aX+8EEQ4CBU3e+cP+1GlcQPAerNvcnmJ79pUBaIl1YXP2XoggrUgA2QlYvTqIBgnH3u1cLSfelw2U3OIRjazEA6Vlw+07xhARLkTgr1DglWpknBv/EZ/Mu1np5DDbTvtmzWfEKJZjKUZ9WwVhw1xnTETfSOVBQWRXu3QXgrrh4foBfhgorxpWHxa4Bo0sbvZDMFPGGI6Snmb42RYUFWHMJ5Yyh38pIiNyG0cXSpt+fN8xhFKO8EG8z8y00RJVxOa+CiRBR4d+OsFLnLxnBXPVQUh1nhnQh7xh2p54XnDm8HeRCPiZB3jZuGeDzMNQA==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com;
  • Cc: Marek Marczykowski-Górecki <marmarek@xxxxxxxxxxxxxxxxxxxxxx>, Simon Gaiser <simon@xxxxxxxxxxxxxxxxxxxxxx>, Xen developer discussion <xen-devel@xxxxxxxxxxxxxxxxxxxx>, Andrew Cooper <Andrew.Cooper3@xxxxxxxxxx>
  • Delivery-date: Wed, 14 Sep 2022 06:44:35 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 14.09.2022 08:40, Demi Marie Obenour wrote:
> On Wed, Sep 14, 2022 at 08:36:02AM +0200, Jan Beulich wrote:
>> On 13.09.2022 19:22, Demi Marie Obenour wrote:
>>> On Tue, Sep 13, 2022 at 04:47:24PM +0200, Jan Beulich wrote:
>>>> On 13.09.2022 16:22, Demi Marie Obenour wrote:
>>>>> On Tue, Sep 06, 2022 at 10:01:00AM +0000, Andrew Cooper wrote:
>>>>>> On 06/09/2022 10:52, Jan Beulich wrote:
>>>>>>> On 02.09.2022 04:05, Demi Marie Obenour wrote:
>>>>>>>> On Intel chips (Ice Lake and later) and ARM64, a bit needs to be set in
>>>>>>>> a CPU register to enforce constant-time execution.  Linux plans to set
>>>>>>>> this bit by default; Xen should do the same.  See
>>>>>>>> https://lore.kernel.org/lkml/YwgCrqutxmX0W72r@xxxxxxxxx/T/ for details.
>>>>>>>> I recommend setting the bit unconditionally and ignoring guest attempts
>>>>>>>> to change it.
>>>>>>> I don't think we ought to set it by default; I can see reasons why 
>>>>>>> kernels
>>>>>>> may want to set it by default (providing a way to turn it off). In Xen
>>>>>>> what I think we need is exposure of the bit to be guest-controllable.
>>>>>>
>>>>>> We absolutely should not have it set by default.  It's a substantial
>>>>>> overhead for something that is only applicable to code which otherwise
>>>>>> crafted to be constant-time.
>>>>>
>>>>> Either Xen needs to set the bit by default, or guests need to both know
>>>>> the bit needs to be set and be able set it.  Otherwise code that *is*
>>>>> intended to be constant-time has no way to protect itself.
>>>>>
>>>>>> As for why Xen doesn't enumerate/virtualise it, that's because
>>>>>> virtualising MSR_ARCH_CAPS for guests is still not working yet, so the
>>>>>> feature can't be enumerated yet even if we did support context switching 
>>>>>> it.
>>>>>
>>>>> Intel and ARM64 guarantee that CPUs that do not enumerate this flag
>>>>> behave as if it is set unconditionally.
>>>>
>>>> I'm not qualified to talk about the Arm side, but may I ask what you've
>>>> derived this statement from for Intel? The doc page referenced by the
>>>> link you did provide (still in context above) specifically further links
>>>> to a page listing instruction with data operand independent timing. All
>>>> other instructions, as I conclude, have variable timing unless the bit
>>>> in ARCH_CAPS enumerates DOITM and then the new MSR bit (of the same name)
>>>> is set.
>>>
>>> My understanding is that only instructions in the constant-time subset
>>> are ever guaranteed to be constant time.
>>
>> Hmm, yes, I did overlook respective wording in the doc.
>>
>>>  On architectures where DOITM
>>> is not enumerated, this guarantee is unconditional.
>>
>> I have to admit I'm suspicious of this "guarantee".
> 
> Do you mean that previous CPUs had a vulnerability that has no fix?

I'm not sure I'd call it a vulnerability, but at least if going back far
enough in history I think you'll find insns on the list which don't have
invariant timing. Like with other documentation on e.g. speculation
issues I take it that Intel simply doesn't consider sufficiently old
CPUs relevant anymore for such new documents.

>>>  On architectures
>>> where DOITM is enumerated, this guarantee only holds when DOITM is set.
>>> Therefore, it is critical that on CPUs that enumerate DOITM, Xen does
>>> one of the following:
>>>
>>> - Ensure that all vCPUs enumerate DOITM, and virtualize the DOITM MSR
>>>   bit for use by guests.
>>>
>>> - Set DOITM by default.
>>>
>>> Since Xen does not support virtualizing MSR_ARCH_CAPS, vCPUs cannot
>>> enumerate DOITM.  Therefore, the only secure option is to set DOITM by
>>> default, so that guests do not need to be aware of it.
>>
>> I can see where you're coming from, but I also agree with Andrew that
>> the resulting loss of performance is a counter-indication to making
>> this the (universal) default. What I could see us doing is make this
>> both Kconfig and command line controllable.
> 
> How large is the loss of performance?

I have no (practical) way to know.

Jan

>  Linux seems to be setting the
> flag unconditionally, so I think my point about guests needing to be
> able to ensure the flag is set stands.  The default can be changed once
> Xen gets support for virtualizing the bit properly, but until then
> unconditionally setting DOITM seems to be the only safe option.




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.