From nobody Thu Dec 26 01:34:39 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 1507558669049191.99871989724477; Mon, 9 Oct 2017 07:17:49 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 1FBF321E78211; Mon, 9 Oct 2017 07:14:11 -0700 (PDT) Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) (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 4F3B621E78211 for ; Mon, 9 Oct 2017 07:14:09 -0700 (PDT) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 09 Oct 2017 07:17:36 -0700 Received: from sunyanwa-mobl1.ccr.corp.intel.com (HELO jwang36-MOBL2.ccr.corp.intel.com) ([10.255.25.15]) by fmsmga002.fm.intel.com with ESMTP; 09 Oct 2017 07:17:34 -0700 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=192.55.52.93; helo=mga11.intel.com; envelope-from=jian.j.wang@intel.com; receiver=edk2-devel@lists.01.org X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.42,500,1500966000"; d="scan'208";a="1228751043" From: Jian J Wang To: edk2-devel@lists.01.org Date: Mon, 9 Oct 2017 22:17:21 +0800 Message-Id: <20171009141722.992-6-jian.j.wang@intel.com> X-Mailer: git-send-email 2.14.1.windows.1 In-Reply-To: <20171009141722.992-1-jian.j.wang@intel.com> References: <20171009141722.992-1-jian.j.wang@intel.com> Subject: [edk2] [PATCH v4 5/6] IntelFrameworkModulePkg/Csm: Add code to bypass NULL pointer detection 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: Michael Kinney , Ayellet Wolman , Jiewen Yao , 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" Legacy has to access interrupt vector, BDA, etc. located in memory between 0-4095. To allow as much code as possible to be monitored by NULL pointer detection, we add code to temporarily disable this feature right before those memory access and enable it again afterwards. Cc: Star Zeng Cc: Eric Dong Cc: Jiewen Yao Cc: Michael Kinney Cc: Ayellet Wolman Suggested-by: Ayellet Wolman Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Jian J Wang --- .../Csm/BiosThunk/KeyboardDxe/BiosKeyboard.c | 101 ++++++++++++++ .../Csm/BiosThunk/KeyboardDxe/BiosKeyboard.h | 2 + .../Csm/BiosThunk/KeyboardDxe/KeyboardDxe.inf | 2 + .../Csm/LegacyBiosDxe/LegacyBda.c | 4 + .../Csm/LegacyBiosDxe/LegacyBios.c | 152 +++++++++++++++++= ++++ .../Csm/LegacyBiosDxe/LegacyBiosDxe.inf | 2 + .../Csm/LegacyBiosDxe/LegacyBiosInterface.h | 18 +++ .../Csm/LegacyBiosDxe/LegacyBootSupport.c | 23 +++- .../Csm/LegacyBiosDxe/LegacyPci.c | 17 ++- IntelFrameworkModulePkg/Csm/LegacyBiosDxe/Thunk.c | 27 +++- 10 files changed, 338 insertions(+), 10 deletions(-) diff --git a/IntelFrameworkModulePkg/Csm/BiosThunk/KeyboardDxe/BiosKeyboard= .c b/IntelFrameworkModulePkg/Csm/BiosThunk/KeyboardDxe/BiosKeyboard.c index 7308523ad8..d2224a20aa 100644 --- a/IntelFrameworkModulePkg/Csm/BiosThunk/KeyboardDxe/BiosKeyboard.c +++ b/IntelFrameworkModulePkg/Csm/BiosThunk/KeyboardDxe/BiosKeyboard.c @@ -1732,6 +1732,98 @@ CheckKeyboardConnect ( } } =20 +/** + Disable NULL pointer detection +*/ +VOID +DisableNullDetection ( + VOID + ) +{ + EFI_STATUS Status; + EFI_GCD_MEMORY_SPACE_DESCRIPTOR Desc; + + if ((PcdGet8 (PcdNullPointerDetectionPropertyMask) & BIT0) =3D=3D 0) { + return; + } + + // + // Check current capabilities and attributes + // + Status =3D gDS->GetMemorySpaceDescriptor (0, &Desc); + ASSERT_EFI_ERROR (Status); + + // + // Try to add EFI_MEMORY_RP support if necessary + // + if ((Desc.Capabilities & EFI_MEMORY_RP) =3D=3D 0) { + Desc.Capabilities |=3D EFI_MEMORY_RP; + Status =3D gDS->SetMemorySpaceCapabilities (0, EFI_PAGES_TO_SIZE(1), + Desc.Capabilities); + ASSERT_EFI_ERROR (Status); + if (EFI_ERROR (Status)) { + return; + } + } + + // + // Don't bother if EFI_MEMORY_RP is already cleared. + // + if ((Desc.Attributes & EFI_MEMORY_RP) !=3D 0) { + Desc.Attributes &=3D ~EFI_MEMORY_RP; + Status =3D gDS->SetMemorySpaceAttributes (0, EFI_PAGES_TO_SIZE(1), + Desc.Attributes); + ASSERT_EFI_ERROR (Status); + } else { + DEBUG ((DEBUG_WARN, "!!! Page 0 is supposed to be disabled !!!\r\n")); + } +} + +/** + Enable NULL pointer detection +*/ +VOID +EnableNullDetection ( + VOID + ) +{ + EFI_STATUS Status; + EFI_GCD_MEMORY_SPACE_DESCRIPTOR Desc; + + if ((PcdGet8 (PcdNullPointerDetectionPropertyMask) & BIT0) =3D=3D 0) { + return; + } + + // + // Check current capabilities and attributes + // + Status =3D gDS->GetMemorySpaceDescriptor (0, &Desc); + ASSERT_EFI_ERROR (Status); + + // + // Try to add EFI_MEMORY_RP support if necessary + // + if ((Desc.Capabilities & EFI_MEMORY_RP) =3D=3D 0) { + Desc.Capabilities |=3D EFI_MEMORY_RP; + Status =3D gDS->SetMemorySpaceCapabilities (0, EFI_PAGES_TO_SIZE(1), + Desc.Capabilities); + ASSERT_EFI_ERROR (Status); + if (EFI_ERROR (Status)) { + return; + } + } + + // + // Don't bother if EFI_MEMORY_RP is already set. + // + if ((Desc.Attributes & EFI_MEMORY_RP) =3D=3D 0) { + Desc.Attributes |=3D EFI_MEMORY_RP; + Status =3D gDS->SetMemorySpaceAttributes (0, EFI_PAGES_TO_SIZE(1), + Desc.Attributes); + ASSERT_EFI_ERROR (Status); + } +} + /** Timer event handler: read a series of key stroke from 8042 and put them into memory key buffer.=20 @@ -1839,6 +1931,11 @@ BiosKeyboardTimerHandler ( // 0 Right Shift pressed =20 =20 + // + // Disable NULL pointer detection temporarily + // + DisableNullDetection (); + // // Clear the CTRL and ALT BDA flag // @@ -1916,6 +2013,10 @@ BiosKeyboardTimerHandler ( KbFlag1 &=3D ~0x0C; =20 *((UINT8 *) (UINTN) 0x417) =3D KbFlag1;=20 =20 + // + // Restore NULL pointer detection + // + EnableNullDetection (); =20 // // Output EFI input key and shift/toggle state diff --git a/IntelFrameworkModulePkg/Csm/BiosThunk/KeyboardDxe/BiosKeyboard= .h b/IntelFrameworkModulePkg/Csm/BiosThunk/KeyboardDxe/BiosKeyboard.h index 0bf28ea140..c64ec0095e 100644 --- a/IntelFrameworkModulePkg/Csm/BiosThunk/KeyboardDxe/BiosKeyboard.h +++ b/IntelFrameworkModulePkg/Csm/BiosThunk/KeyboardDxe/BiosKeyboard.h @@ -18,6 +18,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER= EXPRESS OR IMPLIED. =20 =20 #include +#include =20 #include #include @@ -33,6 +34,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER= EXPRESS OR IMPLIED. #include #include #include +#include #include #include #include diff --git a/IntelFrameworkModulePkg/Csm/BiosThunk/KeyboardDxe/KeyboardDxe.= inf b/IntelFrameworkModulePkg/Csm/BiosThunk/KeyboardDxe/KeyboardDxe.inf index 4d4536466c..596f4ced44 100644 --- a/IntelFrameworkModulePkg/Csm/BiosThunk/KeyboardDxe/KeyboardDxe.inf +++ b/IntelFrameworkModulePkg/Csm/BiosThunk/KeyboardDxe/KeyboardDxe.inf @@ -60,6 +60,7 @@ DebugLib BaseLib PcdLib + DxeServicesTableLib =20 [Protocols] gEfiIsaIoProtocolGuid ## TO_START @@ -73,6 +74,7 @@ =20 [Pcd] gEfiMdeModulePkgTokenSpaceGuid.PcdFastPS2Detection ## S= OMETIMES_CONSUMES + gEfiMdeModulePkgTokenSpaceGuid.PcdNullPointerDetectionPropertyMask ## C= ONSUMES =20 [UserExtensions.TianoCore."ExtraFiles"] KeyboardDxeExtra.uni diff --git a/IntelFrameworkModulePkg/Csm/LegacyBiosDxe/LegacyBda.c b/IntelF= rameworkModulePkg/Csm/LegacyBiosDxe/LegacyBda.c index c45d5d4c3e..c6670febee 100644 --- a/IntelFrameworkModulePkg/Csm/LegacyBiosDxe/LegacyBda.c +++ b/IntelFrameworkModulePkg/Csm/LegacyBiosDxe/LegacyBda.c @@ -34,6 +34,8 @@ LegacyBiosInitBda ( BDA_STRUC *Bda; UINT8 *Ebda; =20 + DisableNullDetection (); + Bda =3D (BDA_STRUC *) ((UINTN) 0x400); Ebda =3D (UINT8 *) ((UINTN) 0x9fc00); =20 @@ -62,5 +64,7 @@ LegacyBiosInitBda ( =20 *Ebda =3D 0x01; =20 + EnableNullDetection (); + return EFI_SUCCESS; } diff --git a/IntelFrameworkModulePkg/Csm/LegacyBiosDxe/LegacyBios.c b/Intel= FrameworkModulePkg/Csm/LegacyBiosDxe/LegacyBios.c index 3ead2d9828..3176a989f6 100644 --- a/IntelFrameworkModulePkg/Csm/LegacyBiosDxe/LegacyBios.c +++ b/IntelFrameworkModulePkg/Csm/LegacyBiosDxe/LegacyBios.c @@ -40,6 +40,7 @@ VOID *mRuntimeSmbiosEntryPoint =3D NULL; EFI_PHYSICAL_ADDRESS mReserveSmbiosEntryPoint =3D 0; EFI_PHYSICAL_ADDRESS mStructureTableAddress =3D 0; UINTN mStructureTablePages =3D 0; +BOOLEAN mEndOfDxe =3D FALSE; =20 /** Do an AllocatePages () of type AllocateMaxAddress for EfiBootServicesCode @@ -765,6 +766,135 @@ InstallSmbiosEventCallback ( } } =20 +/** + Callback function to toggle EndOfDxe status. NULL pointer detection needs + this status to decide if it's necessary to change attributes of page 0. + + @param Event Event whose notification function is being invo= ked. + @param Context The pointer to the notification function's cont= ext, + which is implementation-dependent. + +**/ +VOID +EFIAPI +ToggleEndOfDxeStatus ( + IN EFI_EVENT Event, + IN VOID *Context + ) +{ + mEndOfDxe =3D TRUE; + return; +} + +// +// Legacy BIOS needs to access memory between 0-4095, which will cause page +// fault exception if NULL pointer detection mechanism is enabled. Followi= ng +// functions can be used to disable/enable NULL pointer detection before/a= fter +// accessing those memory. +// + +/** + Enable NULL pointer detection +*/ +VOID +EnableNullDetection ( + VOID + ) +{ + EFI_STATUS Status; + EFI_GCD_MEMORY_SPACE_DESCRIPTOR Desc; + + if (((PcdGet8 (PcdNullPointerDetectionPropertyMask) & BIT0) =3D=3D 0) + || + ((mEndOfDxe =3D=3D TRUE) && + ((PcdGet8 (PcdNullPointerDetectionPropertyMask) & (BIT7|BIT0)) + =3D=3D (BIT7|BIT0))) + ) { + return; + } + + // + // Check current capabilities and attributes + // + Status =3D gDS->GetMemorySpaceDescriptor (0, &Desc); + ASSERT_EFI_ERROR (Status); + + // + // Try to add EFI_MEMORY_RP support if necessary + // + if ((Desc.Capabilities & EFI_MEMORY_RP) =3D=3D 0) { + Desc.Capabilities |=3D EFI_MEMORY_RP; + Status =3D gDS->SetMemorySpaceCapabilities (0, EFI_PAGES_TO_SIZE(1), + Desc.Capabilities); + ASSERT_EFI_ERROR (Status); + if (EFI_ERROR (Status)) { + return; + } + } + + // + // Don't bother if EFI_MEMORY_RP is already set. + // + if ((Desc.Attributes & EFI_MEMORY_RP) =3D=3D 0) { + Desc.Attributes |=3D EFI_MEMORY_RP; + Status =3D gDS->SetMemorySpaceAttributes (0, EFI_PAGES_TO_SIZE(1), + Desc.Attributes); + ASSERT_EFI_ERROR (Status); + } +} + +/** + Disable NULL pointer detection +*/ +VOID +DisableNullDetection ( + VOID + ) +{ + EFI_STATUS Status; + EFI_GCD_MEMORY_SPACE_DESCRIPTOR Desc; + + if (((PcdGet8 (PcdNullPointerDetectionPropertyMask) & BIT0) =3D=3D 0) + || + ((mEndOfDxe =3D=3D TRUE) && + ((PcdGet8 (PcdNullPointerDetectionPropertyMask) & (BIT7|BIT0)) + =3D=3D (BIT7|BIT0))) + ) { + return; + } + + // + // Check current capabilities and attributes + // + Status =3D gDS->GetMemorySpaceDescriptor (0, &Desc); + ASSERT_EFI_ERROR (Status); + + // + // Try to add EFI_MEMORY_RP support if necessary + // + if ((Desc.Capabilities & EFI_MEMORY_RP) =3D=3D 0) { + Desc.Capabilities |=3D EFI_MEMORY_RP; + Status =3D gDS->SetMemorySpaceCapabilities (0, EFI_PAGES_TO_SIZE(1), + Desc.Capabilities); + ASSERT_EFI_ERROR (Status); + if (EFI_ERROR (Status)) { + return; + } + } + + // + // Don't bother if EFI_MEMORY_RP is already cleared. + // + if ((Desc.Attributes & EFI_MEMORY_RP) !=3D 0) { + Desc.Attributes &=3D ~EFI_MEMORY_RP; + Status =3D gDS->SetMemorySpaceAttributes (0, EFI_PAGES_TO_SIZE(1), + Desc.Attributes); + ASSERT_EFI_ERROR (Status); + } else { + DEBUG ((DEBUG_WARN, "!!! Page 0 is supposed to be disabled !!!\r\n")); + } +} + /** Install Driver to produce Legacy BIOS protocol. =20 @@ -802,6 +932,7 @@ LegacyBiosInstall ( UINT64 Length; UINT8 *SecureBoot; EFI_EVENT InstallSmbiosEvent; + EFI_EVENT EndOfDxeEvent; =20 // // Load this driver's image to memory @@ -964,8 +1095,10 @@ LegacyBiosInstall ( // Initialize region from 0x0000 to 4k. This initializes interrupt vector // range. // + DisableNullDetection (); gBS->SetMem ((VOID *) ClearPtr, 0x400, INITIAL_VALUE_BELOW_1K); ZeroMem ((VOID *) ((UINTN)ClearPtr + 0x400), 0xC00); + EnableNullDetection (); =20 // // Allocate pages for OPROM usage @@ -1104,12 +1237,17 @@ LegacyBiosInstall ( // // Save Unexpected interrupt vector so can restore it just prior to boot // + DisableNullDetection (); + BaseVectorMaster =3D (UINT32 *) (sizeof (UINT32) * PROTECTED_MODE_BASE_V= ECTOR_MASTER); Private->BiosUnexpectedInt =3D BaseVectorMaster[0]; IntRedirCode =3D (UINT32) (UINTN) Private->IntThunk->InterruptRedirectio= nCode; for (Index =3D 0; Index < 8; Index++) { BaseVectorMaster[Index] =3D (EFI_SEGMENT (IntRedirCode + Index * 4) <<= 16) | EFI_OFFSET (IntRedirCode + Index * 4); } + + EnableNullDetection (); + // // Save EFI value // @@ -1133,6 +1271,20 @@ LegacyBiosInstall ( ); ASSERT_EFI_ERROR (Status); =20 =20 + // + // Create callback to update status of EndOfDxe, which is needed by NULL + // pointer detection + // + Status =3D gBS->CreateEventEx ( + EVT_NOTIFY_SIGNAL, + TPL_NOTIFY, + ToggleEndOfDxeStatus, + NULL, + &gEfiEndOfDxeEventGroupGuid, + &EndOfDxeEvent + ); + ASSERT_EFI_ERROR (Status); + // // Make a new handle and install the protocol // diff --git a/IntelFrameworkModulePkg/Csm/LegacyBiosDxe/LegacyBiosDxe.inf b/= IntelFrameworkModulePkg/Csm/LegacyBiosDxe/LegacyBiosDxe.inf index 48473a0713..6efc7f36ae 100644 --- a/IntelFrameworkModulePkg/Csm/LegacyBiosDxe/LegacyBiosDxe.inf +++ b/IntelFrameworkModulePkg/Csm/LegacyBiosDxe/LegacyBiosDxe.inf @@ -108,6 +108,7 @@ gEfiDiskInfoIdeInterfaceGuid ## SOMETIMES_CONSUMES ##GU= ID #Used in LegacyBiosBuildIdeData() to assure device is a disk gEfiSmbiosTableGuid ## SOMETIMES_CONSUMES ##Sy= stemTable gEfiLegacyBiosGuid ## SOMETIMES_CONSUMES ##GU= ID #Used in LegacyBiosInstallVgaRom() to locate handle buffer + gEfiEndOfDxeEventGroupGuid ## CONSUMES =20 [Guids.IA32] gEfiAcpi20TableGuid ## SOMETIMES_CONSUMES ##Sy= stemTable @@ -147,6 +148,7 @@ gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdHighPmmMemorySize = ## CONSUMES gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdOpromReservedMemoryBase = ## CONSUMES gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdOpromReservedMemorySize = ## CONSUMES + gEfiMdeModulePkgTokenSpaceGuid.PcdNullPointerDetectionPropertyMask = ## CONSUMES =20 [Depex] gEfiLegacyRegion2ProtocolGuid AND gEfiLegacyInterruptProtocolGuid AND gE= fiLegacyBiosPlatformProtocolGuid AND gEfiLegacy8259ProtocolGuid AND gEfiGen= ericMemTestProtocolGuid AND gEfiCpuArchProtocolGuid AND gEfiTimerArchProtoc= olGuid AND gEfiVariableWriteArchProtocolGuid diff --git a/IntelFrameworkModulePkg/Csm/LegacyBiosDxe/LegacyBiosInterface.= h b/IntelFrameworkModulePkg/Csm/LegacyBiosDxe/LegacyBiosInterface.h index fe9dd7463a..20dfef3fec 100644 --- a/IntelFrameworkModulePkg/Csm/LegacyBiosDxe/LegacyBiosInterface.h +++ b/IntelFrameworkModulePkg/Csm/LegacyBiosDxe/LegacyBiosInterface.h @@ -509,6 +509,8 @@ extern BBS_TABLE *mBbsTable; =20 extern EFI_GENERIC_MEMORY_TEST_PROTOCOL *gGenMemoryTest; =20 +extern BOOLEAN mEndOfDxe; + #define PORT_70 0x70 #define PORT_71 0x71 =20 @@ -1542,4 +1544,20 @@ LegacyBiosInstallVgaRom ( IN LEGACY_BIOS_INSTANCE *Private ); =20 +/** + Enable NULL pointer detection +*/ +VOID +EnableNullDetection ( + VOID + ); + +/** + Disable NULL pointer detection +*/ +VOID +DisableNullDetection ( + VOID + ); + #endif diff --git a/IntelFrameworkModulePkg/Csm/LegacyBiosDxe/LegacyBootSupport.c = b/IntelFrameworkModulePkg/Csm/LegacyBiosDxe/LegacyBootSupport.c index 1e098b3726..c2ac69ce69 100644 --- a/IntelFrameworkModulePkg/Csm/LegacyBiosDxe/LegacyBootSupport.c +++ b/IntelFrameworkModulePkg/Csm/LegacyBiosDxe/LegacyBootSupport.c @@ -1073,8 +1073,10 @@ GenericLegacyBoot ( // Use 182/10 to avoid floating point math. // LocalTime =3D (LocalTime * 182) / 10; + DisableNullDetection (); BdaPtr =3D (UINT32 *) (UINTN)0x46C; *BdaPtr =3D LocalTime; + EnableNullDetection (); =20 // // Shadow PCI ROMs. We must do this near the end since this will kick @@ -1320,6 +1322,7 @@ GenericLegacyBoot ( // set of TIANO vectors) or takes it over. // // + DisableNullDetection (); BaseVectorMaster =3D (UINT32 *) (sizeof (UINT32) * PROTECTED_MODE_BASE= _VECTOR_MASTER); for (Index =3D 0; Index < 8; Index++) { Private->ThunkSavedInt[Index] =3D BaseVectorMaster[Index]; @@ -1327,6 +1330,7 @@ GenericLegacyBoot ( BaseVectorMaster[Index] =3D (UINT32) (Private->BiosUnexpectedInt); } } + EnableNullDetection (); =20 ZeroMem (&Regs, sizeof (EFI_IA32_REGISTER_SET)); Regs.X.AX =3D Legacy16Boot; @@ -1340,10 +1344,12 @@ GenericLegacyBoot ( 0 ); =20 + DisableNullDetection (); BaseVectorMaster =3D (UINT32 *) (sizeof (UINT32) * PROTECTED_MODE_BASE= _VECTOR_MASTER); for (Index =3D 0; Index < 8; Index++) { BaseVectorMaster[Index] =3D Private->ThunkSavedInt[Index]; } + EnableNullDetection (); } Private->LegacyBootEntered =3D TRUE; if ((mBootMode =3D=3D BOOT_LEGACY_OS) || (mBootMode =3D=3D BOOT_UNCONVEN= TIONAL_DEVICE)) { @@ -1731,9 +1737,11 @@ LegacyBiosBuildE820 ( // // First entry is 0 to (640k - EBDA) // + DisableNullDetection (); E820Table[0].BaseAddr =3D 0; E820Table[0].Length =3D (UINT64) ((*(UINT16 *) (UINTN)0x40E) << 4); E820Table[0].Type =3D EfiAcpiAddressRangeMemory; + EnableNullDetection (); =20 // // Second entry is (640k - EBDA) to 640k @@ -1967,6 +1975,8 @@ LegacyBiosCompleteBdaBeforeBoot ( UINT16 MachineConfig; DEVICE_PRODUCER_DATA_HEADER *SioPtr; =20 + DisableNullDetection (); + Bda =3D (BDA_STRUC *) ((UINTN) 0x400); MachineConfig =3D 0; =20 @@ -2025,6 +2035,8 @@ LegacyBiosCompleteBdaBeforeBoot ( MachineConfig =3D (UINT16) (MachineConfig + 0x00 + 0x02 + (SioPtr-= >MousePresent * 0x04)); Bda->MachineConfig =3D MachineConfig; =20 + EnableNullDetection (); + return EFI_SUCCESS; } =20 @@ -2049,15 +2061,20 @@ LegacyBiosUpdateKeyboardLedStatus ( UINT8 LocalLeds; EFI_IA32_REGISTER_SET Regs; =20 - Bda =3D (BDA_STRUC *) ((UINTN) 0x400); - Private =3D LEGACY_BIOS_INSTANCE_FROM_THIS (This); + + DisableNullDetection (); + + Bda =3D (BDA_STRUC *) ((UINTN) 0x400); LocalLeds =3D Leds; Bda->LedStatus =3D (UINT8) ((Bda->LedStatus &~0x07) | LocalLeds); LocalLeds =3D (UINT8) (LocalLeds << 4); Bda->ShiftStatus =3D (UINT8) ((Bda->ShiftStatus &~0x70) | LocalLeds); LocalLeds =3D (UINT8) (Leds & 0x20); Bda->KeyboardStatus =3D (UINT8) ((Bda->KeyboardStatus &~0x20) | LocalLed= s); + + EnableNullDetection (); + // // Call into Legacy16 code to allow it to do any processing // @@ -2102,7 +2119,9 @@ LegacyBiosCompleteStandardCmosBeforeBoot ( // to large capacity drives // CMOS 14 =3D BDA 40:10 plus bit 3(display enabled) // + DisableNullDetection (); Bda =3D (UINT8)(*((UINT8 *)((UINTN)0x410)) | BIT3); + EnableNullDetection (); =20 // // Force display enabled diff --git a/IntelFrameworkModulePkg/Csm/LegacyBiosDxe/LegacyPci.c b/IntelF= rameworkModulePkg/Csm/LegacyBiosDxe/LegacyPci.c index 8ffdf0c1ff..d38cef3e33 100644 --- a/IntelFrameworkModulePkg/Csm/LegacyBiosDxe/LegacyPci.c +++ b/IntelFrameworkModulePkg/Csm/LegacyBiosDxe/LegacyPci.c @@ -2279,6 +2279,7 @@ LegacyBiosInstallRom ( UINTN Function; EFI_IA32_REGISTER_SET Regs; UINT8 VideoMode; + UINT8 OldVideoMode; EFI_TIME BootTime; UINT32 *BdaPtr; UINT32 LocalTime; @@ -2299,6 +2300,7 @@ LegacyBiosInstallRom ( Device =3D 0; Function =3D 0; VideoMode =3D 0; + OldVideoMode =3D 0; PhysicalAddress =3D 0; MaxRomAddr =3D PcdGet32 (PcdEndOpromShadowAddress); =20 @@ -2401,6 +2403,8 @@ LegacyBiosInstallRom ( // 2. BBS compliants drives will not change 40:75 until boot time. // 3. Onboard IDE controllers will change 40:75 // + DisableNullDetection (); + LocalDiskStart =3D (UINT8) ((*(UINT8 *) ((UINTN) 0x475)) + 0x80); if ((Private->Disk4075 + 0x80) < LocalDiskStart) { // @@ -2426,6 +2430,9 @@ LegacyBiosInstallRom ( // VideoMode =3D *(UINT8 *) ((UINTN) (0x400 + BDA_VIDEO_MODE)); } + + EnableNullDetection (); + // // Notify the platform that we are about to scan the ROM // @@ -2466,9 +2473,11 @@ LegacyBiosInstallRom ( // Multiply result by 18.2 for number of ticks since midnight. // Use 182/10 to avoid floating point math. // + DisableNullDetection (); LocalTime =3D (LocalTime * 182) / 10; BdaPtr =3D (UINT32 *) ((UINTN) 0x46C); *BdaPtr =3D LocalTime; + EnableNullDetection (); =20 // // Pass in handoff data @@ -2564,7 +2573,11 @@ LegacyBiosInstallRom ( // // Set mode settings since PrepareToScanRom may change mode // - if (VideoMode !=3D *(UINT8 *) ((UINTN) (0x400 + BDA_VIDEO_MODE))) { + DisableNullDetection (); + OldVideoMode =3D *(UINT8 *) ((UINTN) (0x400 + BDA_VIDEO_MODE)); + EnableNullDetection (); + + if (VideoMode !=3D OldVideoMode) { // // The active video mode is changed, restore it to original mode. // @@ -2604,7 +2617,9 @@ LegacyBiosInstallRom ( } } =20 + DisableNullDetection (); LocalDiskEnd =3D (UINT8) ((*(UINT8 *) ((UINTN) 0x475)) + 0x80); + EnableNullDetection (); =20 // // Allow platform to perform any required actions after the diff --git a/IntelFrameworkModulePkg/Csm/LegacyBiosDxe/Thunk.c b/IntelFrame= workModulePkg/Csm/LegacyBiosDxe/Thunk.c index 3d9a8b9649..f42c13cd89 100644 --- a/IntelFrameworkModulePkg/Csm/LegacyBiosDxe/Thunk.c +++ b/IntelFrameworkModulePkg/Csm/LegacyBiosDxe/Thunk.c @@ -57,7 +57,11 @@ LegacyBiosInt86 ( IN EFI_IA32_REGISTER_SET *Regs ) { - UINT32 *VectorBase; + UINT16 Segment; + UINT16 Offset; + LEGACY_BIOS_INSTANCE *Private; + + Private =3D LEGACY_BIOS_INSTANCE_FROM_THIS (This); =20 Regs->X.Flags.Reserved1 =3D 1; Regs->X.Flags.Reserved2 =3D 0; @@ -72,12 +76,15 @@ LegacyBiosInt86 ( // The base address of legacy interrupt vector table is 0. // We use this base address to get the legacy interrupt handler. // - VectorBase =3D 0; + DisableNullDetection (); + Segment =3D (UINT16)(((UINT32 *)0)[BiosInt] >> 16); + Offset =3D (UINT16)((UINT32 *)0)[BiosInt]; + EnableNullDetection (); =20 return InternalLegacyBiosFarCall ( This, - (UINT16) ((VectorBase)[BiosInt] >> 16), - (UINT16) (VectorBase)[BiosInt], + Segment, + Offset, Regs, &Regs->X.Flags, sizeof (Regs->X.Flags) @@ -293,9 +300,15 @@ InternalLegacyBiosFarCall ( UINTN EbdaBaseAddress; UINTN ReservedEbdaBaseAddress; =20 - EbdaBaseAddress =3D (*(UINT16 *) (UINTN) 0x40E) << 4; - ReservedEbdaBaseAddress =3D CONVENTIONAL_MEMORY_TOP - PcdGet32 (PcdE= bdaReservedMemorySize); - ASSERT (ReservedEbdaBaseAddress <=3D EbdaBaseAddress); + // + // Skip this part of debug code if NULL pointer detection is enabled + // + if ((PcdGet8 (PcdNullPointerDetectionPropertyMask) & BIT0) =3D=3D 0)= { + EbdaBaseAddress =3D (*(UINT16 *) (UINTN) 0x40E) << 4; + ReservedEbdaBaseAddress =3D CONVENTIONAL_MEMORY_TOP + - PcdGet32 (PcdEbdaReservedMemorySize); + ASSERT (ReservedEbdaBaseAddress <=3D EbdaBaseAddress); + } } ); =20 --=20 2.14.1.windows.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel