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

Re: [PATCH v2 9/9] x86/shadow: harden shadow_size()


  • To: Andrew Cooper <Andrew.Cooper3@xxxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Thu, 12 Jan 2023 10:47:22 +0100
  • 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=a+eX77cSMdawL4nZwmXFSn5kJuDxSijDU8TSMLh4aOU=; b=Vj2T75Y6kJC8vFFoWvW1lPJX8fARo2Gwy46zGK7ECriCfIw+btZzog4YY1ar0dOuK+loyDnucw/7rc/SXieSdigHiXP6/AJ9SvBEKz07ff7anp9D1Iwx26VIgR7XUyDCGKdC7uenOafgYLvB6CjEpuv9kifpkA3wo219QTi/B+pHsZpNMXH41qBfYwxJ+rb0LJW0bRVwBq3FRsuLwsJZ+Q22Z5thoBLBs/F1+Ov5ZEklGz5sfpduQoFX6jZDnUC5uSEAJnoAIQqgGOJ5qEMu/LMR+5QCQZ83km4J9GXme/j27RX1FSPCryZ1Ic2ln1JWQZfh0fSeiOTbJUBFwBtpDw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=U3kU3/K17peqCx/MgJ7ZCFWAjEM+gleocgwPRMQS8WgxMZgR8WDXu+VGKxRQCJbqcmK7Zjzco3KcNGmN9vwpgsCiujqs6/wz1yMSYUoilw5Md6Ovi0UzPC9deIfWJUVD2eCzNjjUg0C8OBHtp5OnsOc2ITnhHCKWJ9MMsStbHNg7VyrVH8xp0yM6XXY0oxTpdQd3RxvZvV7rmne+8MiHykGlPP08Fcks7lWjIzFjIqoCzrr+SlHSANwFPDF4ZV+QO/2A/qekOHUWM7hQJXaiiIiBFgAnfzVSpzHOgKuw5qlBGDOxolJq7OUZb3mdU+YGn9vszEPE45j3tx5ni1PxrQ==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com;
  • Cc: Wei Liu <wl@xxxxxxx>, Roger Pau Monne <roger.pau@xxxxxxxxxx>, "Tim (Xen.org)" <tim@xxxxxxx>, George Dunlap <George.Dunlap@xxxxxxxxxx>, "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • Delivery-date: Thu, 12 Jan 2023 09:47:34 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 12.01.2023 00:15, Andrew Cooper wrote:
> On 11/01/2023 1:57 pm, Jan Beulich wrote:
>> Make HVM=y release build behavior prone against array overrun, by
>> (ab)using array_access_nospec(). This is in particular to guard against
>> e.g. SH_type_unused making it here unintentionally.
>>
>> Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>
>> ---
>> v2: New.
>>
>> --- a/xen/arch/x86/mm/shadow/private.h
>> +++ b/xen/arch/x86/mm/shadow/private.h
>> @@ -27,6 +27,7 @@
>>  // been included...
>>  #include <asm/page.h>
>>  #include <xen/domain_page.h>
>> +#include <xen/nospec.h>
>>  #include <asm/x86_emulate.h>
>>  #include <asm/hvm/support.h>
>>  #include <asm/atomic.h>
>> @@ -368,7 +369,7 @@ shadow_size(unsigned int shadow_type)
>>  {
>>  #ifdef CONFIG_HVM
>>      ASSERT(shadow_type < ARRAY_SIZE(sh_type_to_size));
>> -    return sh_type_to_size[shadow_type];
>> +    return array_access_nospec(sh_type_to_size, shadow_type);
> 
> I don't think this is warranted.
> 
> First, if the commit message were accurate, then it's a problem for all
> arrays of size SH_type_unused, yet you've only adjusted a single instance.

Because I think the risk is higher here than for other arrays. In
other cases we have suitable build-time checks (HASH_CALLBACKS_CHECK()
in particular) which would trip upon inappropriate use of one of the
types which are aliased to SH_type_unused when !HVM.

> Secondly, if it were reliably 16 then we could do the basically-free
> "type &= 15;" modification.  (It appears my change to do this
> automatically hasn't been taken yet.), but we'll end up with lfence
> variation here.

How could anything be "reliably 16"? Such enums can change at any time:
They did when making HVM types conditional, and they will again when
adding types needed for 5-level paging.

> But the value isn't attacker controlled.  shadow_type always comes from
> Xen's metadata about the guest, not the guest itself.  So I don't see
> how this can conceivably be a speculative issue even in principle.

I didn't say anything about there being a speculative issue here. It
is for this very reason that I wrote "(ab)using".

Jan



 


Rackspace

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