Received: by 2002:ab2:7903:0:b0:1fb:b500:807b with SMTP id a3csp971914lqj; Mon, 3 Jun 2024 06:41:54 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUb+baCtgDj1XpSeAqbouVLkJyEJqKk2aAZ/LHn8HGWhIaxDCpPyVR9Y71Z6U3oW1k69+6x9KlIe/vUK+Ach71R/vzqfWoMmVeUl/SHxw== X-Google-Smtp-Source: AGHT+IEuvMkXvKiiCmtqYOkmWu6geNWValuZLfVnWdebsbfQ2r6jJo3r2AygFcYoFO/NBx5IwtWN X-Received: by 2002:ac8:5f46:0:b0:43e:e6e:21dd with SMTP id d75a77b69052e-43ff525aefemr100562281cf.12.1717422114254; Mon, 03 Jun 2024 06:41:54 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717422114; cv=pass; d=google.com; s=arc-20160816; b=niwG5JtxZwkziduSKvPWycY1uVw+IDflNOGz3+NhjJJEAjaPftsZVumyulXWrvwvHO xOIwGhmNM3xg0TlPZVZWkIlyVO/003M6g0y9h3o3y+YVN97NuJGab2SdliqNke7VYMwG A/nQSybd8+NqlCc5ox5UcR885fVFsmI9URLL2jJHyqUYQ+scFQCiiUpfiPaOKuOr2kyV CU8/42V269cw9hZtur7ZwS03S0QhzbXtaILkEGdU32s+Gsxx/PaWehE3ndGavKDHbWat QiA6b40A7fQCc15PLMmgI8MWQQ5NwA4Ja6lgmBUfS9vIri010uZ05PNZ0Aj7GEsvTeA1 nz4g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=gUMeLhzZ9g6W48sbpO6G2OUCkSyS4z8rOOOjvOBKWLc=; fh=PTUgNzjDBHIITauZnKBExlBjOkCl/MkQDCGc5iPmzcA=; b=Hi2KRLligMCEU4+sE89YDiGiM5iJcXWg9i6cTxiHNeKvxaoz2FZRBBRaPlckpo+xEg yokzPlcZ9w9eBCF0LhWPQwQgIQsIUKbrnG/i8PCur7JKprDgbgo3XaGjm9kZSBshhl4q ARVIVA9KbTd+VDmNicCuLXWLvu1t/TOxq2fBXz4cwTpgHeX9wEY1ZMRN0rYUuu41Y4tI IGzvH83szwb++5vAA0R7EjrNjHR++nzAu+y6jiCR3ELl3QMsUghPAvFjFtYhJ4x1sHSM gkH5x1aKkhCs4x9ljB1m7PZeuQsR3qprU8yzc/5lcQRhOfHuUkfQch5EzXGlb7k974Kf G7gQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ESftPgcR; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-199236-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-199236-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id d75a77b69052e-43ff25b6df1si86325981cf.752.2024.06.03.06.41.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Jun 2024 06:41:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-199236-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ESftPgcR; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-199236-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-199236-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id F27121C21DF8 for ; Mon, 3 Jun 2024 13:41:53 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A0B0312DD92; Mon, 3 Jun 2024 13:41:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ESftPgcR" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C18F612DD8A; Mon, 3 Jun 2024 13:41:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717422070; cv=none; b=bna4rhpjOY0Xxmaie7c0hRz0arZySf36MDU6qzBeWmXw5Cxd0ZeFbKNaVSjHuxL/TQotRf7W+ss3mPiOvX16Dzy6sBAeYd3dtDfTu1l7hXm0PFnrx1U15pk2WTmOCriskGVaWogvdocC0O1y2SSKWBqfAEYThZJb/fJTzfML0fM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717422070; c=relaxed/simple; bh=Ha1Vb6zLDIgl3FT1iTLBIO/NlIPS2ToAgX6Msao0hhY=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=sPTw9LZEEqY6LSq+6mtfwi63i9NdVNpdC+WkyNGX/zi81XvURL16KnwU0T3Lw1FflLWC4Pu/CHTjFVmykqlywkNUVJNj8XhrmNbb1ov5519TJB09Y7wdVd57BgjyrE4VsTjoSLmLrNzYSJOfzSDLb6wl1zqSHji+yxDnKNGEtKg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ESftPgcR; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id C5E95C32781; Mon, 3 Jun 2024 13:41:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1717422069; bh=Ha1Vb6zLDIgl3FT1iTLBIO/NlIPS2ToAgX6Msao0hhY=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=ESftPgcRwAW263OfIBCOhYLZOuMreNuvfXqqXkvt6Cmf7vzo5PeOYZ6DoRRNP3JZ/ lyssP0SZncpQ3xya77ugCf4jlN8PPSxFKMqvywN23AcgXS4MgFIt3AFzpnqHG4mj1C qfrjFZKJql+XdFwMAueRJ+8ZVDQa7J+DnJOZ6tD1EH+tLJyZ7R38rmczDS421jq+c/ PWNGF2/EOyVowAxI+Y9wWYMJkq7H0TD+iI17mH1o9U/MOfm2TP6nvmVx6wUKyY2wBp WlwNjnjt9JamFdbyy2R0Vk4kEIQnx47+nuTqhjSjYBgTkYWPrN2VD6hbTNUPEJW2Uj jqsetzuLS3xPQ== Date: Mon, 3 Jun 2024 16:39:10 +0300 From: Mike Rapoport To: "Kalra, Ashish" Cc: Borislav Petkov , tglx@linutronix.de, mingo@redhat.com, dave.hansen@linux.intel.com, x86@kernel.org, rafael@kernel.org, hpa@zytor.com, peterz@infradead.org, adrian.hunter@intel.com, sathyanarayanan.kuppuswamy@linux.intel.com, jun.nakajima@intel.com, rick.p.edgecombe@intel.com, thomas.lendacky@amd.com, michael.roth@amd.com, seanjc@google.com, kai.huang@intel.com, bhe@redhat.com, kirill.shutemov@linux.intel.com, bdas@redhat.com, vkuznets@redhat.com, dionnaglaze@google.com, anisinha@redhat.com, jroedel@suse.de, ardb@kernel.org, kexec@lists.infradead.org, linux-coco@lists.linux.dev, linux-kernel@vger.kernel.org Subject: Re: [PATCH v7 1/3] efi/x86: Fix EFI memory map corruption with kexec Message-ID: References: <20240528095522.509667-1-kirill.shutemov@linux.intel.com> <20240603085654.GBZl2FVjPd-gagt-UA@fat_crate.local> <8e3dfc15-f609-4839-85c7-1cc8cefd7acc@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <8e3dfc15-f609-4839-85c7-1cc8cefd7acc@amd.com> On Mon, Jun 03, 2024 at 08:06:56AM -0500, Kalra, Ashish wrote: > On 6/3/2024 3:56 AM, Borislav Petkov wrote > > > > EFI memory map and due to early allocation it uses memblock allocation. > > > > > > Later during boot, efi_enter_virtual_mode() calls kexec_enter_virtual_mode() > > > in case of a kexec-ed kernel boot. > > > > > > This function kexec_enter_virtual_mode() installs the new EFI memory map by > > > calling efi_memmap_init_late() which remaps the efi_memmap physically allocated > > > in efi_arch_mem_reserve(), but this remapping is still using memblock allocation. > > > > > > Subsequently, when memblock is freed later in boot flow, this remapped > > > efi_memmap will have random corruption (similar to a use-after-free scenario). > > > > > > The corrupted EFI memory map is then passed to the next kexec-ed kernel > > > which causes a panic when trying to use the corrupted EFI memory map. > > This sounds fishy: memblock allocated memory is not freed later in the > > boot - it remains reserved. Only free memory is freed from memblock to > > the buddy allocator. > > > > Or is the problem that memblock-allocated memory cannot be memremapped > > because *raisins*? > > This is what seems to be happening: > > efi_arch_mem_reserve() calls efi_memmap_alloc() to allocate memory for > EFI memory map and due to early allocation it uses memblock allocation. > > And later efi_enter_virtual_mode() calls kexec_enter_virtual_mode() > in case of a kexec-ed kernel boot. > > This function kexec_enter_virtual_mode() installs the new EFI memory map by > calling efi_memmap_init_late() which does memremap() on memblock-allocated memory. Does the issue happen only with SNP? I didn't really dig, but my theory would be that it has something to do with arch_memremap_can_ram_remap() in arch/x86/mm/ioremap.c > Thanks, Ashish -- Sincerely yours, Mike.