Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp832227pxu; Mon, 23 Nov 2020 05:26:09 -0800 (PST) X-Google-Smtp-Source: ABdhPJzdTWRw/itC9mtKhszzzy1vLdzWIoPs54kn8bQtTdbVG2kwIKB6V3LVN82+nNSbWHuMTZbv X-Received: by 2002:a17:906:1408:: with SMTP id p8mr43147412ejc.548.1606137969300; Mon, 23 Nov 2020 05:26:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606137969; cv=none; d=google.com; s=arc-20160816; b=FOMGOeKWRk7pkQge6qn2/GGtQGHJ3gd5t2TIDqWklb3/kAi62Dl+VOuitSR9WrC4Nc EZoK/f/K6BTvXN9V3Zquf0RdK7zhcc8xk4v41c0hATmXZtfsqRekIRvTeLGmqQFeVNMm G7E3Qs/ruJp9GEzTszeRODM5zncqROJzvGIOti/0VckcZ49CuSFIIIcnIy5vUUh1wdUC h8r+anJ+vXuf7DBxWc6DhoAldodvJSbzjf5Qob+qEfM8xAKjpTkoF3wn90GVR8dpRCQ5 GdxGxsNzRW/OT/+x2nNwHspU33TyhNiOGQMJdk0p38cpghHLwJHSp/DldBK1AlzXt+zl VjTg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=2DszCnSIVoMNgMciB4NFSE3VEQ1896pyAXrOK2xY1h0=; b=RcWm9iNYOjZTCuesPF3CwIcANAYakPtsWBAjQ0XWLysL+SeTA7bTj0PNx5WETXPdZ1 gn4t6ICfjQc9TRuYdkjzIG6674owpQQuIu7HkoxeIWRNHQ7We2wh0Z636zZiEQqWzI3S Z3iilvAcEiK1a+Xpd8lv0A/BvCUCHwiWE3iyX+KlG/ILOrBTd7ofKcVnwrzwRv6QhDwy y+PHMRf31Tt4Zj7AKTobOZSU1vn6o1oMGuUvN4PxjwxRCF21TGv0BWt5BIZOMXTLTjRL H3eKLSmOebXsATXWFSpS0XnUw0/gRNv5ZQCEa/FeSt+UmWNdVQ7c+wAMyXIgDOX6z0/H FA5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=0ywxc6yq; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u20si6525079eje.628.2020.11.23.05.25.45; Mon, 23 Nov 2020 05:26:09 -0800 (PST) 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=@linuxfoundation.org header.s=korg header.b=0ywxc6yq; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388890AbgKWNVI (ORCPT + 99 others); Mon, 23 Nov 2020 08:21:08 -0500 Received: from mail.kernel.org ([198.145.29.99]:51154 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732120AbgKWMik (ORCPT ); Mon, 23 Nov 2020 07:38:40 -0500 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 14E312065E; Mon, 23 Nov 2020 12:38:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1606135120; bh=2FsW2JYiM5WYfvtAH7r0oJxW60XfTiC3NmMqGW7LjtM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0ywxc6yqZRDTPzxLSsUqSWIrTmVZJt8/X+vGbId8Ob4AODN27uxZ9eYC/uoENSe3K 1jpI55mtWdOVcOvcd0uuXrop1QsaPhQc1LYcbe7xlQeigSRkoVLq1SpTiN+/BxdYsy VSJF3MosgriZ+WxBeVWsnFwTk0bCaWqOODPfOZmk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Arvind Sankar , Ard Biesheuvel , Sasha Levin Subject: [PATCH 5.4 111/158] efi/x86: Free efi_pgd with free_pages() Date: Mon, 23 Nov 2020 13:22:19 +0100 Message-Id: <20201123121825.295716679@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201123121819.943135899@linuxfoundation.org> References: <20201123121819.943135899@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Arvind Sankar [ Upstream commit c2fe61d8be491ff8188edaf22e838f819999146b ] Commit d9e9a6418065 ("x86/mm/pti: Allocate a separate user PGD") changed the PGD allocation to allocate PGD_ALLOCATION_ORDER pages, so in the error path it should be freed using free_pages() rather than free_page(). Commit 06ace26f4e6f ("x86/efi: Free efi_pgd with free_pages()") fixed one instance of this, but missed another. Move the freeing out-of-line to avoid code duplication and fix this bug. Fixes: d9e9a6418065 ("x86/mm/pti: Allocate a separate user PGD") Link: https://lore.kernel.org/r/20201110163919.1134431-1-nivedita@alum.mit.edu Signed-off-by: Arvind Sankar Signed-off-by: Ard Biesheuvel Signed-off-by: Sasha Levin --- arch/x86/platform/efi/efi_64.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/arch/x86/platform/efi/efi_64.c b/arch/x86/platform/efi/efi_64.c index e39c930cfbd1e..5283978181103 100644 --- a/arch/x86/platform/efi/efi_64.c +++ b/arch/x86/platform/efi/efi_64.c @@ -217,28 +217,30 @@ int __init efi_alloc_page_tables(void) gfp_mask = GFP_KERNEL | __GFP_ZERO; efi_pgd = (pgd_t *)__get_free_pages(gfp_mask, PGD_ALLOCATION_ORDER); if (!efi_pgd) - return -ENOMEM; + goto fail; pgd = efi_pgd + pgd_index(EFI_VA_END); p4d = p4d_alloc(&init_mm, pgd, EFI_VA_END); - if (!p4d) { - free_page((unsigned long)efi_pgd); - return -ENOMEM; - } + if (!p4d) + goto free_pgd; pud = pud_alloc(&init_mm, p4d, EFI_VA_END); - if (!pud) { - if (pgtable_l5_enabled()) - free_page((unsigned long) pgd_page_vaddr(*pgd)); - free_pages((unsigned long)efi_pgd, PGD_ALLOCATION_ORDER); - return -ENOMEM; - } + if (!pud) + goto free_p4d; efi_mm.pgd = efi_pgd; mm_init_cpumask(&efi_mm); init_new_context(NULL, &efi_mm); return 0; + +free_p4d: + if (pgtable_l5_enabled()) + free_page((unsigned long)pgd_page_vaddr(*pgd)); +free_pgd: + free_pages((unsigned long)efi_pgd, PGD_ALLOCATION_ORDER); +fail: + return -ENOMEM; } /* -- 2.27.0