Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp16008165ybl; Tue, 31 Dec 2019 19:37:17 -0800 (PST) X-Google-Smtp-Source: APXvYqzru0+Hj/siLHgrqQpiz2JrYt6PE2cINNJQb04GD6MBlLJ8Ds4XiepnIloIAsDn41yitJPl X-Received: by 2002:a17:906:814a:: with SMTP id z10mr78757272ejw.62.1577849837176; Tue, 31 Dec 2019 19:37:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1577849837; cv=none; d=google.com; s=arc-20160816; b=NLFYfkXwKiGDwUs26QmiwyuIq+N9UaFmfUc/71YYyVR4tCNiXgvHRymrefm7OfINBF 5aXpMSibdsOTB3Z4xnu8jqdquGqv6SjrCIhS1UlnYqU0TreSytIonPJduV+ZketX+WCy IWRbSGKoqjhyMkNHtF+pOUNj6Cn/GoVw/HcF1zn8M9VOaJX1B56YkRnYtHf7uxtY9fHp eUDsJIVAkGmk0enlhjZX7jBRjw9dk0UGWICfajGvDiKDlHLO8ZFHbk24MPbd/3skjuKf zYfzoKZjxriqlyD/sUcaNOnsgvKd46NHFrqOvpiNYzrD8wRXLaPwa+7uRh838WewZhnz Kv0g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=xGzTIGJEZW1rd19x+B/i8LC/d+Fdo/UuA9DXF5ovwZU=; b=ZnASOLpBjGKWb5yolvm28ctffvshNFdghYp03cfOns21vPpDyaHjejAdwnSEaqclVd /N32xlB+iEYgMC4GfM5FrDrv5m2KJUCwFnxehymt/2nsGIXsMaYOtu+Uhy759E1bWoiA axfkGwJGSObN/8aBo3UafCzrvMbm7tlapjsGGzlhNVxNzHOpNYCwy0LzZgahNUPmjkZ7 5wz6E2D5590Sr+9f6O6kr1JWMzYk1HnhrYCGIa1Owu75tmS7TgZo+r+mr+ZW9G8FRITB n9LmJ8o/T2PV0/hAq9d2Ebr/S6O/ihEJyr1JOy5ydn+vtZBTFCCzPUw2wUe1AF2s9uBu CkEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=c6mzRu2Y; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u9si9881865edq.348.2019.12.31.19.36.52; Tue, 31 Dec 2019 19:37:17 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=c6mzRu2Y; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727142AbgAADfb (ORCPT + 99 others); Tue, 31 Dec 2019 22:35:31 -0500 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:43576 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727036AbgAADfb (ORCPT ); Tue, 31 Dec 2019 22:35:31 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1577849729; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=xGzTIGJEZW1rd19x+B/i8LC/d+Fdo/UuA9DXF5ovwZU=; b=c6mzRu2YA7y8/ZaFOUGQuMWQZ/1DjL85H7UwSqAJK2xCxN5uvxI2LtLvyowOgyOLSGzeTW T85zzhMnkNAkn9T9SxE6gg4LDjCuhFerx4kGgUsdwSt52qBFfH9EGlNUlM40ITRfPQdAF1 xRBgiv95UaxPDmas1GUDlbvsO3I7THI= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-235-roboTYx1PPClg702gfWojQ-1; Tue, 31 Dec 2019 22:35:26 -0500 X-MC-Unique: roboTYx1PPClg702gfWojQ-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 94034477; Wed, 1 Jan 2020 03:35:24 +0000 (UTC) Received: from dhcp-128-65.nay.redhat.com (ovpn-12-60.pek2.redhat.com [10.72.12.60]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2A9ED5C1D8; Wed, 1 Jan 2020 03:35:20 +0000 (UTC) Date: Wed, 1 Jan 2020 11:35:17 +0800 From: Dave Young To: Dan Williams Cc: mingo@redhat.com, Taku Izumi , Ard Biesheuvel , linux-kernel@vger.kernel.org, linux-efi@vger.kernel.org, kexec@lists.infradead.org, x86@kernel.org Subject: Re: [PATCH v2 3/4] efi: Fix efi_memmap_alloc() leaks Message-ID: <20200101033517.GB14346@dhcp-128-65.nay.redhat.com> References: <157782985777.367056.14741265874314204783.stgit@dwillia2-desk3.amr.corp.intel.com> <157782987346.367056.16932641815225610530.stgit@dwillia2-desk3.amr.corp.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <157782987346.367056.16932641815225610530.stgit@dwillia2-desk3.amr.corp.intel.com> User-Agent: Mutt/1.12.1 (2019-06-15) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Dan, On 12/31/19 at 02:04pm, Dan Williams wrote: > With efi_fake_memmap() and efi_arch_mem_reserve() the efi table may be > updated and replaced multiple times. When that happens a previous > dynamically allocated efi memory map can be garbage collected. Use the > new EFI_MEMMAP_{SLAB,MEMBLOCK} flags to detect when a dynamically > allocated memory map is being replaced. > > Cc: Taku Izumi > Cc: Ard Biesheuvel > Signed-off-by: Dan Williams > --- > drivers/firmware/efi/memmap.c | 24 ++++++++++++++++++++++++ > 1 file changed, 24 insertions(+) > > diff --git a/drivers/firmware/efi/memmap.c b/drivers/firmware/efi/memmap.c > index 2b81ee6858a9..188ab3cd5c52 100644 > --- a/drivers/firmware/efi/memmap.c > +++ b/drivers/firmware/efi/memmap.c > @@ -29,6 +29,28 @@ static phys_addr_t __init __efi_memmap_alloc_late(unsigned long size) > return PFN_PHYS(page_to_pfn(p)); > } > > +static void __init __efi_memmap_free(u64 phys, unsigned long size, unsigned long flags) > +{ > + if (WARN_ON(slab_is_available() && (flags & EFI_MEMMAP_MEMBLOCK))) > + return; > + > + if (flags & EFI_MEMMAP_MEMBLOCK) { > + memblock_free(phys, size); > + } else if (flags & EFI_MEMMAP_SLAB) { > + struct page *p = pfn_to_page(PHYS_PFN(phys)); > + unsigned int order = get_order(size); > + > + free_pages((unsigned long) page_address(p), order); > + } > +} > + > +static void __init efi_memmap_free(void) > +{ > + __efi_memmap_free(efi.memmap.phys_map, > + efi.memmap.desc_size * efi.memmap.nr_map, > + efi.memmap.flags); > +} > + > /** > * efi_memmap_alloc - Allocate memory for the EFI memory map > * @num_entries: Number of entries in the allocated map. > @@ -209,6 +231,8 @@ int __init efi_memmap_install(phys_addr_t addr, unsigned int nr_map, > data.desc_size = efi.memmap.desc_size; > flags |= efi.memmap.flags & EFI_MEMMAP_LATE; > > + efi_memmap_free(); > + > return __efi_memmap_init(&data, flags); Hmm, only free the memmap in case __efi_memmap_init succeeded.. Thanks Dave