From nobody Thu Dec 26 13:38:18 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 1505971259028918.5315556246887; Wed, 20 Sep 2017 22:20:59 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 6735021F077AA; Wed, 20 Sep 2017 22:17:51 -0700 (PDT) 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 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 X-Original-To: edk2-devel@lists.01.org X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.42,423,1500966000"; d="scan'208";a="154308650" From: Jian J Wang To: edk2-devel@lists.01.org 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: [edk2] [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: , Cc: Eric Dong , Jordan Justen , Jiewen Yao , Ayellet Wolman , Michael Kinney , Laszlo Ersek , 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" 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/Q= emuVideoDxe.inf index 577e07b0a8..8078232ded 100644 --- a/OvmfPkg/QemuVideoDxe/QemuVideoDxe.inf +++ b/OvmfPkg/QemuVideoDxe/QemuVideoDxe.inf @@ -67,6 +67,7 @@ UefiBootServicesTableLib UefiDriverEntryPoint UefiLib + DxeServicesTableLib =20 [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. **/ =20 +#include #include #include #include #include +#include + #include =20 #include "Qemu.h" @@ -74,11 +77,21 @@ InstallVbeShim ( UINT8 *Ptr; UINTN Printed; VBE_MODE_INFO *VbeModeInfo; + EFI_STATUS Status; =20 Segment0 =3D 0x00000; SegmentC =3D 0xC0000; SegmentF =3D 0xF0000; =20 + // + // Disable NULL pointer detection temporarily. Otherwise the installation + // will fail due to the lack of memory access right. + // + if ((PcdGet8 (PcdNullPointerDetectionPropertyMask) & (BIT0|BIT7)) =3D=3D= BIT0) { + Status =3D 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 =3D (UINT16) ((UINT32)SegmentC >> 4); Int0x10->Offset =3D (UINT16) ((UINTN) (VbeModeInfo + 1) - SegmentC); =20 + // + // Get NULL pointer detection back + // + if ((PcdGet8 (PcdNullPointerDetectionPropertyMask) & (BIT0|BIT7)) =3D=3D= BIT0) { + Status =3D 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__)); } --=20 2.14.1.windows.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel