From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.24; helo=mga09.intel.com; envelope-from=jian.j.wang@intel.com; receiver=edk2-devel@lists.01.org Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) (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 28CA42265A330 for ; Wed, 11 Apr 2018 01:38:55 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 11 Apr 2018 01:38:55 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.48,435,1517904000"; d="scan'208";a="32503847" Received: from shwdeopenpsi777.ccr.corp.intel.com ([10.239.158.27]) by orsmga007.jf.intel.com with ESMTP; 11 Apr 2018 01:38:54 -0700 From: Jian J Wang To: edk2-devel@lists.01.org Cc: Star Zeng , Eric Dong , Jiewen Yao , Ruiyu Ni Date: Wed, 11 Apr 2018 16:38:45 +0800 Message-Id: <20180411083846.7300-2-jian.j.wang@intel.com> X-Mailer: git-send-email 2.16.2.windows.1 In-Reply-To: <20180411083846.7300-1-jian.j.wang@intel.com> References: <20180411083846.7300-1-jian.j.wang@intel.com> Subject: [PATCH 1/2] MdeModulePkg/DxeCore: add sanity check for SetMemoryAttributes X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 11 Apr 2018 08:38:55 -0000 Heap Guard feature needs enough memory and paging to work. Otherwise calling SetMemoryAttributes to change page attribute will fail. This patch add necessary check of result of calling SetMemoryAttributes. This can help users to debug their problem in enabling this feature. Cc: Star Zeng Cc: Eric Dong Cc: Jiewen Yao Cc: Ruiyu Ni Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Jian J Wang --- MdeModulePkg/Core/Dxe/Mem/HeapGuard.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/MdeModulePkg/Core/Dxe/Mem/HeapGuard.c b/MdeModulePkg/Core/Dxe/Mem/HeapGuard.c index fd6aeee8da..9d765c98f6 100644 --- a/MdeModulePkg/Core/Dxe/Mem/HeapGuard.c +++ b/MdeModulePkg/Core/Dxe/Mem/HeapGuard.c @@ -580,6 +580,8 @@ SetGuardPage ( IN EFI_PHYSICAL_ADDRESS BaseAddress ) { + EFI_STATUS Status; + if (gCpu == NULL) { return; } @@ -593,7 +595,8 @@ SetGuardPage ( // Note: This might overwrite other attributes needed by other features, // such as NX memory protection. // - gCpu->SetMemoryAttributes (gCpu, BaseAddress, EFI_PAGE_SIZE, EFI_MEMORY_RP); + Status = gCpu->SetMemoryAttributes (gCpu, BaseAddress, EFI_PAGE_SIZE, EFI_MEMORY_RP); + ASSERT_EFI_ERROR (Status); mOnGuarding = FALSE; } @@ -613,6 +616,7 @@ UnsetGuardPage ( ) { UINT64 Attributes; + EFI_STATUS Status; if (gCpu == NULL) { return; @@ -638,7 +642,8 @@ UnsetGuardPage ( // such as memory protection (NX). Please make sure they are not enabled // at the same time. // - gCpu->SetMemoryAttributes (gCpu, BaseAddress, EFI_PAGE_SIZE, Attributes); + Status = gCpu->SetMemoryAttributes (gCpu, BaseAddress, EFI_PAGE_SIZE, Attributes); + ASSERT_EFI_ERROR (Status); mOnGuarding = FALSE; } -- 2.16.2.windows.1