From nobody Fri Nov 1 10:26:40 2024 Delivered-To: importer@patchew.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 1517201571738188.40633312173634; Sun, 28 Jan 2018 20:52:51 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 62AB722344356; Sun, 28 Jan 2018 20:47:16 -0800 (PST) Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) (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 349DE2222C220 for ; Sun, 28 Jan 2018 20:47:14 -0800 (PST) Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 28 Jan 2018 20:52:47 -0800 Received: from jwang36-mobl2.ccr.corp.intel.com ([10.239.193.4]) by fmsmga008.fm.intel.com with ESMTP; 28 Jan 2018 20:52:46 -0800 X-Original-To: edk2-devel@lists.01.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; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.126; helo=mga18.intel.com; envelope-from=jian.j.wang@intel.com; receiver=edk2-devel@lists.01.org X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,429,1511856000"; d="scan'208";a="13824519" From: Jian J Wang To: edk2-devel@lists.01.org Date: Mon, 29 Jan 2018 12:52:41 +0800 Message-Id: <20180129045241.20360-1-jian.j.wang@intel.com> X-Mailer: git-send-email 2.15.1.windows.2 Subject: [edk2] [PATCH] MdeModulePkg/Core: fix guard page missing issue X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ruiyu Ni , Eric Dong , Star Zeng 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" This issue is a regression one caused by a patch at 425d25699be83c35e12df8470b827d7fbcef3bce That fix didn't take the 0 page to free into account, which still needs to call UnsetGuardPage() even no memory needs to free. The fix is just moving the calling of UnsetGuardPage() to the place right after calling AdjustMemoryF(). Cc: Ruiyu Ni Cc: Star Zeng Cc: Eric Dong Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Jian J Wang Reviewed-by: Ruiyu Ni --- MdeModulePkg/Core/Dxe/Mem/HeapGuard.c | 7 +++---- MdeModulePkg/Core/Dxe/Mem/Pool.c | 16 ++++++++-------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/MdeModulePkg/Core/Dxe/Mem/HeapGuard.c b/MdeModulePkg/Core/Dxe/= Mem/HeapGuard.c index 92753c7269..392aeb8a02 100644 --- a/MdeModulePkg/Core/Dxe/Mem/HeapGuard.c +++ b/MdeModulePkg/Core/Dxe/Mem/HeapGuard.c @@ -1135,10 +1135,6 @@ CoreConvertPagesWithGuard ( OldPages =3D NumberOfPages; =20 AdjustMemoryF (&Start, &NumberOfPages); - if (NumberOfPages =3D=3D 0) { - return EFI_SUCCESS; - } - // // It's safe to unset Guard page inside memory lock because there shou= ld // be no memory allocation occurred in updating memory page attribute = at @@ -1147,6 +1143,9 @@ CoreConvertPagesWithGuard ( // marking it usable (from non-present to present). // UnsetGuardForMemory (OldStart, OldPages); + if (NumberOfPages =3D=3D 0) { + return EFI_SUCCESS; + } } else { AdjustMemoryA (&Start, &NumberOfPages); } diff --git a/MdeModulePkg/Core/Dxe/Mem/Pool.c b/MdeModulePkg/Core/Dxe/Mem/P= ool.c index df9a1d28df..1ff2061f7f 100644 --- a/MdeModulePkg/Core/Dxe/Mem/Pool.c +++ b/MdeModulePkg/Core/Dxe/Mem/Pool.c @@ -642,15 +642,15 @@ CoreFreePoolPagesWithGuard ( NoPagesGuarded =3D NoPages; =20 AdjustMemoryF (&Memory, &NoPages); + // + // It's safe to unset Guard page inside memory lock because there should + // be no memory allocation occurred in updating memory page attribute at + // this point. And unsetting Guard page before free will prevent Guard + // page just freed back to pool from being allocated right away before + // marking it usable (from non-present to present). + // + UnsetGuardForMemory (MemoryGuarded, NoPagesGuarded); if (NoPages > 0) { - // - // It's safe to unset Guard page inside memory lock because there shou= ld - // be no memory allocation occurred in updating memory page attribute = at - // this point. And unsetting Guard page before free will prevent Guard - // page just freed back to pool from being allocated right away before - // marking it usable (from non-present to present). - // - UnsetGuardForMemory (MemoryGuarded, NoPagesGuarded); CoreFreePoolPagesI (PoolType, Memory, NoPages); } } --=20 2.14.1.windows.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel