From nobody Sat May 4 08:29:24 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1502422482188496.90370985095717; Thu, 10 Aug 2017 20:34:42 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id B7BCF21D490F8; Thu, 10 Aug 2017 20:32:19 -0700 (PDT) Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 5E12A21D490F1 for ; Thu, 10 Aug 2017 20:32:17 -0700 (PDT) Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 10 Aug 2017 20:34:37 -0700 Received: from shwdeopenpsi068.ccr.corp.intel.com ([10.239.9.12]) by orsmga001.jf.intel.com with ESMTP; 10 Aug 2017 20:34:36 -0700 X-Original-To: edk2-devel@lists.01.org X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.41,356,1498546800"; d="scan'208";a="1161532495" From: Star Zeng To: edk2-devel@lists.01.org Date: Fri, 11 Aug 2017 11:34:32 +0800 Message-Id: <1502422473-94884-2-git-send-email-star.zeng@intel.com> X-Mailer: git-send-email 2.7.0.windows.1 In-Reply-To: <1502422473-94884-1-git-send-email-star.zeng@intel.com> References: <1502422473-94884-1-git-send-email-star.zeng@intel.com> Subject: [edk2] [PATCH 1/2] MdeModulePkg DxeCore: Fix double free pages on LoadImage failure path X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Liming Gao , Star Zeng , Andrew Fish MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" https://bugzilla.tianocore.org/show_bug.cgi?id=3D667 reported there is double free pages on LoadImage failure path. CoreLoadPeImage() ... return EFI_SUCCESS; Done: // // Free memory. // if (DstBufAlocated) { CoreFreePages (Image->ImageContext.ImageAddress, Image->NumberOfPages); } ... CoreUnloadAndCloseImage() ... if ((Image->ImageBasePage !=3D 0) && FreePage) { CoreFreePages (Image->ImageBasePage, Image->NumberOfPages); } ... This patch is to follow the suggestion at https://lists.01.org/pipermail/edk2-devel/2017-August/013112.html to set Image->ImageContext.ImageAddress and Image->ImageBasePage to 0 after the free in CoreLoadPeImage(). Cc: Liming Gao Cc: Andrew Fish Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Star Zeng Reviewed-by: Liming Gao --- MdeModulePkg/Core/Dxe/Image/Image.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/MdeModulePkg/Core/Dxe/Image/Image.c b/MdeModulePkg/Core/Dxe/Im= age/Image.c index 03e979a60409..4e22aa6dc7e3 100644 --- a/MdeModulePkg/Core/Dxe/Image/Image.c +++ b/MdeModulePkg/Core/Dxe/Image/Image.c @@ -788,6 +788,8 @@ Done: =20 if (DstBufAlocated) { CoreFreePages (Image->ImageContext.ImageAddress, Image->NumberOfPages); + Image->ImageContext.ImageAddress =3D 0; + Image->ImageBasePage =3D 0; } =20 if (Image->ImageContext.FixupData !=3D NULL) { --=20 2.7.0.windows.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Sat May 4 08:29:24 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1502422484404125.25491395294443; Thu, 10 Aug 2017 20:34:44 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id EC67021D490FB; Thu, 10 Aug 2017 20:32:19 -0700 (PDT) Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 860FE21D490EF for ; Thu, 10 Aug 2017 20:32:18 -0700 (PDT) Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 10 Aug 2017 20:34:38 -0700 Received: from shwdeopenpsi068.ccr.corp.intel.com ([10.239.9.12]) by orsmga001.jf.intel.com with ESMTP; 10 Aug 2017 20:34:37 -0700 X-Original-To: edk2-devel@lists.01.org X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.41,356,1498546800"; d="scan'208";a="1161532500" From: Star Zeng To: edk2-devel@lists.01.org Date: Fri, 11 Aug 2017 11:34:33 +0800 Message-Id: <1502422473-94884-3-git-send-email-star.zeng@intel.com> X-Mailer: git-send-email 2.7.0.windows.1 In-Reply-To: <1502422473-94884-1-git-send-email-star.zeng@intel.com> References: <1502422473-94884-1-git-send-email-star.zeng@intel.com> Subject: [edk2] [PATCH 2/2] MdeModulePkg DxeCore: Enhance "ConvertPages: Incompatible memory types" X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Liming Gao , Star Zeng , Andrew Fish MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" When double free pages by FreePages() or allocate allocated pages by AllocatePages() with AllocateAddress type, the code will print debug message "ConvertPages: Incompatible memory types", but the debug message is not very obvious for the error paths by FreePages() or AllocatePages(). Refer https://lists.01.org/pipermail/edk2-devel/2017-August/013075.html for the discussion. This patch is to enhance the debug message for the error paths by FreePages() or AllocatePages. Cc: Liming Gao Cc: Andrew Fish Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Star Zeng Reviewed-by: Liming Gao --- MdeModulePkg/Core/Dxe/Mem/Page.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/MdeModulePkg/Core/Dxe/Mem/Page.c b/MdeModulePkg/Core/Dxe/Mem/P= age.c index 3b3b9a8131a2..a142c79ee2ca 100644 --- a/MdeModulePkg/Core/Dxe/Mem/Page.c +++ b/MdeModulePkg/Core/Dxe/Mem/Page.c @@ -1,7 +1,7 @@ /** @file UEFI Memory page management functions. =20 -Copyright (c) 2007 - 2016, Intel Corporation. All rights reserved.
+Copyright (c) 2007 - 2017, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD = License which accompanies this distribution. The full text of the license may be = found at @@ -788,7 +788,12 @@ CoreConvertPagesEx ( // Debug code - verify conversion is allowed // if (!(NewType =3D=3D EfiConventionalMemory ? 1 : 0) ^ (Entry->Type = =3D=3D EfiConventionalMemory ? 1 : 0)) { - DEBUG ((DEBUG_ERROR | DEBUG_PAGE, "ConvertPages: Incompatible memo= ry types\n")); + DEBUG ((DEBUG_ERROR | DEBUG_PAGE, "ConvertPages: Incompatible memo= ry types, ")); + if (Entry->Type =3D=3D EfiConventionalMemory) { + DEBUG ((DEBUG_ERROR | DEBUG_PAGE, "the pages to free have been f= reed\n")); + } else { + DEBUG ((DEBUG_ERROR | DEBUG_PAGE, "the pages to allocate have be= en allocated\n")); + } return EFI_NOT_FOUND; } =20 --=20 2.7.0.windows.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel