Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp1796877pxb; Fri, 22 Oct 2021 07:51:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwYCaBo/HzpRT1XoF09oVItZRoYzhAzrAXwUCSOmfNxtvfacXEHPytwK5hREuO6aGTOoKO/ X-Received: by 2002:a17:90b:1d04:: with SMTP id on4mr461460pjb.68.1634914291183; Fri, 22 Oct 2021 07:51:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634914291; cv=none; d=google.com; s=arc-20160816; b=ajdn4m2VoyzmU7YGfQlDO/cHfgybDwWyKyS61aT+OPhhs3DWbQf/ey77wCq7jpMTjq AIgGZiBmfQVjPSl2L0aJqEONetXJEOqJyuW+Eip9h+UrzXWzb/l9as5knkN0/He8Fx/i LH4wEIpnJt64dwAZRRbrHuEcyHJA2kxhaqm3sF3Huj6wP6A+AsXyupRettPdBVUUMzl/ FDHBOcXIqpEQZVQbQWmS88dXN4mjHKFeYAQ+s89fgRi/H2IiGgde3Ajep3gwEA9ay8Y5 BpqkpVVm80dW5o7Zcgjtz5QzUu5WTKMFQUanGPYvCKzedMszafRSxLL03Wo36GFTCh42 Becw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=0enC/o0gJI2REk0OYmieBaaErnWk6CTBKfbz0VmCLtk=; b=J3eBNRREl7/Dl/E/b6vCd31ISufquNd/NIN3hQWJDL11+65bnnN+MLreOaBuoMAG5G Zjj8gWG5+yeWxqICiS6w/CDGJW9+dbm/cwyQSsSBWuxOFjlooGD5w/qks2E/fTa8fIYE 2URk9KBI62zIUJ4xAMidSsuPgIGmIJdkrn/64uxuuUfoMtqbj7/jtdggCXwmJj0jiD30 irDGB1IBx1dPa6fHbgaF0NszuFyt6ctVBx1otZ/Vwy7tTtKiVW19hSWaiAw8JSNsht4p jFvzPnzQlRU81tXsMnmINE9Q5unjk06BmuDSCObz8mLztHQYUTttNjZDWUo4J/stmshb fGXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=sHa0yAkh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id nt21si15581774pjb.178.2021.10.22.07.51.18; Fri, 22 Oct 2021 07:51:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=sHa0yAkh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233285AbhJVOvC (ORCPT + 99 others); Fri, 22 Oct 2021 10:51:02 -0400 Received: from mail.kernel.org ([198.145.29.99]:37188 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233269AbhJVOvB (ORCPT ); Fri, 22 Oct 2021 10:51:01 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id C4D9861213; Fri, 22 Oct 2021 14:48:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1634914123; bh=D7YiPLV5BWiABRuEJr1caIsL8j1JOmX/Rlc+/V7Zfbg=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=sHa0yAkhFeH0wZLIgP+ZI7JoVDO5tgcdXSeghzQbQK7n/dxfo66MH/BjWZ/GwXYsY 1lmUGj33d6m9ZyKJVNRgOnfGQf6661uVPXTNjyiQVYf2SEd27wMupbpxE5k1cNCRpM Y7TGbObewe6NQWRkG0jIaqgVqtC6/OyDZcfm2mUoRVAe6k8KDCEsK8TLhu0x5e9V1T FZLL09ifW1DG2+8UYL7E9psr+jwEKpcegXa58VLfO9xnwswOxplLAXtGgmLgW5fSFr 8ELzw3slNSG/FZEpwOCBZtuoxL1qo3u6UCLPNYi3DMe4PCTM2GBqA7Bf4muiaG2gcg N136D/QBNtSLQ== Received: by mail-oi1-f169.google.com with SMTP id v77so5329881oie.1; Fri, 22 Oct 2021 07:48:43 -0700 (PDT) X-Gm-Message-State: AOAM530FzKiqbAFhZAcm+0Y5Kh40LEFcrBIquFq8dAmAW//06pwQdR0l JzAGEUch7G6/YKkutBhKiWvdu8rqA6nFDzYeQFE= X-Received: by 2002:aca:4bc4:: with SMTP id y187mr92315oia.174.1634914123022; Fri, 22 Oct 2021 07:48:43 -0700 (PDT) MIME-Version: 1.0 References: <9d9ca009-93c5-acc3-7445-d514c7878478@amd.com> In-Reply-To: <9d9ca009-93c5-acc3-7445-d514c7878478@amd.com> From: Ard Biesheuvel Date: Fri, 22 Oct 2021 16:48:31 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] x86/sme: Explicitly map new EFI memmap table as encrypted To: Tom Lendacky Cc: Linux Kernel Mailing List , X86 ML , linux-efi , platform-driver-x86@vger.kernel.org, Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , Darren Hart , Andy Shevchenko , Matt Fleming , "# 3.4.x" Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 21 Oct 2021 at 15:21, Tom Lendacky wrote: > > On 10/20/21 1:02 PM, Tom Lendacky wrote: > > Reserving memory using efi_mem_reserve() calls into the x86 > > efi_arch_mem_reserve() function. This function will insert a new EFI > > memory descriptor into the EFI memory map representing the area of > > memory to be reserved and marking it as EFI runtime memory. As part > > of adding this new entry, a new EFI memory map is allocated and mapped. > > The mapping is where a problem can occur. This new memory map is mapped > > using early_memremap() and generally mapped encrypted, unless the new > > memory for the mapping happens to come from an area of memory that is > > marked as EFI_BOOT_SERVICES_DATA memory. This bit already sounds dodgy to me. At runtime, anything provided by the firmware that needs to be mapped unencrypted should be identifiable as such, regardless of the memory type. So why is there a special case for BS data? > > In this case, the new memory will > > be mapped unencrypted. However, during replacement of the old memory map, > > efi_mem_type() is disabled, so the new memory map will now be long-term > > mapped encrypted (in efi.memmap), resulting in the map containing invalid > > data and causing the kernel boot to crash. > > > > Since it is known that the area will be mapped encrypted going forward, > > explicitly map the new memory map as encrypted using early_memremap_prot(). > > > > Cc: # 4.14.x > > Fixes: 8f716c9b5feb ("x86/mm: Add support to access boot related data in the clear") > > Signed-off-by: Tom Lendacky > > --- > > arch/x86/platform/efi/quirks.c | 3 ++- > > 1 file changed, 2 insertions(+), 1 deletion(-) > > > > diff --git a/arch/x86/platform/efi/quirks.c b/arch/x86/platform/efi/quirks.c > > index b15ebfe40a73..b0b848d6933a 100644 > > --- a/arch/x86/platform/efi/quirks.c > > +++ b/arch/x86/platform/efi/quirks.c > > @@ -277,7 +277,8 @@ void __init efi_arch_mem_reserve(phys_addr_t addr, u64 size) > > return; > > } > > > > - new = early_memremap(data.phys_map, data.size); > > + new = early_memremap_prot(data.phys_map, data.size, > > + pgprot_val(pgprot_encrypted(FIXMAP_PAGE_NORMAL))); > > I should really have a comment above this as to why this version of the > early_memremap is being used. > > Let me add that (and maybe work on the commit message a bit) and submit a > v2. But I'll hold off for a bit in case any discussion comes about. > For the [backported] change itself (with the comment added) Acked-by: Ard Biesheuvel but I'd still like to understand if we can improve the situation with BS data.