From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) (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 9F34521F077A2 for ; Wed, 20 Sep 2017 22:17:49 -0700 (PDT) Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 20 Sep 2017 22:20:56 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.42,423,1500966000"; d="scan'208";a="154308650" Received: from jwang36-mobl2.ccr.corp.intel.com ([10.239.192.31]) by fmsmga006.fm.intel.com with ESMTP; 20 Sep 2017 22:20:54 -0700 From: Jian J Wang To: edk2-devel@lists.01.org Cc: Star Zeng , Eric Dong , Laszlo Ersek , Jiewen Yao , Michael Kinney , Jordan Justen , Ayellet Wolman Date: Thu, 21 Sep 2017 13:20:32 +0800 Message-Id: <20170921052032.13652-7-jian.j.wang@intel.com> X-Mailer: git-send-email 2.14.1.windows.1 In-Reply-To: <20170921052032.13652-1-jian.j.wang@intel.com> References: <20170921052032.13652-1-jian.j.wang@intel.com> Subject: [PATCH v2 6/6] OvmfPkg/QemuVideoDxe: Bypass NULL pointer detection during VBE SHIM installing 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: , X-List-Received-Date: Thu, 21 Sep 2017 05:17:49 -0000 QemuVideoDxe driver will install VBE SHIM into page 0. If NULL pointer detection is enabled, this driver will fail to load. NULL pointer detection bypassing code is added to prevent such problem during boot. Please note that Windows 7 will try to access VBE SHIM during boot if it's installed, and then cause boot failure. This can be fixed by setting BIT7 of PcdNullPointerDetectionPropertyMask to disable NULL pointer detection after EndOfDxe. As far as we know, there's no other OSs has such issue. Cc: Star Zeng Cc: Eric Dong Cc: Laszlo Ersek Cc: Jiewen Yao Cc: Michael Kinney Cc: Jordan Justen Cc: Ayellet Wolman Suggested-by: Ayellet Wolman Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Jian J Wang --- OvmfPkg/QemuVideoDxe/QemuVideoDxe.inf | 2 ++ OvmfPkg/QemuVideoDxe/VbeShim.c | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/OvmfPkg/QemuVideoDxe/QemuVideoDxe.inf b/OvmfPkg/QemuVideoDxe/QemuVideoDxe.inf index 577e07b0a8..8078232ded 100644 --- a/OvmfPkg/QemuVideoDxe/QemuVideoDxe.inf +++ b/OvmfPkg/QemuVideoDxe/QemuVideoDxe.inf @@ -67,6 +67,7 @@ UefiBootServicesTableLib UefiDriverEntryPoint UefiLib + DxeServicesTableLib [Protocols] gEfiDriverSupportedEfiVersionProtocolGuid # PROTOCOL ALWAYS_PRODUCED @@ -77,3 +78,4 @@ [Pcd] gOptionRomPkgTokenSpaceGuid.PcdDriverSupportedEfiVersion gUefiOvmfPkgTokenSpaceGuid.PcdOvmfHostBridgePciDevId + gEfiMdeModulePkgTokenSpaceGuid.PcdNullPointerDetectionPropertyMask diff --git a/OvmfPkg/QemuVideoDxe/VbeShim.c b/OvmfPkg/QemuVideoDxe/VbeShim.c index e45a08e887..c3fb6d8d3c 100644 --- a/OvmfPkg/QemuVideoDxe/VbeShim.c +++ b/OvmfPkg/QemuVideoDxe/VbeShim.c @@ -21,10 +21,13 @@ WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. **/ +#include #include #include #include #include +#include + #include #include "Qemu.h" @@ -74,11 +77,21 @@ InstallVbeShim ( UINT8 *Ptr; UINTN Printed; VBE_MODE_INFO *VbeModeInfo; + EFI_STATUS Status; Segment0 = 0x00000; SegmentC = 0xC0000; SegmentF = 0xF0000; + // + // Disable NULL pointer detection temporarily. Otherwise the installation + // will fail due to the lack of memory access right. + // + if ((PcdGet8 (PcdNullPointerDetectionPropertyMask) & (BIT0|BIT7)) == BIT0) { + Status = gDS->SetMemorySpaceAttributes (0, EFI_PAGES_TO_SIZE (1), 0); + ASSERT_EFI_ERROR (Status); + } + // // Attempt to cover the real mode IVT with an allocation. This is a UEFI // driver, hence the arch protocols have been installed previously. Among @@ -304,5 +317,14 @@ InstallVbeShim ( Int0x10->Segment = (UINT16) ((UINT32)SegmentC >> 4); Int0x10->Offset = (UINT16) ((UINTN) (VbeModeInfo + 1) - SegmentC); + // + // Get NULL pointer detection back + // + if ((PcdGet8 (PcdNullPointerDetectionPropertyMask) & (BIT0|BIT7)) == BIT0) { + Status = gDS->SetMemorySpaceAttributes (0, EFI_PAGES_TO_SIZE(1), + EFI_MEMORY_RP); + ASSERT_EFI_ERROR (Status); + } + DEBUG ((EFI_D_INFO, "%a: VBE shim installed\n", __FUNCTION__)); } -- 2.14.1.windows.1