Received: by 2002:ab2:784b:0:b0:1fd:adc2:8405 with SMTP id m11csp388223lqp; Mon, 10 Jun 2024 07:12:35 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVeBE1PGPMbcDYeefMlIuiCg6Gk4j/TWYCAGiKq3Dk3tFQJI9j6l9Qa4YZ8+rWFIUHHqrGYYZ6AGjjdGc+btUFY1QlfefoOL9Bim+0DdA== X-Google-Smtp-Source: AGHT+IG/Ag8KGXDuL0h8OT3e+Iq0LnEmWRh3auUIQCzpH+OSq5Qs9CU4lnhoNoHC60K3m1YQZwjB X-Received: by 2002:a05:6808:1289:b0:3d2:28ff:c9a0 with SMTP id 5614622812f47-3d228ffcb16mr4644468b6e.52.1718028755512; Mon, 10 Jun 2024 07:12:35 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718028755; cv=pass; d=google.com; s=arc-20160816; b=kJOY3+cTfFQaismJjYo1+Xhq6fpCmwoXczkh/4HkYCVT4rEN7PrHwLX7HU5hSbdDoA Ln9Wxuwa4fOVDUnG1b1L7BeJZ0dLeJ1xLeD5ty4FP09TPN3bVW3yyYtzlK399QNdzpuP kattBpA9aFJL1ms8HgefNACurOqh1t7zGgyWfOChFQEW8KDZU3xfx4fi2K4JC4S7QUUR 3iQ+dBVTu01KlK/+25f5xKRcM5ShBjX4W4sExuvXN70oFJ4spxQDyD++kP5ZeS08O6XX zEuFK01OohUWLFXbTv5er2ojtL8SYTgXy4mGgZBVjUhdjM0OySAoJDjAyy4K+2vZZEoy zPwA== 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=Q2BNtRklMm/oGfJO8WR6592/uoN7Ou98TXBAEZPJFRE=; fh=fEkYnOazxYMvuUTjCHl186GH+t7Y1eEfrLEhtLAzyY4=; b=VkI8xe9pO/2JrE9TD3mn85fOmBGFpuVPY8Tp/cKDi+yEcTDtvv8zThgjibC24b2VkQ 4QSXm/bb20zU+KA7xYFA6ovuZOIud45mGGgLXquHNGO8FVNiJ6ATd21qgFG4VOBbu6Z3 QS85adlC/nNLCghdnPkHlhQ3GhGcJdzBfPQQtpf3LuUVVKWi5PjeznsiQ+HU8vQ2zoQx 0u6Cv9KdlGPXxh3CG15q7RFY2XQaFiK4qQmpHf3ycBgpLrhFvwSCrEzj/VJEHEMtF5GK T1OQXnKaLXQWPfwPUKOkKP8cZnusUcUxjDYKQIfhiBdnOjhskf9MfoEozqtMJomc3FXT vyvw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@alien8.de header.s=alien8 header.b=BoYbLXII; arc=pass (i=1 spf=pass spfdomain=alien8.de dkim=pass dkdomain=alien8.de dmarc=pass fromdomain=alien8.de); spf=pass (google.com: domain of linux-kernel+bounces-208344-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-208344-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alien8.de Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id ada2fe7eead31-48c428e48d1si846903137.53.2024.06.10.07.12.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jun 2024 07:12:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-208344-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@alien8.de header.s=alien8 header.b=BoYbLXII; arc=pass (i=1 spf=pass spfdomain=alien8.de dkim=pass dkdomain=alien8.de dmarc=pass fromdomain=alien8.de); spf=pass (google.com: domain of linux-kernel+bounces-208344-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-208344-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alien8.de 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 35FC71C214C6 for ; Mon, 10 Jun 2024 14:12:35 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D4B758286B; Mon, 10 Jun 2024 14:12:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (4096-bit key) header.d=alien8.de header.i=@alien8.de header.b="BoYbLXII" Received: from mail.alien8.de (mail.alien8.de [65.109.113.108]) (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 1BBD084D2A; Mon, 10 Jun 2024 14:12:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=65.109.113.108 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718028740; cv=none; b=EOGTeN6zp3UTQ9apjUbL0WPostvRS+ORIqEzXJlAHK/upL2t7NunPCwgs7Rhzlmweytzr/jiKyzML0bH0qQ6yvlTXbUbdzpKWgskq2m+zOb+tOPhtu5OLPLa9yarWphqpRT4FsNN3N0msCJZjkRZU2bGkc21HoqWDgVljWj/iEE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718028740; c=relaxed/simple; bh=xAFr7ozPpI8DuqOfWnDR2BQJvB3UgfxfbtowfoYvgBo=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=DXLYGMAALBMLF96R8MZ6lOfsDN0zRLoL5H2yowSzOljO62hOE8pzomZpc7HH5E7Szk/F+d/lj61225SCcebma1kthq402DCEPuG54C+H3LDJ6RqZKMNxf6i6FwgSgoiVSt7DeaaJs+q32u49zWAfhtmX0T2FZ43OsXPczgdDVxg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=alien8.de; spf=pass smtp.mailfrom=alien8.de; dkim=pass (4096-bit key) header.d=alien8.de header.i=@alien8.de header.b=BoYbLXII; arc=none smtp.client-ip=65.109.113.108 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=alien8.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=alien8.de Received: from localhost (localhost.localdomain [127.0.0.1]) by mail.alien8.de (SuperMail on ZX Spectrum 128k) with ESMTP id B0F2240E0081; Mon, 10 Jun 2024 14:12:15 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at mail.alien8.de Authentication-Results: mail.alien8.de (amavisd-new); dkim=pass (4096-bit key) header.d=alien8.de Received: from mail.alien8.de ([127.0.0.1]) by localhost (mail.alien8.de [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id F7bdWQwRfOpn; Mon, 10 Jun 2024 14:12:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alien8.de; s=alien8; t=1718028731; bh=Q2BNtRklMm/oGfJO8WR6592/uoN7Ou98TXBAEZPJFRE=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=BoYbLXIII6dSl9aiajG6s2LxJqHKd/s7l4nNyqmMDOP2bRiVZ0iTtpm6TKADwME4N wArWddpsjvrLPgPDWLgD1WHJ+hzrc8JNf+qAycwhzoJS8foAdSe2txy9OMDGZUcHm9 VXMGVV67YV5l67JlWTz62j0f/j/X48QkcM2SOce1Lx5SabCRmUbdDCwM4TaYVj+DsB IyfimZsImk0SsPaX9wEmy7t8qdjzm6tD1sgGqjHbkikddhG2VzVxp9Z7byN8fNUX/z o2ZTeGehghmYIQE0Mpe14EtT3SrvVDKJPMo7B9fmwG31EQg61TzF8Y6yUvAdOmnuwz 3gkp6l9QSlCdVOtI1Z65UiJA2asaXPZnY77IctA5Pr4afwKZk1izoi0D2cRHEK8boW ssZWIP10I9eH5WW+SbVJwmVco+PtwCM77zrHbEod9tNWhxVROMjVQL6EmGdjPEDNsh PbBJMvFMyqSk0UqG4c7mgYL1rk2r96tfNdV1XZdBLlVRtEuBZDrsEUG3WFY1jrF86U AKg6f2sj+j5CmTPIdbnqquMg3c0ZhpqqGrOMI2CoylYSNwGfcBoDNfydhjQt0t2W8a 2GtecUwBf76J8YRte/zVR1Ah4b57Mno+EMfqNFUAxBWMEL+fwTulfTqdUkTXyWbfdT 8a+0+f0deAtdXSa06zIOjUxw= Received: from zn.tnic (p5de8ee85.dip0.t-ipconnect.de [93.232.238.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature ECDSA (P-256) server-digest SHA256) (No client certificate requested) by mail.alien8.de (SuperMail on ZX Spectrum 128k) with ESMTPSA id 537B840E0027; Mon, 10 Jun 2024 14:12:02 +0000 (UTC) Date: Mon, 10 Jun 2024 16:11:56 +0200 From: Borislav Petkov To: Ard Biesheuvel , Dan Williams Cc: linux-efi@vger.kernel.org, linux-kernel@vger.kernel.org, x86@kernel.org, Ard Biesheuvel , Ashish Kalra , Dave Young , Mike Rapoport Subject: Re: [PATCH] x86/efi: Free EFI memory map only when installing a new one. Message-ID: <20240610141156.GDZmcJrEi11xESpy3a@fat_crate.local> References: <20240610140932.2489527-2-ardb+git@google.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=utf-8 Content-Disposition: inline In-Reply-To: <20240610140932.2489527-2-ardb+git@google.com> + Dan because of f0ef6523475f ("efi: Fix efi_memmap_alloc() leaks") Thanks Ard. On Mon, Jun 10, 2024 at 04:09:33PM +0200, Ard Biesheuvel wrote: > From: Ard Biesheuvel > > The logic in __efi_memmap_init() is shared between two different > execution flows: > - mapping the EFI memory map early or late into the kernel VA space, so > that its entries can be accessed; > - cloning the EFI memory map in order to insert new entries that are > created as a result of creating a memory reservation > (efi_arch_mem_reserve()) > > In the former case, the underlying memory containing the kernel's view > of the EFI memory map (which may be heavily modified by the kernel > itself on x86) is not modified at all, and the only thing that changes > is the virtual mapping of this memory, which is different between early > and late boot. > > In the latter case, an entirely new allocation is created that carries a > new, updated version of the kernel's view of the EFI memory map. When > installing this new version, the old version will no longer be > referenced, and if the memory was allocated by the kernel, it will leak > unless it gets freed. > > The logic that implements this freeing currently lives on the code path > that is shared between these two use cases, but it should only apply to > the latter. So move it to the correct spot. > > Cc: Ashish Kalra > Cc: Dave Young > Cc: Mike Rapoport > Cc: Borislav Petkov > Link: https://lore.kernel.org/all/36ad5079-4326-45ed-85f6-928ff76483d3@amd.com > Signed-off-by: Ard Biesheuvel > --- > arch/x86/platform/efi/memmap.c | 5 +++++ > drivers/firmware/efi/memmap.c | 5 ----- > 2 files changed, 5 insertions(+), 5 deletions(-) > > diff --git a/arch/x86/platform/efi/memmap.c b/arch/x86/platform/efi/memmap.c > index 4ef20b49eb5e..4990244e5168 100644 > --- a/arch/x86/platform/efi/memmap.c > +++ b/arch/x86/platform/efi/memmap.c > @@ -97,6 +97,11 @@ int __init efi_memmap_install(struct efi_memory_map_data *data) > if (efi_enabled(EFI_PARAVIRT)) > return 0; > > + if (efi.memmap.flags & (EFI_MEMMAP_MEMBLOCK | EFI_MEMMAP_SLAB)) > + __efi_memmap_free(efi.memmap.phys_map, > + efi.memmap.desc_size * efi.memmap.nr_map, > + efi.memmap.flags); > + > return __efi_memmap_init(data); > } > > diff --git a/drivers/firmware/efi/memmap.c b/drivers/firmware/efi/memmap.c > index 3365944f7965..3759e95a7407 100644 > --- a/drivers/firmware/efi/memmap.c > +++ b/drivers/firmware/efi/memmap.c > @@ -51,11 +51,6 @@ int __init __efi_memmap_init(struct efi_memory_map_data *data) > return -ENOMEM; > } > > - if (efi.memmap.flags & (EFI_MEMMAP_MEMBLOCK | EFI_MEMMAP_SLAB)) > - __efi_memmap_free(efi.memmap.phys_map, > - efi.memmap.desc_size * efi.memmap.nr_map, > - efi.memmap.flags); > - > map.phys_map = data->phys_map; > map.nr_map = data->size / data->desc_size; > map.map_end = map.map + data->size; > -- > 2.45.2.505.gda0bf45e8d-goog > -- Regards/Gruss, Boris. https://people.kernel.org/tglx/notes-about-netiquette