├── AslrPkg ├── AslrPkg.dec ├── AslrPkg.dsc ├── Contributions.txt ├── License.txt └── Override │ └── MdeModulePkg │ └── Core │ ├── Dxe │ ├── Dispatcher │ │ ├── Dependency.c │ │ └── Dispatcher.c │ ├── DxeCore.uni │ ├── DxeCoreExtra.uni │ ├── DxeMain.h │ ├── DxeMain.inf │ ├── DxeMain │ │ ├── DxeMain.c │ │ └── DxeProtocolNotify.c │ ├── Event │ │ ├── Event.c │ │ ├── Event.h │ │ ├── Timer.c │ │ └── Tpl.c │ ├── FwVol │ │ ├── Ffs.c │ │ ├── FwVol.c │ │ ├── FwVolAttrib.c │ │ ├── FwVolDriver.h │ │ ├── FwVolRead.c │ │ └── FwVolWrite.c │ ├── FwVolBlock │ │ ├── FwVolBlock.c │ │ └── FwVolBlock.h │ ├── Gcd │ │ ├── Gcd.c │ │ └── Gcd.h │ ├── Hand │ │ ├── DriverSupport.c │ │ ├── Handle.c │ │ ├── Handle.h │ │ ├── Locate.c │ │ └── Notify.c │ ├── Image │ │ ├── Image.c │ │ └── Image.h │ ├── Library │ │ └── Library.c │ ├── Mem │ │ ├── Imem.h │ │ ├── MemData.c │ │ ├── MemoryProfileRecord.c │ │ ├── Page.c │ │ └── Pool.c │ ├── Misc │ │ ├── DebugImageInfo.c │ │ ├── InstallConfigurationTable.c │ │ ├── MemoryAttributesTable.c │ │ ├── MemoryProtection.c │ │ ├── PropertiesTable.c │ │ ├── SetWatchdogTimer.c │ │ └── Stall.c │ └── SectionExtraction │ │ └── CoreSectionExtraction.c │ ├── DxeIplPeim │ ├── Arm │ │ └── DxeLoadFunc.c │ ├── DxeIpl.h │ ├── DxeIpl.inf │ ├── DxeIpl.uni │ ├── DxeIplExtra.uni │ ├── DxeLoad.c │ ├── Ebc │ │ └── DxeLoadFunc.c │ ├── Ia32 │ │ ├── DxeLoadFunc.c │ │ ├── IdtVectorAsm.S │ │ ├── IdtVectorAsm.asm │ │ └── IdtVectorAsm.nasm │ ├── Ipf │ │ └── DxeLoadFunc.c │ └── X64 │ │ ├── DxeLoadFunc.c │ │ ├── VirtualMemory.c │ │ └── VirtualMemory.h │ └── PiSmmCore │ ├── Dependency.c │ ├── Dispatcher.c │ ├── Handle.c │ ├── InstallConfigurationTable.c │ ├── Locate.c │ ├── MemoryAttributesTable.c │ ├── Notify.c │ ├── Page.c │ ├── PiSmmCore.c │ ├── PiSmmCore.h │ ├── PiSmmCore.inf │ ├── PiSmmCore.uni │ ├── PiSmmCoreExtra.uni │ ├── PiSmmCorePrivateData.h │ ├── PiSmmIpl.c │ ├── PiSmmIpl.inf │ ├── PiSmmIpl.uni │ ├── PiSmmIplExtra.uni │ ├── Pool.c │ ├── Smi.c │ ├── SmiHandlerProfile.c │ └── SmramProfileRecord.c ├── ControlFlowPkg ├── CfgTest │ └── CfgTest │ │ ├── CfgTest.c │ │ ├── CfgTest.h │ │ ├── CfgTest.inf │ │ ├── CfgTestAgent.c │ │ ├── CfgTestAgent.inf │ │ ├── Ia32 │ │ └── ExternFunc.nasm │ │ └── X64 │ │ └── ExternFunc.nasm ├── Contributions.txt ├── ControlFlowPkg.dec ├── ControlFlowPkg.dsc ├── DxeCet │ └── Override │ │ ├── IntelFsp2WrapperPkg │ │ └── Library │ │ │ └── BaseFspWrapperApiLib │ │ │ ├── BaseFspWrapperApiLib.inf │ │ │ ├── FspWrapperApiLib.c │ │ │ ├── IA32 │ │ │ └── DispatchExecute.c │ │ │ └── X64 │ │ │ ├── Cet.nasm │ │ │ ├── DispatchExecute.c │ │ │ └── Thunk64To32.nasm │ │ ├── MdeModulePkg │ │ └── Core │ │ │ └── DxeIplPeim │ │ │ ├── Arm │ │ │ └── DxeLoadFunc.c │ │ │ ├── DxeIpl.h │ │ │ ├── DxeIpl.inf │ │ │ ├── DxeIpl.uni │ │ │ ├── DxeIplExtra.uni │ │ │ ├── DxeLoad.c │ │ │ ├── Ebc │ │ │ └── DxeLoadFunc.c │ │ │ ├── Ia32 │ │ │ ├── DxeLoadFunc.c │ │ │ └── IdtVectorAsm.nasm │ │ │ └── X64 │ │ │ ├── DxeLoadFunc.c │ │ │ ├── VirtualMemory.c │ │ │ └── VirtualMemory.h │ │ └── UefiCpuPkg │ │ └── CpuDxe │ │ ├── CpuDxe.c │ │ ├── CpuDxe.h │ │ ├── CpuDxe.inf │ │ ├── CpuDxe.uni │ │ ├── CpuDxeExtra.uni │ │ ├── CpuGdt.c │ │ ├── CpuGdt.h │ │ ├── CpuMp.c │ │ ├── CpuMp.h │ │ ├── CpuPageTable.c │ │ ├── CpuPageTable.h │ │ ├── Ia32 │ │ ├── Cet.nasm │ │ └── CpuAsm.nasm │ │ └── X64 │ │ ├── Cet.nasm │ │ └── CpuAsm.nasm ├── Ibt │ └── Override │ │ └── UefiCpuPkg │ │ ├── Library │ │ └── CpuExceptionHandlerLib │ │ │ ├── CpuExceptionCommon.c │ │ │ ├── CpuExceptionCommon.h │ │ │ ├── DxeCpuExceptionHandlerLib.inf │ │ │ ├── DxeCpuExceptionHandlerLib.uni │ │ │ ├── DxeException.c │ │ │ ├── Ia32 │ │ │ ├── ArchExceptionHandler.c │ │ │ ├── ArchInterruptDefs.h │ │ │ ├── ExceptionHandlerAsm.S │ │ │ ├── ExceptionHandlerAsm.nasm │ │ │ └── ExceptionTssEntryAsm.nasm │ │ │ ├── PeiCpuException.c │ │ │ ├── PeiCpuExceptionHandlerLib.inf │ │ │ ├── PeiCpuExceptionHandlerLib.uni │ │ │ ├── PeiDxeSmmCpuException.c │ │ │ ├── SecPeiCpuException.c │ │ │ ├── SecPeiCpuExceptionHandlerLib.inf │ │ │ ├── SecPeiCpuExceptionHandlerLib.uni │ │ │ ├── SmmCpuExceptionHandlerLib.inf │ │ │ ├── SmmCpuExceptionHandlerLib.uni │ │ │ ├── SmmException.c │ │ │ └── X64 │ │ │ ├── ArchExceptionHandler.c │ │ │ ├── ArchInterruptDefs.h │ │ │ ├── ExceptionHandlerAsm.S │ │ │ └── ExceptionHandlerAsm.nasm │ │ └── PiSmmCpuDxeSmm │ │ ├── CpuS3.c │ │ ├── CpuService.c │ │ ├── CpuService.h │ │ ├── Ia32 │ │ ├── Cet.nasm │ │ ├── MpFuncs.nasm │ │ ├── PageTbl.c │ │ ├── Semaphore.c │ │ ├── SmiEntry.nasm │ │ ├── SmiException.nasm │ │ ├── SmmFuncsArch.c │ │ ├── SmmInit.nasm │ │ ├── SmmProfileArch.c │ │ └── SmmProfileArch.h │ │ ├── MpService.c │ │ ├── PiSmmCpuDxeSmm.c │ │ ├── PiSmmCpuDxeSmm.h │ │ ├── PiSmmCpuDxeSmm.inf │ │ ├── PiSmmCpuDxeSmm.uni │ │ ├── PiSmmCpuDxeSmmExtra.uni │ │ ├── SmmCpuMemoryManagement.c │ │ ├── SmmProfile.c │ │ ├── SmmProfile.h │ │ ├── SmmProfileInternal.h │ │ ├── SmramSaveState.c │ │ ├── SyncTimer.c │ │ └── X64 │ │ ├── Cet.nasm │ │ ├── MpFuncs.nasm │ │ ├── PageTbl.c │ │ ├── Semaphore.c │ │ ├── SmiEntry.nasm │ │ ├── SmiException.nasm │ │ ├── SmmFuncsArch.c │ │ ├── SmmInit.nasm │ │ ├── SmmProfileArch.c │ │ └── SmmProfileArch.h ├── Library │ └── CfgStubLib │ │ ├── CfgProtocol.h │ │ ├── CfgStub.c │ │ ├── CfgStubLib.inf │ │ ├── CfiStub.c │ │ ├── PeLoadConfiguration.h │ │ ├── UefiImage.c │ │ ├── WinNTInclude.h │ │ ├── WinNTServiceLibMsvc.c │ │ └── WinNtThunk.h ├── License.txt └── Test │ ├── IndirectBranchTrackingTest │ ├── Ia32 │ │ └── EndBr.nasm │ ├── IndirectBranchTrackingTest.c │ ├── IndirectBranchTrackingTest.inf │ ├── IndirectBranchTrackingTestSmm.c │ ├── IndirectBranchTrackingTestSmm.inf │ └── X64 │ │ └── EndBr.nasm │ └── ShadowStackTest │ ├── ShadowStackTest.c │ ├── ShadowStackTest.inf │ ├── ShadowStackTestSmm.c │ └── ShadowStackTestSmm.inf ├── CppPkg ├── Contributions.txt ├── CppPkg.dsc ├── Library │ └── UefiCppEntryPoint │ │ ├── CppCrt.inf │ │ ├── Scripts │ │ └── gcc-ld-script │ │ ├── UefiImage.c │ │ ├── crt.c │ │ ├── crtbegin.cpp │ │ ├── crtend.cpp │ │ ├── ctors.cpp │ │ └── new_delete.cpp ├── License.txt └── TestCpp │ ├── TestCpp.cpp │ └── TestCpp.inf ├── OverflowDetectionPkg ├── Contributions.txt ├── Include │ └── Library │ │ └── PageTableLib.h ├── Library │ ├── PageTableLibNull │ │ ├── PageTableLibNull.c │ │ └── PageTableLibNull.inf │ └── PageTableLibX86Pae │ │ ├── PageTableLibX86Pae.c │ │ └── PageTableLibX86Pae.inf ├── License.txt ├── OverflowDetectionPkg.dec ├── OverflowDetectionPkg.dsc └── Test │ ├── DoubleFree │ ├── DoubleFreePage.c │ ├── DoubleFreePage.inf │ ├── DoubleFreePageSmm.inf │ ├── DoubleFreePool.c │ ├── DoubleFreePool.inf │ └── DoubleFreePoolSmm.inf │ ├── ExecDataSection │ ├── ExecDataSection.c │ ├── ExecDataSection.inf │ ├── ExecDataSectionSmm.c │ └── ExecDataSectionSmm.inf │ ├── HeapOverflow │ ├── HeapOverflowDownPage.c │ ├── HeapOverflowDownPage.inf │ ├── HeapOverflowDownPageSmm.inf │ ├── HeapOverflowDownPool.c │ ├── HeapOverflowDownPool.inf │ ├── HeapOverflowDownPoolSmm.inf │ ├── HeapOverflowUpPage.c │ ├── HeapOverflowUpPage.inf │ ├── HeapOverflowUpPageSmm.inf │ ├── HeapOverflowUpPool.c │ ├── HeapOverflowUpPool.inf │ └── HeapOverflowUpPoolSmm.inf │ ├── PartialFree │ ├── PartialFreePage.c │ ├── PartialFreePage.inf │ └── PartialFreePageSmm.inf │ ├── RingSwitch │ ├── Communication.h │ ├── CpuDump.c │ ├── Ia32 │ │ └── Ring.nasm │ ├── RingSwitch.c │ ├── RingSwitch.inf │ ├── RingSwitchSmm.c │ ├── RingSwitchSmm.inf │ ├── RingSwitchSmmApp.c │ ├── RingSwitchSmmApp.inf │ └── X64 │ │ └── Ring.nasm │ ├── StackOverflow │ ├── CpuDump.c │ ├── Ia32 │ │ └── Stack.nasm │ ├── StackOverflow.c │ ├── StackOverflow.inf │ ├── StackOverflowSmm.c │ ├── StackOverflowSmm.inf │ └── X64 │ │ └── Stack.nasm │ └── WriteCodeSection │ ├── WriteCodeSection.c │ ├── WriteCodeSection.inf │ ├── WriteCodeSectionSmm.c │ └── WriteCodeSectionSmm.inf ├── Readme.md ├── StackCheckPkg ├── Contributions.txt ├── Library │ └── StackCheckLib │ │ ├── ASanStub.c │ │ ├── GSStub.c │ │ ├── MSanStub.c │ │ ├── RTCStub.c │ │ ├── RTCcStub.c │ │ ├── RTCsStub.c │ │ ├── RTCuStub.c │ │ ├── StackCheckLib.inf │ │ ├── StackProtectorStub.c │ │ └── UBSanStub.c ├── License.txt ├── StackCheckPkg.dec ├── StackCheckPkg.dsc └── Test │ ├── SideChannelTest │ ├── SideChannelTest.c │ └── SideChannelTest.inf │ ├── SmallTypeTest │ ├── SmallTypeTest.c │ └── SmallTypeTest.inf │ ├── StackCookieTest │ ├── StackCookieTest.c │ └── StackCookieTest.inf │ ├── StackFrameTest │ ├── StackFrameTest.c │ └── StackFrameTest.inf │ ├── UninitializedVariableTest │ ├── UninitializedVariableTest.c │ └── UninitializedVariableTest.inf │ └── Variant1Test │ ├── Variant1App │ ├── Variant1App.c │ ├── Variant1App.inf │ └── spectre.c │ └── Variant1Smm │ ├── Variant1Smm.c │ ├── Variant1Smm.inf │ ├── Variant1SmmApp.c │ ├── Variant1SmmApp.inf │ └── Variant1SmmCommBuffer.h ├── Summary.md ├── UserModePkg ├── Contributions.txt ├── Include │ └── Protocol │ │ └── UserModeThunk.h ├── License.txt ├── UserModePkg.dec ├── UserModePkg.dsc └── UserModeThunk │ ├── Ia32 │ ├── Context.c │ ├── ExceptionHandlerAsm.nasm │ └── UserMode.asm │ ├── UserModeThunk.c │ ├── UserModeThunk.inf │ └── x64 │ ├── Context.c │ ├── ExceptionHandlerAsm.nasm │ └── UserMode.asm └── doc └── A_Tour_Beyond_BIOS_Securiy_Enhancement_to_Mitigate_Buffer_Overflow_in_UEFI.pdf /AslrPkg/AslrPkg.dec: -------------------------------------------------------------------------------- 1 | ## @file 2 | # 3 | # Copyright (c) 2016, Intel Corporation. All rights reserved.
4 | # 5 | # This program and the accompanying materials 6 | # are licensed and made available under the terms and conditions of the BSD License 7 | # which accompanies this distribution. The full text of the license may be found at 8 | # http://opensource.org/licenses/bsd-license.php 9 | # 10 | # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 12 | # 13 | ## 14 | 15 | [Defines] 16 | DEC_SPECIFICATION = 0x00010005 17 | PACKAGE_NAME = AslrPkg 18 | PACKAGE_GUID = 49ECDD2B-7403-46D0-9BFD-4164556047D2 19 | PACKAGE_VERSION = 0.1 20 | 21 | [Includes] 22 | 23 | [Guids] 24 | gEfiAslrPkgTokenSpaceGuid = { 0x502532c8, 0xf940, 0x4a04, { 0xa9, 0xd2, 0x34, 0xdb, 0x8d, 0xa5, 0x39, 0x75 }} 25 | 26 | [PcdsFeatureFlag] 27 | ## This PCD control ASLR image shuffle enabling. 28 | gEfiAslrPkgTokenSpaceGuid.PcdImageShuffleEnable|TRUE|BOOLEAN|0x00010001 29 | 30 | [PcdsFixedAtBuild, PcdsPatchableInModule] 31 | ## This PCD control ASLR entropy bits. 32 | gEfiAslrPkgTokenSpaceGuid.PcdASLRMinimumEntropyBits|0x04|UINT8|0x00000001 33 | -------------------------------------------------------------------------------- /AslrPkg/License.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012, Intel Corporation. All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions 5 | are met: 6 | 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above copyright 10 | notice, this list of conditions and the following disclaimer in 11 | the documentation and/or other materials provided with the 12 | distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 15 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 16 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 17 | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 18 | COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 19 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 20 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 24 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 | POSSIBILITY OF SUCH DAMAGE. 26 | -------------------------------------------------------------------------------- /AslrPkg/Override/MdeModulePkg/Core/Dxe/DxeCore.uni: -------------------------------------------------------------------------------- 1 | // /** @file 2 | // This is core module in DXE phase. 3 | // 4 | // It provides an implementation of DXE Core that is compliant with DXE CIS. 5 | // 6 | // Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.
7 | // 8 | // This program and the accompanying materials 9 | // are licensed and made available under the terms and conditions of the BSD License 10 | // which accompanies this distribution. The full text of the license may be found at 11 | // http://opensource.org/licenses/bsd-license.php 12 | // 13 | // THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 15 | // 16 | // **/ 17 | 18 | 19 | #string STR_MODULE_ABSTRACT #language en-US "The core module in DXE phase" 20 | 21 | #string STR_MODULE_DESCRIPTION #language en-US "It provides an implementation of DXE Core that is compliant with DXE CIS." 22 | 23 | -------------------------------------------------------------------------------- /AslrPkg/Override/MdeModulePkg/Core/Dxe/DxeCoreExtra.uni: -------------------------------------------------------------------------------- 1 | // /** @file 2 | // DxeCore Localized Strings and Content 3 | // 4 | // Copyright (c) 2013 - 2014, Intel Corporation. All rights reserved.
5 | // 6 | // This program and the accompanying materials 7 | // are licensed and made available under the terms and conditions of the BSD License 8 | // which accompanies this distribution. The full text of the license may be found at 9 | // http://opensource.org/licenses/bsd-license.php 10 | // 11 | // THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 13 | // 14 | // **/ 15 | 16 | #string STR_PROPERTIES_MODULE_NAME 17 | #language en-US 18 | "Core DXE Services Driver" 19 | 20 | 21 | -------------------------------------------------------------------------------- /AslrPkg/Override/MdeModulePkg/Core/Dxe/FwVol/FwVolWrite.c: -------------------------------------------------------------------------------- 1 | /** @file 2 | Implements functions to write firmware file 3 | 4 | Copyright (c) 2006 - 2008, Intel Corporation. All rights reserved.
5 | This program and the accompanying materials 6 | are licensed and made available under the terms and conditions of the BSD License 7 | which accompanies this distribution. The full text of the license may be found at 8 | http://opensource.org/licenses/bsd-license.php 9 | 10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 12 | 13 | **/ 14 | 15 | #include "DxeMain.h" 16 | #include "FwVolDriver.h" 17 | 18 | 19 | /** 20 | Writes one or more files to the firmware volume. 21 | 22 | @param This Indicates the calling context. 23 | @param NumberOfFiles Number of files. 24 | @param WritePolicy WritePolicy indicates the level of reliability 25 | for the write in the event of a power failure or 26 | other system failure during the write operation. 27 | @param FileData FileData is an pointer to an array of 28 | EFI_FV_WRITE_DATA. Each element of array 29 | FileData represents a file to be written. 30 | 31 | @retval EFI_SUCCESS Files successfully written to firmware volume 32 | @retval EFI_OUT_OF_RESOURCES Not enough buffer to be allocated. 33 | @retval EFI_DEVICE_ERROR Device error. 34 | @retval EFI_WRITE_PROTECTED Write protected. 35 | @retval EFI_NOT_FOUND Not found. 36 | @retval EFI_INVALID_PARAMETER Invalid parameter. 37 | @retval EFI_UNSUPPORTED This function not supported. 38 | 39 | **/ 40 | EFI_STATUS 41 | EFIAPI 42 | FvWriteFile ( 43 | IN CONST EFI_FIRMWARE_VOLUME2_PROTOCOL *This, 44 | IN UINT32 NumberOfFiles, 45 | IN EFI_FV_WRITE_POLICY WritePolicy, 46 | IN EFI_FV_WRITE_FILE_DATA *FileData 47 | ) 48 | { 49 | return EFI_UNSUPPORTED; 50 | } 51 | 52 | 53 | -------------------------------------------------------------------------------- /AslrPkg/Override/MdeModulePkg/Core/Dxe/Gcd/Gcd.h: -------------------------------------------------------------------------------- 1 | /** @file 2 | GCD Operations and data structure used to 3 | convert from GCD attributes to EFI Memory Map attributes. 4 | 5 | Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.
6 | This program and the accompanying materials 7 | are licensed and made available under the terms and conditions of the BSD License 8 | which accompanies this distribution. The full text of the license may be found at 9 | http://opensource.org/licenses/bsd-license.php 10 | 11 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 13 | 14 | **/ 15 | 16 | #ifndef _GCD_H_ 17 | #define _GCD_H_ 18 | 19 | // 20 | // GCD Operations 21 | // 22 | #define GCD_MEMORY_SPACE_OPERATION 0x20 23 | #define GCD_IO_SPACE_OPERATION 0x40 24 | 25 | #define GCD_ADD_MEMORY_OPERATION (GCD_MEMORY_SPACE_OPERATION | 0) 26 | #define GCD_ALLOCATE_MEMORY_OPERATION (GCD_MEMORY_SPACE_OPERATION | 1) 27 | #define GCD_FREE_MEMORY_OPERATION (GCD_MEMORY_SPACE_OPERATION | 2) 28 | #define GCD_REMOVE_MEMORY_OPERATION (GCD_MEMORY_SPACE_OPERATION | 3) 29 | #define GCD_SET_ATTRIBUTES_MEMORY_OPERATION (GCD_MEMORY_SPACE_OPERATION | 4) 30 | #define GCD_SET_CAPABILITIES_MEMORY_OPERATION (GCD_MEMORY_SPACE_OPERATION | 5) 31 | 32 | #define GCD_ADD_IO_OPERATION (GCD_IO_SPACE_OPERATION | 0) 33 | #define GCD_ALLOCATE_IO_OPERATION (GCD_IO_SPACE_OPERATION | 1) 34 | #define GCD_FREE_IO_OPERATION (GCD_IO_SPACE_OPERATION | 2) 35 | #define GCD_REMOVE_IO_OPERATION (GCD_IO_SPACE_OPERATION | 3) 36 | 37 | // 38 | // The data structure used to convert from GCD attributes to EFI Memory Map attributes 39 | // 40 | typedef struct { 41 | UINT64 Attribute; 42 | UINT64 Capability; 43 | BOOLEAN Memory; 44 | } GCD_ATTRIBUTE_CONVERSION_ENTRY; 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /AslrPkg/Override/MdeModulePkg/Core/Dxe/Mem/MemData.c: -------------------------------------------------------------------------------- 1 | /** @file 2 | Global data used in memory service 3 | 4 | Copyright (c) 2006 - 2008, Intel Corporation. All rights reserved.
5 | This program and the accompanying materials 6 | are licensed and made available under the terms and conditions of the BSD License 7 | which accompanies this distribution. The full text of the license may be found at 8 | http://opensource.org/licenses/bsd-license.php 9 | 10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 12 | 13 | **/ 14 | 15 | #include "DxeMain.h" 16 | 17 | 18 | // 19 | // MemoryLock - synchronizes access to the memory map and pool lists 20 | // 21 | EFI_LOCK gMemoryLock = EFI_INITIALIZE_LOCK_VARIABLE (TPL_NOTIFY); 22 | 23 | // 24 | // MemoryMap - the current memory map 25 | // 26 | LIST_ENTRY gMemoryMap = INITIALIZE_LIST_HEAD_VARIABLE (gMemoryMap); 27 | -------------------------------------------------------------------------------- /AslrPkg/Override/MdeModulePkg/Core/DxeIplPeim/DxeIpl.uni: -------------------------------------------------------------------------------- 1 | // /** @file 2 | // Last PEIM executed in PEI phase to load DXE Core from a Firmware Volume. 3 | // 4 | // This module produces a special PPI named the DXE Initial Program Load (IPL) 5 | // PPI to discover and dispatch the DXE Foundation and components that are 6 | // needed to run the DXE Foundation. 7 | // 8 | // Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.
9 | // 10 | // This program and the accompanying materials 11 | // are licensed and made available under the terms and conditions of the BSD License 12 | // which accompanies this distribution. The full text of the license may be found at 13 | // http://opensource.org/licenses/bsd-license.php 14 | // 15 | // THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 17 | // 18 | // **/ 19 | 20 | 21 | #string STR_MODULE_ABSTRACT #language en-US "Last PEIM executed in PEI phase to load DXE Core from a Firmware Volume" 22 | 23 | #string STR_MODULE_DESCRIPTION #language en-US "This module produces a special PPI named the DXE Initial Program Load (IPL) PPI to discover and dispatch the DXE Foundation and components that are needed to run the DXE Foundation." 24 | 25 | -------------------------------------------------------------------------------- /AslrPkg/Override/MdeModulePkg/Core/DxeIplPeim/DxeIplExtra.uni: -------------------------------------------------------------------------------- 1 | // /** @file 2 | // DxeIpl Localized Strings and Content 3 | // 4 | // Copyright (c) 2013 - 2014, Intel Corporation. All rights reserved.
5 | // 6 | // This program and the accompanying materials 7 | // are licensed and made available under the terms and conditions of the BSD License 8 | // which accompanies this distribution. The full text of the license may be found at 9 | // http://opensource.org/licenses/bsd-license.php 10 | // 11 | // THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 13 | // 14 | // **/ 15 | 16 | #string STR_PROPERTIES_MODULE_NAME 17 | #language en-US 18 | "Core DXE Services Initial Program Loader" 19 | 20 | 21 | -------------------------------------------------------------------------------- /AslrPkg/Override/MdeModulePkg/Core/DxeIplPeim/Ebc/DxeLoadFunc.c: -------------------------------------------------------------------------------- 1 | /** @file 2 | EBC-specific functionality for DxeLoad. 3 | 4 | Copyright (c) 2006 - 2008, Intel Corporation. All rights reserved.
5 | This program and the accompanying materials 6 | are licensed and made available under the terms and conditions of the BSD License 7 | which accompanies this distribution. The full text of the license may be found at 8 | http://opensource.org/licenses/bsd-license.php 9 | 10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 12 | 13 | **/ 14 | 15 | #include "DxeIpl.h" 16 | 17 | 18 | 19 | /** 20 | Transfers control to DxeCore. 21 | 22 | This function performs a CPU architecture specific operations to execute 23 | the entry point of DxeCore with the parameters of HobList. 24 | It also installs EFI_END_OF_PEI_PPI to signal the end of PEI phase. 25 | 26 | @param DxeCoreEntryPoint The entry point of DxeCore. 27 | @param HobList The start of HobList passed to DxeCore. 28 | 29 | **/ 30 | VOID 31 | HandOffToDxeCore ( 32 | IN EFI_PHYSICAL_ADDRESS DxeCoreEntryPoint, 33 | IN EFI_PEI_HOB_POINTERS HobList 34 | ) 35 | { 36 | VOID *BaseOfStack; 37 | VOID *TopOfStack; 38 | EFI_STATUS Status; 39 | 40 | // 41 | // Allocate 128KB for the Stack 42 | // 43 | BaseOfStack = AllocatePages (EFI_SIZE_TO_PAGES (STACK_SIZE)); 44 | ASSERT (BaseOfStack != NULL); 45 | 46 | // 47 | // Compute the top of the stack we were allocated. Pre-allocate a UINTN 48 | // for safety. 49 | // 50 | TopOfStack = (VOID *) ((UINTN) BaseOfStack + EFI_SIZE_TO_PAGES (STACK_SIZE) * EFI_PAGE_SIZE - CPU_STACK_ALIGNMENT); 51 | TopOfStack = ALIGN_POINTER (TopOfStack, CPU_STACK_ALIGNMENT); 52 | 53 | // 54 | // End of PEI phase signal 55 | // 56 | Status = PeiServicesInstallPpi (&gEndOfPeiSignalPpi); 57 | ASSERT_EFI_ERROR (Status); 58 | 59 | // 60 | // Update the contents of BSP stack HOB to reflect the real stack info passed to DxeCore. 61 | // 62 | UpdateStackHob ((EFI_PHYSICAL_ADDRESS)(UINTN) BaseOfStack, STACK_SIZE); 63 | 64 | // 65 | // Transfer the control to the entry point of DxeCore. 66 | // 67 | SwitchStack ( 68 | (SWITCH_STACK_ENTRY_POINT)(UINTN)DxeCoreEntryPoint, 69 | HobList.Raw, 70 | NULL, 71 | TopOfStack 72 | ); 73 | } 74 | -------------------------------------------------------------------------------- /AslrPkg/Override/MdeModulePkg/Core/DxeIplPeim/Ia32/IdtVectorAsm.S: -------------------------------------------------------------------------------- 1 | #/** @file 2 | # 3 | # IDT vector entry. 4 | # 5 | # Copyright (c) 2007 - 2009, Intel Corporation. All rights reserved.
6 | # This program and the accompanying materials 7 | # are licensed and made available under the terms and conditions of the BSD License 8 | # which accompanies this distribution. The full text of the license may be found at 9 | # http://opensource.org/licenses/bsd-license.php 10 | # 11 | # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 13 | # 14 | #**/ 15 | 16 | .text 17 | .code32 18 | 19 | 20 | .p2align 3 21 | ASM_GLOBAL ASM_PFX(AsmGetVectorTemplatInfo) 22 | ASM_GLOBAL ASM_PFX(AsmVectorFixup) 23 | /* 24 | ; 25 | ;----------------------------------------------------------------------- 26 | ; Template of IDT Vector Handlers. 27 | ; 28 | ;----------------------------------------------------------------------- 29 | */ 30 | VectorTemplateBase: 31 | pushl %eax 32 | .byte 0x6a # push #VectorNum 33 | VectorNum: 34 | .byte 0 35 | movl CommonInterruptEntry, %eax 36 | jmp *%eax 37 | VectorTemplateEnd: 38 | 39 | 40 | ASM_PFX(AsmGetVectorTemplatInfo): 41 | movl 4(%esp), %ecx 42 | movl $VectorTemplateBase, (%ecx) 43 | movl $(VectorTemplateEnd - VectorTemplateBase), %eax 44 | ret 45 | 46 | ASM_PFX(AsmVectorFixup): 47 | movl 8(%esp), %eax 48 | movl 4(%esp), %ecx 49 | movb %al, (VectorNum - VectorTemplateBase)(%ecx) 50 | ret 51 | 52 | /* 53 | ; The follow algorithm is used for the common interrupt routine. 54 | 55 | ; 56 | ; +---------------------+ <-- 16-byte aligned ensured by processor 57 | ; + Old SS + 58 | ; +---------------------+ 59 | ; + Old RSP + 60 | ; +---------------------+ 61 | ; + RFlags + 62 | ; +---------------------+ 63 | ; + CS + 64 | ; +---------------------+ 65 | ; + RIP + 66 | ; +---------------------+ 67 | ; + Error Code + 68 | ; +---------------------+ 69 | ; + Vector Number + 70 | ; +---------------------+ 71 | */ 72 | 73 | CommonInterruptEntry: 74 | cli 75 | 1: 76 | jmp 1b 77 | 78 | 79 | 80 | 81 | -------------------------------------------------------------------------------- /AslrPkg/Override/MdeModulePkg/Core/DxeIplPeim/Ia32/IdtVectorAsm.nasm: -------------------------------------------------------------------------------- 1 | ;/** @file 2 | ; 3 | ; IDT vector entry. 4 | ; 5 | ; Copyright (c) 2007 - 2016, Intel Corporation. All rights reserved.
6 | ; This program and the accompanying materials 7 | ; are licensed and made available under the terms and conditions of the BSD License 8 | ; which accompanies this distribution. The full text of the license may be found at 9 | ; http://opensource.org/licenses/bsd-license.php 10 | ; 11 | ; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 12 | ; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 13 | ; 14 | ;**/ 15 | 16 | SECTION .text 17 | 18 | ; 19 | ;------------------------------------------------------------------------------ 20 | ; Generic IDT Vector Handlers for the Host. 21 | ; 22 | ;------------------------------------------------------------------------------ 23 | 24 | ALIGN 8 25 | global ASM_PFX(AsmGetVectorTemplatInfo) 26 | global ASM_PFX(AsmVectorFixup) 27 | 28 | @VectorTemplateBase: 29 | push eax 30 | db 0x6a ; push #VectorNumber 31 | @VectorNum: 32 | db 0 33 | mov eax, CommonInterruptEntry 34 | jmp eax 35 | @VectorTemplateEnd: 36 | 37 | global ASM_PFX(AsmGetVectorTemplatInfo) 38 | ASM_PFX(AsmGetVectorTemplatInfo): 39 | mov ecx, [esp + 4] 40 | mov dword [ecx], @VectorTemplateBase 41 | mov eax, (@VectorTemplateEnd - @VectorTemplateBase) 42 | ret 43 | 44 | global ASM_PFX(AsmVectorFixup) 45 | ASM_PFX(AsmVectorFixup): 46 | mov eax, dword [esp + 8] 47 | mov ecx, [esp + 4] 48 | mov [ecx + (@VectorNum - @VectorTemplateBase)], al 49 | ret 50 | 51 | ;---------------------------------------; 52 | ; CommonInterruptEntry ; 53 | ;---------------------------------------; 54 | ; The follow algorithm is used for the common interrupt routine. 55 | 56 | ; 57 | ; +---------------------+ <-- 16-byte aligned ensured by processor 58 | ; + Old SS + 59 | ; +---------------------+ 60 | ; + Old RSP + 61 | ; +---------------------+ 62 | ; + RFlags + 63 | ; +---------------------+ 64 | ; + CS + 65 | ; +---------------------+ 66 | ; + RIP + 67 | ; +---------------------+ 68 | ; + Error Code + 69 | ; +---------------------+ 70 | ; + Vector Number + 71 | ; +---------------------+ 72 | 73 | CommonInterruptEntry: 74 | cli 75 | 76 | jmp $ 77 | 78 | -------------------------------------------------------------------------------- /AslrPkg/Override/MdeModulePkg/Core/PiSmmCore/PiSmmCore.uni: -------------------------------------------------------------------------------- 1 | // /** @file 2 | // This module provide an SMM CIS compliant implementation of SMM Core. 3 | // 4 | // This module provide an SMM CIS compliant implementation of SMM Core. 5 | // 6 | // Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.
7 | // 8 | // This program and the accompanying materials 9 | // are licensed and made available under the terms and conditions of the BSD License 10 | // which accompanies this distribution. The full text of the license may be found at 11 | // http://opensource.org/licenses/bsd-license.php 12 | // THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 13 | // WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 14 | // 15 | // **/ 16 | 17 | 18 | #string STR_MODULE_ABSTRACT #language en-US "Provides an SMM CIS compliant implementation of SMM Core" 19 | 20 | #string STR_MODULE_DESCRIPTION #language en-US "This module provide an SMM CIS compliant implementation of SMM Core." 21 | 22 | -------------------------------------------------------------------------------- /AslrPkg/Override/MdeModulePkg/Core/PiSmmCore/PiSmmCoreExtra.uni: -------------------------------------------------------------------------------- 1 | // /** @file 2 | // PiSmmCore Localized Strings and Content 3 | // 4 | // Copyright (c) 2013 - 2014, Intel Corporation. All rights reserved.
5 | // 6 | // This program and the accompanying materials 7 | // are licensed and made available under the terms and conditions of the BSD License 8 | // which accompanies this distribution. The full text of the license may be found at 9 | // http://opensource.org/licenses/bsd-license.php 10 | // THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 12 | // 13 | // **/ 14 | 15 | #string STR_PROPERTIES_MODULE_NAME 16 | #language en-US 17 | "Core SMM Services Driver" 18 | 19 | 20 | -------------------------------------------------------------------------------- /AslrPkg/Override/MdeModulePkg/Core/PiSmmCore/PiSmmIpl.uni: -------------------------------------------------------------------------------- 1 | // /** @file 2 | // This module provide an SMM CIS compliant implementation of SMM IPL. 3 | // 4 | // This module provide an SMM CIS compliant implementation of SMM IPL. 5 | // 6 | // Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.
7 | // 8 | // This program and the accompanying materials 9 | // are licensed and made available under the terms and conditions of the BSD License 10 | // which accompanies this distribution. The full text of the license may be found at 11 | // http://opensource.org/licenses/bsd-license.php 12 | // THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 13 | // WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 14 | // 15 | // **/ 16 | 17 | 18 | #string STR_MODULE_ABSTRACT #language en-US "Provides an SMM CIS compliant implementation of SMM IPL" 19 | 20 | #string STR_MODULE_DESCRIPTION #language en-US "This module provide an SMM CIS compliant implementation of SMM IPL." 21 | 22 | -------------------------------------------------------------------------------- /AslrPkg/Override/MdeModulePkg/Core/PiSmmCore/PiSmmIplExtra.uni: -------------------------------------------------------------------------------- 1 | // /** @file 2 | // PiSmmIpl Localized Strings and Content 3 | // 4 | // Copyright (c) 2013 - 2014, Intel Corporation. All rights reserved.
5 | // 6 | // This program and the accompanying materials 7 | // are licensed and made available under the terms and conditions of the BSD License 8 | // which accompanies this distribution. The full text of the license may be found at 9 | // http://opensource.org/licenses/bsd-license.php 10 | // THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 12 | // 13 | // **/ 14 | 15 | #string STR_PROPERTIES_MODULE_NAME 16 | #language en-US 17 | "Core SMM Services Initial Program Loader" 18 | 19 | 20 | -------------------------------------------------------------------------------- /ControlFlowPkg/CfgTest/CfgTest/CfgTest.c: -------------------------------------------------------------------------------- 1 | /** @file 2 | 3 | Copyright (c) 2016, Intel Corporation. All rights reserved.
4 | This program and the accompanying materials 5 | are licensed and made available under the terms and conditions of the BSD License 6 | which accompanies this distribution. The full text of the license may be found at 7 | http://opensource.org/licenses/bsd-license.php 8 | 9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | 12 | **/ 13 | 14 | #include 15 | 16 | #include 17 | #include 18 | #include 19 | #include "CfgTest.h" 20 | 21 | VOID 22 | EFIAPI 23 | ExternFunc ( 24 | VOID 25 | ); 26 | 27 | VOID 28 | EFIAPI 29 | ExternFunc2 ( 30 | VOID 31 | ); 32 | 33 | EFI_GUID gCfgTestProtocolGuid = CFG_TEST_PROTOCOL_GUID; 34 | 35 | CFG_TEST_PROTOCOL mCfgTestProtocol = { 36 | ExternFunc, 37 | ExternFunc2 38 | }; 39 | 40 | VOID 41 | EFIAPI 42 | CfgTest ( 43 | VOID 44 | ) 45 | { 46 | EXTERNAL_FUNC Func; 47 | 48 | Func = (EXTERNAL_FUNC)((UINTN)ExternFunc); 49 | Func (); 50 | 51 | //Func = (EXTERNAL_FUNC)((UINTN)ExternFunc + 1); 52 | //Func (); 53 | } 54 | 55 | EFI_STATUS 56 | EFIAPI 57 | CfgTestInitialize( 58 | IN EFI_HANDLE ImageHandle, 59 | IN EFI_SYSTEM_TABLE *SystemTable 60 | ) 61 | { 62 | EFI_STATUS Status; 63 | EFI_HANDLE Handle; 64 | 65 | CfgTest (); 66 | 67 | Handle = NULL; 68 | Status = gBS->InstallProtocolInterface ( 69 | &Handle, 70 | &gCfgTestProtocolGuid, 71 | EFI_NATIVE_INTERFACE, 72 | &mCfgTestProtocol 73 | ); 74 | 75 | return EFI_SUCCESS; 76 | } 77 | -------------------------------------------------------------------------------- /ControlFlowPkg/CfgTest/CfgTest/CfgTest.h: -------------------------------------------------------------------------------- 1 | /** @file 2 | 3 | Copyright (c) 2016, Intel Corporation. All rights reserved.
4 | This program and the accompanying materials 5 | are licensed and made available under the terms and conditions of the BSD License 6 | which accompanies this distribution. The full text of the license may be found at 7 | http://opensource.org/licenses/bsd-license.php 8 | 9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | 12 | **/ 13 | 14 | #ifndef _CFG_TEST_H_ 15 | #define _CFG_TEST_H_ 16 | 17 | #define CFG_TEST_PROTOCOL_GUID \ 18 | { 0xe34ccd0, 0x820f, 0x4c76, { 0xbc, 0x73, 0xbb, 0x38, 0x57, 0x6c, 0xab, 0x12 } } 19 | 20 | typedef 21 | VOID 22 | (EFIAPI *EXTERNAL_FUNC) ( 23 | VOID 24 | ); 25 | 26 | typedef struct { 27 | EXTERNAL_FUNC ExternFunc; 28 | EXTERNAL_FUNC ExternFunc2; 29 | } CFG_TEST_PROTOCOL; 30 | 31 | extern EFI_GUID gCfgTestProtocolGuid; 32 | 33 | #endif -------------------------------------------------------------------------------- /ControlFlowPkg/CfgTest/CfgTest/CfgTest.inf: -------------------------------------------------------------------------------- 1 | ## @file 2 | # 3 | # Copyright (c) 2016, Intel Corporation. All rights reserved.
4 | # This program and the accompanying materials are licensed and made available under 5 | # the terms and conditions of the BSD License that accompanies this distribution. 6 | # The full text of the license may be found at 7 | # http://opensource.org/licenses/bsd-license.php. 8 | # 9 | # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | # 12 | ## 13 | 14 | [Defines] 15 | INF_VERSION = 0x00010005 16 | BASE_NAME = CfgTest 17 | FILE_GUID = 9822E519-85C2-4EEA-AB79-B665842A6C8F 18 | MODULE_TYPE = UEFI_DRIVER 19 | VERSION_STRING = 1.0 20 | ENTRY_POINT = CfgTestInitialize 21 | 22 | [Sources] 23 | CfgTest.c 24 | 25 | [Sources.Ia32] 26 | Ia32/ExternFunc.nasm 27 | 28 | [Sources.X64] 29 | X64/ExternFunc.nasm 30 | 31 | [Packages] 32 | MdePkg/MdePkg.dec 33 | 34 | [LibraryClasses] 35 | UefiDriverEntryPoint 36 | UefiBootServicesTableLib 37 | 38 | [BuildOptions] 39 | MSFT:*_*_*_CC_FLAGS = /Od /GL- /guard:cf 40 | # Using /SUBSYSTEM:EFI_BOOT_SERVICE_DRIVER will cause guard info stripped. 41 | # Need MSVCRTd.Lib to generate Guard Info 42 | MSFT:*_*_*_DLINK_FLAGS = /guard:cf /SUBSYSTEM:CONSOLE MSVCRTD.lib 43 | MSFT:*_VS2015x86_IA32_DLINK_FLAGS = /LIBPATH:"$(VCINSTALLDIR)\Lib" 44 | MSFT:*_VS2015x86_X64_DLINK_FLAGS = /LIBPATH:"$(VCINSTALLDIR)\Lib\AMD64" 45 | MSFT:*_VS2017_IA32_DLINK_FLAGS = /LIBPATH:"%VCToolsInstallDir%lib\x86" 46 | MSFT:*_VS2017_X64_DLINK_FLAGS = /LIBPATH:"%VCToolsInstallDir%lib\x64" 47 | 48 | # need use -fsplit-lto-unit for project 49 | GCC:*_CLANGPDB_*_CC_FLAGS = -O0 -fsanitize=cfi -------------------------------------------------------------------------------- /ControlFlowPkg/CfgTest/CfgTest/CfgTestAgent.c: -------------------------------------------------------------------------------- 1 | /** @file 2 | 3 | Copyright (c) 2016, Intel Corporation. All rights reserved.
4 | This program and the accompanying materials 5 | are licensed and made available under the terms and conditions of the BSD License 6 | which accompanies this distribution. The full text of the license may be found at 7 | http://opensource.org/licenses/bsd-license.php 8 | 9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | 12 | **/ 13 | 14 | #include 15 | 16 | #include 17 | #include 18 | #include 19 | #include "CfgTest.h" 20 | 21 | EFI_GUID gCfgTestProtocolGuid = CFG_TEST_PROTOCOL_GUID; 22 | 23 | CFG_TEST_PROTOCOL *mCfgTestProtocol; 24 | 25 | VOID 26 | EFIAPI 27 | CfgTest ( 28 | VOID 29 | ) 30 | { 31 | EXTERNAL_FUNC Func; 32 | 33 | Func = (EXTERNAL_FUNC)((UINTN)mCfgTestProtocol->ExternFunc); 34 | Func (); 35 | 36 | Func = (EXTERNAL_FUNC)((UINTN)mCfgTestProtocol->ExternFunc + 1); 37 | Func (); 38 | } 39 | 40 | EFI_STATUS 41 | EFIAPI 42 | CfgTestAgentInitialize( 43 | IN EFI_HANDLE ImageHandle, 44 | IN EFI_SYSTEM_TABLE *SystemTable 45 | ) 46 | { 47 | EFI_STATUS Status; 48 | 49 | Status = gBS->LocateProtocol ( 50 | &gCfgTestProtocolGuid, 51 | NULL, 52 | (VOID *)&mCfgTestProtocol 53 | ); 54 | if (EFI_ERROR(Status)) { 55 | return Status; 56 | } 57 | 58 | CfgTest (); 59 | 60 | return EFI_SUCCESS; 61 | } 62 | -------------------------------------------------------------------------------- /ControlFlowPkg/CfgTest/CfgTest/CfgTestAgent.inf: -------------------------------------------------------------------------------- 1 | ## @file 2 | # 3 | # Copyright (c) 2016, Intel Corporation. All rights reserved.
4 | # This program and the accompanying materials are licensed and made available under 5 | # the terms and conditions of the BSD License that accompanies this distribution. 6 | # The full text of the license may be found at 7 | # http://opensource.org/licenses/bsd-license.php. 8 | # 9 | # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | # 12 | ## 13 | 14 | [Defines] 15 | INF_VERSION = 0x00010005 16 | BASE_NAME = CfgTestAgent 17 | FILE_GUID = FFDC78B1-A28F-4DD4-84A9-89222D97269C 18 | MODULE_TYPE = UEFI_DRIVER 19 | VERSION_STRING = 1.0 20 | ENTRY_POINT = CfgTestAgentInitialize 21 | 22 | [Sources] 23 | CfgTestAgent.c 24 | 25 | [Packages] 26 | MdePkg/MdePkg.dec 27 | 28 | [LibraryClasses] 29 | UefiDriverEntryPoint 30 | UefiBootServicesTableLib 31 | 32 | [BuildOptions] 33 | MSFT:*_*_*_CC_FLAGS = /Od /GL- /guard:cf 34 | # Using /SUBSYSTEM:EFI_BOOT_SERVICE_DRIVER will cause guard info stripped. 35 | # Need MSVCRTd.Lib to generate Guard Info 36 | MSFT:*_*_*_DLINK_FLAGS = /guard:cf /SUBSYSTEM:CONSOLE MSVCRTD.lib 37 | MSFT:*_VS2015x86_IA32_DLINK_FLAGS = /LIBPATH:"$(VCINSTALLDIR)\Lib" 38 | MSFT:*_VS2015x86_X64_DLINK_FLAGS = /LIBPATH:"$(VCINSTALLDIR)\Lib\AMD64" 39 | MSFT:*_VS2017_IA32_DLINK_FLAGS = /LIBPATH:"%VCToolsInstallDir%lib\x86" 40 | MSFT:*_VS2017_X64_DLINK_FLAGS = /LIBPATH:"%VCToolsInstallDir%lib\x64" 41 | 42 | GCC:*_CLANGPDB_*_CC_FLAGS = -O0 -fsanitize=cfi 43 | -------------------------------------------------------------------------------- /ControlFlowPkg/CfgTest/CfgTest/Ia32/ExternFunc.nasm: -------------------------------------------------------------------------------- 1 | ;------------------------------------------------------------------------------ ; 2 | ; Copyright (c) 2016, Intel Corporation. All rights reserved.
3 | ; This program and the accompanying materials 4 | ; are licensed and made available under the terms and conditions of the BSD License 5 | ; which accompanies this distribution. The full text of the license may be found at 6 | ; http://opensource.org/licenses/bsd-license.php. 7 | ; 8 | ; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 9 | ; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 10 | ; 11 | ;------------------------------------------------------------------------------- 12 | 13 | SECTION .text 14 | 15 | global ASM_PFX(ExternFunc) 16 | ASM_PFX(ExternFunc): 17 | nop 18 | ret 19 | 20 | global ASM_PFX(ExternFunc2) 21 | ASM_PFX(ExternFunc2): 22 | nop 23 | ret 24 | -------------------------------------------------------------------------------- /ControlFlowPkg/CfgTest/CfgTest/X64/ExternFunc.nasm: -------------------------------------------------------------------------------- 1 | ;------------------------------------------------------------------------------ ; 2 | ; Copyright (c) 2016, Intel Corporation. All rights reserved.
3 | ; This program and the accompanying materials 4 | ; are licensed and made available under the terms and conditions of the BSD License 5 | ; which accompanies this distribution. The full text of the license may be found at 6 | ; http://opensource.org/licenses/bsd-license.php. 7 | ; 8 | ; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 9 | ; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 10 | ; 11 | ;------------------------------------------------------------------------------- 12 | 13 | DEFAULT REL 14 | SECTION .text 15 | 16 | global ASM_PFX(ExternFunc) 17 | ASM_PFX(ExternFunc): 18 | nop 19 | ret 20 | 21 | global ASM_PFX(ExternFunc2) 22 | ASM_PFX(ExternFunc2): 23 | nop 24 | ret 25 | -------------------------------------------------------------------------------- /ControlFlowPkg/ControlFlowPkg.dec: -------------------------------------------------------------------------------- 1 | ## @file 2 | # 3 | # Copyright (c) 2012, Intel Corporation. All rights reserved.
4 | # 5 | # This program and the accompanying materials 6 | # are licensed and made available under the terms and conditions of the BSD License 7 | # which accompanies this distribution. The full text of the license may be found at 8 | # http://opensource.org/licenses/bsd-license.php 9 | # 10 | # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 12 | # 13 | ## 14 | 15 | [Defines] 16 | DEC_SPECIFICATION = 0x00010005 17 | PACKAGE_NAME = ControlFlowPkg 18 | PACKAGE_GUID = 59A1163D-E131-405E-954F-0C86CDBCECF8 19 | PACKAGE_VERSION = 0.1 20 | 21 | [Includes] 22 | -------------------------------------------------------------------------------- /ControlFlowPkg/DxeCet/Override/IntelFsp2WrapperPkg/Library/BaseFspWrapperApiLib/IA32/DispatchExecute.c: -------------------------------------------------------------------------------- 1 | /** @file 2 | Execute 32-bit code in Protected Mode. 3 | 4 | Copyright (c) 2014 - 2016, Intel Corporation. All rights reserved.
5 | This program and the accompanying materials 6 | are licensed and made available under the terms and conditions of the BSD License 7 | which accompanies this distribution. The full text of the license may be found at 8 | http://opensource.org/licenses/bsd-license.php. 9 | 10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 12 | 13 | **/ 14 | 15 | #include 16 | #include 17 | 18 | /** 19 | FSP API functions. 20 | 21 | @param[in] Param1 The first parameter to pass to 32bit code. 22 | @param[in] Param2 The second parameter to pass to 32bit code. 23 | 24 | @return EFI_STATUS. 25 | **/ 26 | typedef 27 | EFI_STATUS 28 | (EFIAPI *FSP_FUNCTION) ( 29 | IN VOID *Param1, 30 | IN VOID *Param2 31 | ); 32 | 33 | /** 34 | Wrapper for a thunk to transition from long mode to compatibility mode to execute 32-bit code and then transit back to 35 | long mode. 36 | 37 | @param[in] Function The 32bit code entry to be executed. 38 | @param[in] Param1 The first parameter to pass to 32bit code. 39 | @param[in] Param2 The second parameter to pass to 32bit code. 40 | 41 | @return EFI_STATUS. 42 | **/ 43 | EFI_STATUS 44 | Execute32BitCode ( 45 | IN UINT64 Function, 46 | IN UINT64 Param1, 47 | IN UINT64 Param2 48 | ) 49 | { 50 | FSP_FUNCTION EntryFunc; 51 | EFI_STATUS Status; 52 | 53 | EntryFunc = (FSP_FUNCTION) (UINTN) (Function); 54 | Status = EntryFunc ((VOID *)(UINTN)Param1, (VOID *)(UINTN)Param2); 55 | 56 | return Status; 57 | } 58 | 59 | -------------------------------------------------------------------------------- /ControlFlowPkg/DxeCet/Override/IntelFsp2WrapperPkg/Library/BaseFspWrapperApiLib/X64/Cet.nasm: -------------------------------------------------------------------------------- 1 | ;------------------------------------------------------------------------------ ; 2 | ; Copyright (c) 2018, Intel Corporation. All rights reserved.
3 | ; This program and the accompanying materials 4 | ; are licensed and made available under the terms and conditions of the BSD License 5 | ; which accompanies this distribution. The full text of the license may be found at 6 | ; http://opensource.org/licenses/bsd-license.php. 7 | ; 8 | ; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 9 | ; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 10 | ; 11 | ;------------------------------------------------------------------------------- 12 | 13 | DEFAULT REL 14 | SECTION .text 15 | 16 | global ASM_PFX(DisableCet) 17 | ASM_PFX(DisableCet): 18 | 19 | ; Skip the pushed data for call 20 | mov rax, 1 21 | DB 0xF3, 0x48, 0x0F, 0xAE, 0xE8 ; INCSSP RAX 22 | 23 | mov rax, cr4 24 | btr eax, 23 ; clear CET 25 | mov cr4, rax 26 | ret 27 | 28 | global ASM_PFX(EnableCet) 29 | ASM_PFX(EnableCet): 30 | 31 | mov rax, cr4 32 | bts eax, 23 ; set CET 33 | mov cr4, rax 34 | 35 | ; use jmp to skip the check for ret 36 | pop rax 37 | jmp rax 38 | 39 | -------------------------------------------------------------------------------- /ControlFlowPkg/DxeCet/Override/MdeModulePkg/Core/DxeIplPeim/DxeIpl.uni: -------------------------------------------------------------------------------- 1 | // /** @file 2 | // Last PEIM executed in PEI phase to load DXE Core from a Firmware Volume. 3 | // 4 | // This module produces a special PPI named the DXE Initial Program Load (IPL) 5 | // PPI to discover and dispatch the DXE Foundation and components that are 6 | // needed to run the DXE Foundation. 7 | // 8 | // Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.
9 | // 10 | // This program and the accompanying materials 11 | // are licensed and made available under the terms and conditions of the BSD License 12 | // which accompanies this distribution. The full text of the license may be found at 13 | // http://opensource.org/licenses/bsd-license.php 14 | // 15 | // THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 17 | // 18 | // **/ 19 | 20 | 21 | #string STR_MODULE_ABSTRACT #language en-US "Last PEIM executed in PEI phase to load DXE Core from a Firmware Volume" 22 | 23 | #string STR_MODULE_DESCRIPTION #language en-US "This module produces a special PPI named the DXE Initial Program Load (IPL) PPI to discover and dispatch the DXE Foundation and components that are needed to run the DXE Foundation." 24 | 25 | -------------------------------------------------------------------------------- /ControlFlowPkg/DxeCet/Override/MdeModulePkg/Core/DxeIplPeim/DxeIplExtra.uni: -------------------------------------------------------------------------------- 1 | // /** @file 2 | // DxeIpl Localized Strings and Content 3 | // 4 | // Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.
5 | // 6 | // This program and the accompanying materials 7 | // are licensed and made available under the terms and conditions of the BSD License 8 | // which accompanies this distribution. The full text of the license may be found at 9 | // http://opensource.org/licenses/bsd-license.php 10 | // 11 | // THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 13 | // 14 | // **/ 15 | 16 | #string STR_PROPERTIES_MODULE_NAME 17 | #language en-US 18 | "Core DXE Services Initial Program Loader" 19 | 20 | 21 | -------------------------------------------------------------------------------- /ControlFlowPkg/DxeCet/Override/MdeModulePkg/Core/DxeIplPeim/Ebc/DxeLoadFunc.c: -------------------------------------------------------------------------------- 1 | /** @file 2 | EBC-specific functionality for DxeLoad. 3 | 4 | Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.
5 | This program and the accompanying materials 6 | are licensed and made available under the terms and conditions of the BSD License 7 | which accompanies this distribution. The full text of the license may be found at 8 | http://opensource.org/licenses/bsd-license.php 9 | 10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 12 | 13 | **/ 14 | 15 | #include "DxeIpl.h" 16 | 17 | 18 | 19 | /** 20 | Transfers control to DxeCore. 21 | 22 | This function performs a CPU architecture specific operations to execute 23 | the entry point of DxeCore with the parameters of HobList. 24 | It also installs EFI_END_OF_PEI_PPI to signal the end of PEI phase. 25 | 26 | @param DxeCoreEntryPoint The entry point of DxeCore. 27 | @param HobList The start of HobList passed to DxeCore. 28 | 29 | **/ 30 | VOID 31 | HandOffToDxeCore ( 32 | IN EFI_PHYSICAL_ADDRESS DxeCoreEntryPoint, 33 | IN EFI_PEI_HOB_POINTERS HobList 34 | ) 35 | { 36 | VOID *BaseOfStack; 37 | VOID *TopOfStack; 38 | EFI_STATUS Status; 39 | 40 | // 41 | // Allocate 128KB for the Stack 42 | // 43 | BaseOfStack = AllocatePages (EFI_SIZE_TO_PAGES (STACK_SIZE)); 44 | ASSERT (BaseOfStack != NULL); 45 | 46 | // 47 | // Compute the top of the stack we were allocated. Pre-allocate a UINTN 48 | // for safety. 49 | // 50 | TopOfStack = (VOID *) ((UINTN) BaseOfStack + EFI_SIZE_TO_PAGES (STACK_SIZE) * EFI_PAGE_SIZE - CPU_STACK_ALIGNMENT); 51 | TopOfStack = ALIGN_POINTER (TopOfStack, CPU_STACK_ALIGNMENT); 52 | 53 | // 54 | // End of PEI phase signal 55 | // 56 | Status = PeiServicesInstallPpi (&gEndOfPeiSignalPpi); 57 | ASSERT_EFI_ERROR (Status); 58 | 59 | // 60 | // Update the contents of BSP stack HOB to reflect the real stack info passed to DxeCore. 61 | // 62 | UpdateStackHob ((EFI_PHYSICAL_ADDRESS)(UINTN) BaseOfStack, STACK_SIZE); 63 | 64 | // 65 | // Transfer the control to the entry point of DxeCore. 66 | // 67 | SwitchStack ( 68 | (SWITCH_STACK_ENTRY_POINT)(UINTN)DxeCoreEntryPoint, 69 | HobList.Raw, 70 | NULL, 71 | TopOfStack 72 | ); 73 | } 74 | -------------------------------------------------------------------------------- /ControlFlowPkg/DxeCet/Override/UefiCpuPkg/CpuDxe/CpuDxe.uni: -------------------------------------------------------------------------------- 1 | // /** @file 2 | // CPU driver installs CPU Architecture Protocol and CPU MP Protocol. 3 | // 4 | // CPU driver installs CPU Architecture Protocol and CPU MP Protocol. 5 | // 6 | // Copyright (c) 2008 - 2018, Intel Corporation. All rights reserved.
7 | // 8 | // This program and the accompanying materials 9 | // are licensed and made available under the terms and conditions of the BSD License 10 | // which accompanies this distribution. The full text of the license may be found at 11 | // http://opensource.org/licenses/bsd-license.php 12 | // 13 | // THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 15 | // 16 | // **/ 17 | 18 | 19 | #string STR_MODULE_ABSTRACT #language en-US "CPU driver installs CPU Architecture Protocol and CPU MP Protocol." 20 | 21 | #string STR_MODULE_DESCRIPTION #language en-US "CPU driver installs CPU Architecture Protocol and CPU MP Protocol." 22 | 23 | -------------------------------------------------------------------------------- /ControlFlowPkg/DxeCet/Override/UefiCpuPkg/CpuDxe/CpuDxeExtra.uni: -------------------------------------------------------------------------------- 1 | // /** @file 2 | // CpuDxe Localized Strings and Content 3 | // 4 | // Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.
5 | // 6 | // This program and the accompanying materials 7 | // are licensed and made available under the terms and conditions of the BSD License 8 | // which accompanies this distribution. The full text of the license may be found at 9 | // http://opensource.org/licenses/bsd-license.php 10 | // 11 | // THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 13 | // 14 | // **/ 15 | 16 | #string STR_PROPERTIES_MODULE_NAME 17 | #language en-US 18 | "CPU Architectural and CPU Multi-processor DXE Driver" 19 | 20 | 21 | -------------------------------------------------------------------------------- /ControlFlowPkg/DxeCet/Override/UefiCpuPkg/CpuDxe/CpuGdt.h: -------------------------------------------------------------------------------- 1 | /** @file 2 | C based implemention of IA32 interrupt handling only 3 | requiring a minimal assembly interrupt entry point. 4 | 5 | Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.
6 | This program and the accompanying materials 7 | are licensed and made available under the terms and conditions of the BSD License 8 | which accompanies this distribution. The full text of the license may be found at 9 | http://opensource.org/licenses/bsd-license.php 10 | 11 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 13 | 14 | **/ 15 | 16 | #ifndef _CPU_GDT_H_ 17 | #define _CPU_GDT_H_ 18 | 19 | // 20 | // Local structure definitions 21 | // 22 | 23 | #pragma pack (1) 24 | 25 | // 26 | // Global Descriptor Entry structures 27 | // 28 | 29 | typedef struct _GDT_ENTRY { 30 | UINT16 Limit15_0; 31 | UINT16 Base15_0; 32 | UINT8 Base23_16; 33 | UINT8 Type; 34 | UINT8 Limit19_16_and_flags; 35 | UINT8 Base31_24; 36 | } GDT_ENTRY; 37 | 38 | typedef 39 | struct _GDT_ENTRIES { 40 | GDT_ENTRY Null; 41 | GDT_ENTRY Linear; 42 | GDT_ENTRY LinearCode; 43 | GDT_ENTRY SysData; 44 | GDT_ENTRY SysCode; 45 | GDT_ENTRY Spare4; 46 | GDT_ENTRY LinearData64; 47 | GDT_ENTRY LinearCode64; 48 | GDT_ENTRY Spare5; 49 | } GDT_ENTRIES; 50 | 51 | #pragma pack () 52 | 53 | #define NULL_SEL OFFSET_OF (GDT_ENTRIES, Null) 54 | #define LINEAR_SEL OFFSET_OF (GDT_ENTRIES, Linear) 55 | #define LINEAR_CODE_SEL OFFSET_OF (GDT_ENTRIES, LinearCode) 56 | #define SYS_DATA_SEL OFFSET_OF (GDT_ENTRIES, SysData) 57 | #define SYS_CODE_SEL OFFSET_OF (GDT_ENTRIES, SysCode) 58 | #define SPARE4_SEL OFFSET_OF (GDT_ENTRIES, Spare4) 59 | #define LINEAR_DATA64_SEL OFFSET_OF (GDT_ENTRIES, LinearData64) 60 | #define LINEAR_CODE64_SEL OFFSET_OF (GDT_ENTRIES, LinearCode64) 61 | #define SPARE5_SEL OFFSET_OF (GDT_ENTRIES, Spare5) 62 | 63 | #if defined (MDE_CPU_IA32) 64 | #define CPU_CODE_SEL LINEAR_CODE_SEL 65 | #define CPU_DATA_SEL LINEAR_SEL 66 | #elif defined (MDE_CPU_X64) 67 | #define CPU_CODE_SEL LINEAR_CODE64_SEL 68 | #define CPU_DATA_SEL LINEAR_DATA64_SEL 69 | #else 70 | #error CPU type not supported for CPU GDT initialization! 71 | #endif 72 | 73 | #endif // _CPU_GDT_H_ 74 | 75 | -------------------------------------------------------------------------------- /ControlFlowPkg/DxeCet/Override/UefiCpuPkg/CpuDxe/Ia32/Cet.nasm: -------------------------------------------------------------------------------- 1 | ;------------------------------------------------------------------------------ ; 2 | ; Copyright (c) 2019, Intel Corporation. All rights reserved.
3 | ; This program and the accompanying materials 4 | ; are licensed and made available under the terms and conditions of the BSD License 5 | ; which accompanies this distribution. The full text of the license may be found at 6 | ; http://opensource.org/licenses/bsd-license.php. 7 | ; 8 | ; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 9 | ; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 10 | ; 11 | ;------------------------------------------------------------------------------- 12 | 13 | SECTION .text 14 | 15 | global ASM_PFX(DisableCet) 16 | ASM_PFX(DisableCet): 17 | 18 | ; Skip the pushed data for call 19 | mov eax, 1 20 | DB 0xF3, 0x0F, 0xAE, 0xE8 ; INCSSP RAX 21 | 22 | mov eax, cr4 23 | btr eax, 23 ; clear CET 24 | mov cr4, eax 25 | ret 26 | 27 | global ASM_PFX(EnableCet) 28 | ASM_PFX(EnableCet): 29 | 30 | mov eax, cr4 31 | bts eax, 23 ; set CET 32 | mov cr4, eax 33 | 34 | ; use jmp to skip the check for ret 35 | pop eax 36 | jmp eax 37 | 38 | -------------------------------------------------------------------------------- /ControlFlowPkg/DxeCet/Override/UefiCpuPkg/CpuDxe/Ia32/CpuAsm.nasm: -------------------------------------------------------------------------------- 1 | ;------------------------------------------------------------------------------ 2 | ;* 3 | ;* Copyright (c) 2016, Intel Corporation. All rights reserved.
4 | ;* This program and the accompanying materials 5 | ;* are licensed and made available under the terms and conditions of the BSD License 6 | ;* which accompanies this distribution. The full text of the license may be found at 7 | ;* http://opensource.org/licenses/bsd-license.php 8 | ;* 9 | ;* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | ;* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | ;* 12 | ;* CpuAsm.nasm 13 | ;* 14 | ;* Abstract: 15 | ;* 16 | ;------------------------------------------------------------------------------ 17 | 18 | SECTION .text 19 | 20 | ;------------------------------------------------------------------------------ 21 | ; VOID 22 | ; SetCodeSelector ( 23 | ; UINT16 Selector 24 | ; ); 25 | ;------------------------------------------------------------------------------ 26 | global ASM_PFX(SetCodeSelector) 27 | ASM_PFX(SetCodeSelector): 28 | mov ecx, [esp+4] 29 | sub esp, 0x10 30 | lea eax, [setCodeSelectorLongJump] 31 | mov [esp], eax 32 | mov [esp+4], cx 33 | jmp dword far [esp] 34 | setCodeSelectorLongJump: 35 | add esp, 0x10 36 | ret 37 | 38 | ;------------------------------------------------------------------------------ 39 | ; VOID 40 | ; SetDataSelectors ( 41 | ; UINT16 Selector 42 | ; ); 43 | ;------------------------------------------------------------------------------ 44 | global ASM_PFX(SetDataSelectors) 45 | ASM_PFX(SetDataSelectors): 46 | mov ecx, [esp+4] 47 | o16 mov ss, cx 48 | o16 mov ds, cx 49 | o16 mov es, cx 50 | o16 mov fs, cx 51 | o16 mov gs, cx 52 | ret 53 | 54 | -------------------------------------------------------------------------------- /ControlFlowPkg/DxeCet/Override/UefiCpuPkg/CpuDxe/X64/Cet.nasm: -------------------------------------------------------------------------------- 1 | ;------------------------------------------------------------------------------ ; 2 | ; Copyright (c) 2019, Intel Corporation. All rights reserved.
3 | ; This program and the accompanying materials 4 | ; are licensed and made available under the terms and conditions of the BSD License 5 | ; which accompanies this distribution. The full text of the license may be found at 6 | ; http://opensource.org/licenses/bsd-license.php. 7 | ; 8 | ; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 9 | ; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 10 | ; 11 | ;------------------------------------------------------------------------------- 12 | 13 | DEFAULT REL 14 | SECTION .text 15 | 16 | global ASM_PFX(DisableCet) 17 | ASM_PFX(DisableCet): 18 | 19 | ; Skip the pushed data for call 20 | mov rax, 1 21 | DB 0xF3, 0x48, 0x0F, 0xAE, 0xE8 ; INCSSP RAX 22 | 23 | mov rax, cr4 24 | btr eax, 23 ; clear CET 25 | mov cr4, rax 26 | ret 27 | 28 | global ASM_PFX(EnableCet) 29 | ASM_PFX(EnableCet): 30 | 31 | mov rax, cr4 32 | bts eax, 23 ; set CET 33 | mov cr4, rax 34 | 35 | ; use jmp to skip the check for ret 36 | pop rax 37 | jmp rax 38 | 39 | -------------------------------------------------------------------------------- /ControlFlowPkg/DxeCet/Override/UefiCpuPkg/CpuDxe/X64/CpuAsm.nasm: -------------------------------------------------------------------------------- 1 | ;------------------------------------------------------------------------------ 2 | ;* 3 | ;* Copyright (c) 2016, Intel Corporation. All rights reserved.
4 | ;* This program and the accompanying materials 5 | ;* are licensed and made available under the terms and conditions of the BSD License 6 | ;* which accompanies this distribution. The full text of the license may be found at 7 | ;* http://opensource.org/licenses/bsd-license.php 8 | ;* 9 | ;* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | ;* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | ;* 12 | ;* CpuAsm.nasm 13 | ;* 14 | ;* Abstract: 15 | ;* 16 | ;------------------------------------------------------------------------------ 17 | 18 | DEFAULT REL 19 | SECTION .text 20 | 21 | ;------------------------------------------------------------------------------ 22 | ; VOID 23 | ; SetCodeSelector ( 24 | ; UINT16 Selector 25 | ; ); 26 | ;------------------------------------------------------------------------------ 27 | global ASM_PFX(SetCodeSelector) 28 | ASM_PFX(SetCodeSelector): 29 | sub rsp, 0x10 30 | lea rax, [setCodeSelectorLongJump] 31 | mov [rsp], rax 32 | mov [rsp+4], cx 33 | jmp dword far [rsp] 34 | setCodeSelectorLongJump: 35 | add rsp, 0x10 36 | ret 37 | 38 | ;------------------------------------------------------------------------------ 39 | ; VOID 40 | ; SetDataSelectors ( 41 | ; UINT16 Selector 42 | ; ); 43 | ;------------------------------------------------------------------------------ 44 | global ASM_PFX(SetDataSelectors) 45 | ASM_PFX(SetDataSelectors): 46 | o16 mov ss, cx 47 | o16 mov ds, cx 48 | o16 mov es, cx 49 | o16 mov fs, cx 50 | o16 mov gs, cx 51 | ret 52 | 53 | -------------------------------------------------------------------------------- /ControlFlowPkg/Ibt/Override/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.inf: -------------------------------------------------------------------------------- 1 | ## @file 2 | # CPU Exception Handler library instance for DXE modules. 3 | # 4 | # Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.
5 | # This program and the accompanying materials 6 | # are licensed and made available under the terms and conditions of the BSD License 7 | # which accompanies this distribution. The full text of the license may be found at 8 | # http://opensource.org/licenses/bsd-license.php 9 | # 10 | # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 12 | # 13 | ## 14 | 15 | [Defines] 16 | INF_VERSION = 0x00010005 17 | BASE_NAME = DxeCpuExceptionHandlerLib 18 | MODULE_UNI_FILE = DxeCpuExceptionHandlerLib.uni 19 | FILE_GUID = B6E9835A-EDCF-4748-98A8-27D3C722E02D 20 | MODULE_TYPE = DXE_DRIVER 21 | VERSION_STRING = 1.1 22 | LIBRARY_CLASS = CpuExceptionHandlerLib|DXE_CORE DXE_DRIVER UEFI_APPLICATION 23 | 24 | # 25 | # The following information is for reference only and not required by the build tools. 26 | # 27 | # VALID_ARCHITECTURES = IA32 X64 28 | # 29 | 30 | [Sources.Ia32] 31 | Ia32/ExceptionHandlerAsm.nasm 32 | Ia32/ExceptionTssEntryAsm.nasm 33 | Ia32/ExceptionHandlerAsm.S 34 | Ia32/ArchExceptionHandler.c 35 | Ia32/ArchInterruptDefs.h 36 | 37 | [Sources.X64] 38 | X64/ExceptionHandlerAsm.nasm 39 | X64/ExceptionHandlerAsm.S 40 | X64/ArchExceptionHandler.c 41 | X64/ArchInterruptDefs.h 42 | 43 | [Sources.common] 44 | CpuExceptionCommon.h 45 | CpuExceptionCommon.c 46 | PeiDxeSmmCpuException.c 47 | DxeException.c 48 | 49 | [Pcd] 50 | gEfiMdeModulePkgTokenSpaceGuid.PcdCpuStackGuard 51 | gUefiCpuPkgTokenSpaceGuid.PcdCpuStackSwitchExceptionList 52 | gUefiCpuPkgTokenSpaceGuid.PcdCpuKnownGoodStackSize 53 | 54 | [Packages] 55 | MdePkg/MdePkg.dec 56 | MdeModulePkg/MdeModulePkg.dec 57 | UefiCpuPkg/UefiCpuPkg.dec 58 | 59 | [LibraryClasses] 60 | BaseLib 61 | SerialPortLib 62 | PrintLib 63 | SynchronizationLib 64 | LocalApicLib 65 | PeCoffGetEntryPointLib 66 | MemoryAllocationLib 67 | DebugLib 68 | -------------------------------------------------------------------------------- /ControlFlowPkg/Ibt/Override/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.uni: -------------------------------------------------------------------------------- 1 | // /** @file 2 | // CPU Exception Handler library instance for DXE modules. 3 | // 4 | // CPU Exception Handler library instance for DXE modules. 5 | // 6 | // Copyright (c) 2013 - 2014, Intel Corporation. All rights reserved.
7 | // 8 | // This program and the accompanying materials 9 | // are licensed and made available under the terms and conditions of the BSD License 10 | // which accompanies this distribution. The full text of the license may be found at 11 | // http://opensource.org/licenses/bsd-license.php 12 | // 13 | // THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 15 | // 16 | // **/ 17 | 18 | 19 | #string STR_MODULE_ABSTRACT #language en-US "CPU Exception Handler library instance for DXE modules." 20 | 21 | #string STR_MODULE_DESCRIPTION #language en-US "CPU Exception Handler library instance for DXE modules." 22 | 23 | -------------------------------------------------------------------------------- /ControlFlowPkg/Ibt/Override/UefiCpuPkg/Library/CpuExceptionHandlerLib/Ia32/ArchInterruptDefs.h: -------------------------------------------------------------------------------- 1 | /** @file 2 | Ia32 arch definition for CPU Exception Handler Library. 3 | 4 | Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.
5 | This program and the accompanying materials 6 | are licensed and made available under the terms and conditions of the BSD License 7 | which accompanies this distribution. The full text of the license may be found at 8 | http://opensource.org/licenses/bsd-license.php 9 | 10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 12 | 13 | **/ 14 | 15 | #ifndef _ARCH_CPU_INTERRUPT_DEFS_H_ 16 | #define _ARCH_CPU_INTERRUPT_DEFS_H_ 17 | 18 | typedef struct { 19 | EFI_SYSTEM_CONTEXT_IA32 SystemContext; 20 | BOOLEAN ExceptionDataFlag; 21 | UINTN OldIdtHandler; 22 | } EXCEPTION_HANDLER_CONTEXT; 23 | 24 | // 25 | // Register Structure Definitions 26 | // 27 | typedef struct { 28 | EFI_STATUS_CODE_DATA Header; 29 | EFI_SYSTEM_CONTEXT_IA32 SystemContext; 30 | } CPU_STATUS_CODE_TEMPLATE; 31 | 32 | typedef struct { 33 | SPIN_LOCK SpinLock; 34 | UINT32 ApicId; 35 | UINT32 Attribute; 36 | UINTN ExceptonHandler; 37 | UINTN OldFlags; 38 | UINTN OldCs; 39 | UINTN OldIp; 40 | UINTN ExceptionData; 41 | UINT8 HookAfterStubHeaderCode[HOOKAFTER_STUB_SIZE]; 42 | } RESERVED_VECTORS_DATA; 43 | 44 | #define CPU_TSS_DESC_SIZE \ 45 | (sizeof (IA32_TSS_DESCRIPTOR) * \ 46 | (FixedPcdGetSize (PcdCpuStackSwitchExceptionList) + 1)) 47 | 48 | #define CPU_TSS_SIZE \ 49 | (sizeof (IA32_TASK_STATE_SEGMENT) * \ 50 | (FixedPcdGetSize (PcdCpuStackSwitchExceptionList) + 1)) 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /ControlFlowPkg/Ibt/Override/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuExceptionHandlerLib.inf: -------------------------------------------------------------------------------- 1 | ## @file 2 | # CPU Exception Handler library instance for PEI module. 3 | # 4 | # Copyright (c) 2016 - 2018, Intel Corporation. All rights reserved.
5 | # This program and the accompanying materials 6 | # are licensed and made available under the terms and conditions of the BSD License 7 | # which accompanies this distribution. The full text of the license may be found at 8 | # http://opensource.org/licenses/bsd-license.php 9 | # 10 | # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 12 | # 13 | ## 14 | 15 | [Defines] 16 | INF_VERSION = 0x00010005 17 | BASE_NAME = PeiCpuExceptionHandlerLib 18 | MODULE_UNI_FILE = PeiCpuExceptionHandlerLib.uni 19 | FILE_GUID = 980DDA67-44A6-4897-99E6-275290B71F9E 20 | MODULE_TYPE = PEIM 21 | VERSION_STRING = 1.1 22 | LIBRARY_CLASS = CpuExceptionHandlerLib|PEI_CORE PEIM 23 | 24 | # 25 | # The following information is for reference only and not required by the build tools. 26 | # 27 | # VALID_ARCHITECTURES = IA32 X64 28 | # 29 | 30 | [Sources.Ia32] 31 | Ia32/ExceptionHandlerAsm.nasm 32 | Ia32/ExceptionTssEntryAsm.nasm 33 | Ia32/ExceptionHandlerAsm.S 34 | Ia32/ArchExceptionHandler.c 35 | Ia32/ArchInterruptDefs.h 36 | 37 | [Sources.X64] 38 | X64/ExceptionHandlerAsm.nasm 39 | X64/ExceptionHandlerAsm.S 40 | X64/ArchExceptionHandler.c 41 | X64/ArchInterruptDefs.h 42 | 43 | [Sources.common] 44 | CpuExceptionCommon.h 45 | CpuExceptionCommon.c 46 | PeiCpuException.c 47 | PeiDxeSmmCpuException.c 48 | 49 | [Packages] 50 | MdePkg/MdePkg.dec 51 | MdeModulePkg/MdeModulePkg.dec 52 | UefiCpuPkg/UefiCpuPkg.dec 53 | 54 | [LibraryClasses] 55 | BaseLib 56 | SerialPortLib 57 | PrintLib 58 | LocalApicLib 59 | PeCoffGetEntryPointLib 60 | HobLib 61 | MemoryAllocationLib 62 | SynchronizationLib 63 | 64 | [Pcd] 65 | gEfiMdeModulePkgTokenSpaceGuid.PcdCpuStackGuard # CONSUMES 66 | 67 | -------------------------------------------------------------------------------- /ControlFlowPkg/Ibt/Override/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuExceptionHandlerLib.uni: -------------------------------------------------------------------------------- 1 | // /** @file 2 | // CPU Exception Handler library instance for PEI module. 3 | // 4 | // CPU Exception Handler library instance for PEI module. 5 | // 6 | // Copyright (c) 2016, Intel Corporation. All rights reserved.
7 | // 8 | // This program and the accompanying materials 9 | // are licensed and made available under the terms and conditions of the BSD License 10 | // which accompanies this distribution. The full text of the license may be found at 11 | // http://opensource.org/licenses/bsd-license.php 12 | // 13 | // THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 15 | // 16 | // **/ 17 | 18 | 19 | #string STR_MODULE_ABSTRACT #language en-US "CPU Exception Handler library instance for PEI module." 20 | 21 | #string STR_MODULE_DESCRIPTION #language en-US "CPU Exception Handler library instance for PEI module." 22 | 23 | -------------------------------------------------------------------------------- /ControlFlowPkg/Ibt/Override/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuExceptionHandlerLib.inf: -------------------------------------------------------------------------------- 1 | ## @file 2 | # CPU Exception Handler library instance for SEC/PEI modules. 3 | # 4 | # Copyright (c) 2012 - 2018, Intel Corporation. All rights reserved.
5 | # This program and the accompanying materials 6 | # are licensed and made available under the terms and conditions of the BSD License 7 | # which accompanies this distribution. The full text of the license may be found at 8 | # http://opensource.org/licenses/bsd-license.php 9 | # 10 | # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 12 | # 13 | ## 14 | 15 | [Defines] 16 | INF_VERSION = 0x00010005 17 | BASE_NAME = SecPeiCpuExceptionHandlerLib 18 | MODULE_UNI_FILE = SecPeiCpuExceptionHandlerLib.uni 19 | FILE_GUID = CA4BBC99-DFC6-4234-B553-8B6586B7B113 20 | MODULE_TYPE = PEIM 21 | VERSION_STRING = 1.1 22 | LIBRARY_CLASS = CpuExceptionHandlerLib|SEC PEI_CORE PEIM 23 | 24 | # 25 | # The following information is for reference only and not required by the build tools. 26 | # 27 | # VALID_ARCHITECTURES = IA32 X64 28 | # 29 | 30 | [Sources.Ia32] 31 | Ia32/ExceptionHandlerAsm.nasm 32 | Ia32/ExceptionTssEntryAsm.nasm 33 | Ia32/ExceptionHandlerAsm.S 34 | Ia32/ArchExceptionHandler.c 35 | Ia32/ArchInterruptDefs.h 36 | 37 | [Sources.X64] 38 | X64/ExceptionHandlerAsm.nasm 39 | X64/ExceptionHandlerAsm.S 40 | X64/ArchExceptionHandler.c 41 | X64/ArchInterruptDefs.h 42 | 43 | [Sources.common] 44 | CpuExceptionCommon.h 45 | CpuExceptionCommon.c 46 | SecPeiCpuException.c 47 | 48 | [Packages] 49 | MdePkg/MdePkg.dec 50 | MdeModulePkg/MdeModulePkg.dec 51 | UefiCpuPkg/UefiCpuPkg.dec 52 | 53 | [LibraryClasses] 54 | BaseLib 55 | SerialPortLib 56 | PrintLib 57 | LocalApicLib 58 | PeCoffGetEntryPointLib 59 | -------------------------------------------------------------------------------- /ControlFlowPkg/Ibt/Override/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuExceptionHandlerLib.uni: -------------------------------------------------------------------------------- 1 | // /** @file 2 | // CPU Exception Handler library instance for SEC/PEI modules. 3 | // 4 | // CPU Exception Handler library instance for SEC/PEI modules. 5 | // 6 | // Copyright (c) 2012 - 2014, Intel Corporation. All rights reserved.
7 | // 8 | // This program and the accompanying materials 9 | // are licensed and made available under the terms and conditions of the BSD License 10 | // which accompanies this distribution. The full text of the license may be found at 11 | // http://opensource.org/licenses/bsd-license.php 12 | // 13 | // THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 15 | // 16 | // **/ 17 | 18 | 19 | #string STR_MODULE_ABSTRACT #language en-US "CPU Exception Handler library instance for SEC/PEI modules." 20 | 21 | #string STR_MODULE_DESCRIPTION #language en-US "CPU Exception Handler library instance for SEC/PEI modules." 22 | 23 | -------------------------------------------------------------------------------- /ControlFlowPkg/Ibt/Override/UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmCpuExceptionHandlerLib.inf: -------------------------------------------------------------------------------- 1 | ## @file 2 | # CPU Exception Handler library instance for SMM modules. 3 | # 4 | # Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.
5 | # This program and the accompanying materials 6 | # are licensed and made available under the terms and conditions of the BSD License 7 | # which accompanies this distribution. The full text of the license may be found at 8 | # http://opensource.org/licenses/bsd-license.php 9 | # 10 | # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 12 | # 13 | ## 14 | 15 | [Defines] 16 | INF_VERSION = 0x00010005 17 | BASE_NAME = SmmCpuExceptionHandlerLib 18 | MODULE_UNI_FILE = SmmCpuExceptionHandlerLib.uni 19 | FILE_GUID = 8D2C439B-3981-42ff-9CE5-1B50ECA502D6 20 | MODULE_TYPE = DXE_SMM_DRIVER 21 | VERSION_STRING = 1.1 22 | LIBRARY_CLASS = CpuExceptionHandlerLib|DXE_SMM_DRIVER 23 | 24 | # 25 | # The following information is for reference only and not required by the build tools. 26 | # 27 | # VALID_ARCHITECTURES = IA32 X64 28 | # 29 | 30 | [Sources.Ia32] 31 | Ia32/ExceptionHandlerAsm.nasm 32 | Ia32/ExceptionTssEntryAsm.nasm 33 | Ia32/ExceptionHandlerAsm.S 34 | Ia32/ArchExceptionHandler.c 35 | Ia32/ArchInterruptDefs.h 36 | 37 | [Sources.X64] 38 | X64/ExceptionHandlerAsm.nasm 39 | X64/ExceptionHandlerAsm.S 40 | X64/ArchExceptionHandler.c 41 | X64/ArchInterruptDefs.h 42 | 43 | [Sources.common] 44 | CpuExceptionCommon.h 45 | CpuExceptionCommon.c 46 | PeiDxeSmmCpuException.c 47 | SmmException.c 48 | 49 | [Packages] 50 | MdePkg/MdePkg.dec 51 | MdeModulePkg/MdeModulePkg.dec 52 | UefiCpuPkg/UefiCpuPkg.dec 53 | 54 | [LibraryClasses] 55 | BaseLib 56 | SerialPortLib 57 | PrintLib 58 | SynchronizationLib 59 | LocalApicLib 60 | PeCoffGetEntryPointLib 61 | DebugLib 62 | 63 | -------------------------------------------------------------------------------- /ControlFlowPkg/Ibt/Override/UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmCpuExceptionHandlerLib.uni: -------------------------------------------------------------------------------- 1 | // /** @file 2 | // CPU Exception Handler library instance for SMM modules. 3 | // 4 | // CPU Exception Handler library instance for SMM modules. 5 | // 6 | // Copyright (c) 2013 - 2014, Intel Corporation. All rights reserved.
7 | // 8 | // This program and the accompanying materials 9 | // are licensed and made available under the terms and conditions of the BSD License 10 | // which accompanies this distribution. The full text of the license may be found at 11 | // http://opensource.org/licenses/bsd-license.php 12 | // 13 | // THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 15 | // 16 | // **/ 17 | 18 | 19 | #string STR_MODULE_ABSTRACT #language en-US "CPU Exception Handler library instance for SMM modules." 20 | 21 | #string STR_MODULE_DESCRIPTION #language en-US "CPU Exception Handler library instance for SMM modules." 22 | 23 | -------------------------------------------------------------------------------- /ControlFlowPkg/Ibt/Override/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ArchInterruptDefs.h: -------------------------------------------------------------------------------- 1 | /** @file 2 | X64 arch definition for CPU Exception Handler Library. 3 | 4 | Copyright (c) 2013, Intel Corporation. All rights reserved.
5 | This program and the accompanying materials 6 | are licensed and made available under the terms and conditions of the BSD License 7 | which accompanies this distribution. The full text of the license may be found at 8 | http://opensource.org/licenses/bsd-license.php 9 | 10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 12 | 13 | **/ 14 | 15 | #ifndef _ARCH_CPU_INTERRUPT_DEFS_H_ 16 | #define _ARCH_CPU_INTERRUPT_DEFS_H_ 17 | 18 | typedef struct { 19 | EFI_SYSTEM_CONTEXT_X64 SystemContext; 20 | BOOLEAN ExceptionDataFlag; 21 | UINTN OldIdtHandler; 22 | } EXCEPTION_HANDLER_CONTEXT; 23 | 24 | // 25 | // Register Structure Definitions 26 | // 27 | typedef struct { 28 | EFI_STATUS_CODE_DATA Header; 29 | EFI_SYSTEM_CONTEXT_X64 SystemContext; 30 | } CPU_STATUS_CODE_TEMPLATE; 31 | 32 | typedef struct { 33 | SPIN_LOCK SpinLock; 34 | UINT32 ApicId; 35 | UINT32 Attribute; 36 | UINTN ExceptonHandler; 37 | UINTN OldSs; 38 | UINTN OldSp; 39 | UINTN OldFlags; 40 | UINTN OldCs; 41 | UINTN OldIp; 42 | UINTN ExceptionData; 43 | UINT8 HookAfterStubHeaderCode[HOOKAFTER_STUB_SIZE]; 44 | } RESERVED_VECTORS_DATA; 45 | 46 | #define CPU_TSS_DESC_SIZE sizeof (IA32_TSS_DESCRIPTOR) 47 | #define CPU_TSS_SIZE sizeof (IA32_TASK_STATE_SEGMENT) 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /ControlFlowPkg/Ibt/Override/UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/Cet.nasm: -------------------------------------------------------------------------------- 1 | ;------------------------------------------------------------------------------ ; 2 | ; Copyright (c) 2019, Intel Corporation. All rights reserved.
3 | ; This program and the accompanying materials 4 | ; are licensed and made available under the terms and conditions of the BSD License 5 | ; which accompanies this distribution. The full text of the license may be found at 6 | ; http://opensource.org/licenses/bsd-license.php. 7 | ; 8 | ; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 9 | ; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 10 | ; 11 | ;------------------------------------------------------------------------------- 12 | 13 | %include "Nasm.inc" 14 | 15 | SECTION .text 16 | 17 | global ASM_PFX(DisableCet) 18 | ASM_PFX(DisableCet): 19 | 20 | ; Skip the pushed data for call 21 | mov eax, 1 22 | INCSSP_EAX 23 | 24 | mov eax, cr4 25 | btr eax, 23 ; clear CET 26 | mov cr4, eax 27 | ret 28 | 29 | global ASM_PFX(EnableCet) 30 | ASM_PFX(EnableCet): 31 | 32 | mov eax, cr4 33 | bts eax, 23 ; set CET 34 | mov cr4, eax 35 | 36 | ; use jmp to skip the check for ret 37 | pop eax 38 | jmp eax 39 | 40 | -------------------------------------------------------------------------------- /ControlFlowPkg/Ibt/Override/UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/Semaphore.c: -------------------------------------------------------------------------------- 1 | /** @file 2 | Semaphore mechanism to indicate to the BSP that an AP has exited SMM 3 | after SMBASE relocation. 4 | 5 | Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.
6 | This program and the accompanying materials 7 | are licensed and made available under the terms and conditions of the BSD License 8 | which accompanies this distribution. The full text of the license may be found at 9 | http://opensource.org/licenses/bsd-license.php 10 | 11 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 13 | 14 | **/ 15 | 16 | #include "PiSmmCpuDxeSmm.h" 17 | 18 | UINTN mSmmRelocationOriginalAddress; 19 | volatile BOOLEAN *mRebasedFlag; 20 | 21 | /** 22 | Hook return address of SMM Save State so that semaphore code 23 | can be executed immediately after AP exits SMM to indicate to 24 | the BSP that an AP has exited SMM after SMBASE relocation. 25 | 26 | @param[in] CpuIndex The processor index. 27 | @param[in] RebasedFlag A pointer to a flag that is set to TRUE 28 | immediately after AP exits SMM. 29 | 30 | **/ 31 | VOID 32 | SemaphoreHook ( 33 | IN UINTN CpuIndex, 34 | IN volatile BOOLEAN *RebasedFlag 35 | ) 36 | { 37 | SMRAM_SAVE_STATE_MAP *CpuState; 38 | 39 | mRebasedFlag = RebasedFlag; 40 | 41 | CpuState = (SMRAM_SAVE_STATE_MAP *)(UINTN)(SMM_DEFAULT_SMBASE + SMRAM_SAVE_STATE_MAP_OFFSET); 42 | mSmmRelocationOriginalAddress = (UINTN)HookReturnFromSmm ( 43 | CpuIndex, 44 | CpuState, 45 | (UINT64)(UINTN)&SmmRelocationSemaphoreComplete, 46 | (UINT64)(UINTN)&SmmRelocationSemaphoreComplete 47 | ); 48 | } 49 | -------------------------------------------------------------------------------- /ControlFlowPkg/Ibt/Override/UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/SmmProfileArch.c: -------------------------------------------------------------------------------- 1 | /** @file 2 | IA-32 processor specific functions to enable SMM profile. 3 | 4 | Copyright (c) 2012 - 2016, Intel Corporation. All rights reserved.
5 | This program and the accompanying materials 6 | are licensed and made available under the terms and conditions of the BSD License 7 | which accompanies this distribution. The full text of the license may be found at 8 | http://opensource.org/licenses/bsd-license.php 9 | 10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 12 | 13 | **/ 14 | 15 | #include "PiSmmCpuDxeSmm.h" 16 | #include "SmmProfileInternal.h" 17 | 18 | /** 19 | Create SMM page table for S3 path. 20 | 21 | **/ 22 | VOID 23 | InitSmmS3Cr3 ( 24 | VOID 25 | ) 26 | { 27 | mSmmS3ResumeState->SmmS3Cr3 = Gen4GPageTable (TRUE); 28 | 29 | return ; 30 | } 31 | 32 | /** 33 | Allocate pages for creating 4KB-page based on 2MB-page when page fault happens. 34 | 32-bit firmware does not need it. 35 | 36 | **/ 37 | VOID 38 | InitPagesForPFHandler ( 39 | VOID 40 | ) 41 | { 42 | } 43 | 44 | /** 45 | Update page table to map the memory correctly in order to make the instruction 46 | which caused page fault execute successfully. And it also save the original page 47 | table to be restored in single-step exception. 32-bit firmware does not need it. 48 | 49 | @param PageTable PageTable Address. 50 | @param PFAddress The memory address which caused page fault exception. 51 | @param CpuIndex The index of the processor. 52 | @param ErrorCode The Error code of exception. 53 | @param IsValidPFAddress The flag indicates if SMM profile data need be added. 54 | 55 | **/ 56 | VOID 57 | RestorePageTableAbove4G ( 58 | UINT64 *PageTable, 59 | UINT64 PFAddress, 60 | UINTN CpuIndex, 61 | UINTN ErrorCode, 62 | BOOLEAN *IsValidPFAddress 63 | ) 64 | { 65 | } 66 | 67 | /** 68 | Clear TF in FLAGS. 69 | 70 | @param SystemContext A pointer to the processor context when 71 | the interrupt occurred on the processor. 72 | 73 | **/ 74 | VOID 75 | ClearTrapFlag ( 76 | IN OUT EFI_SYSTEM_CONTEXT SystemContext 77 | ) 78 | { 79 | SystemContext.SystemContextIa32->Eflags &= (UINTN) ~BIT8; 80 | } 81 | -------------------------------------------------------------------------------- /ControlFlowPkg/Ibt/Override/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.uni: -------------------------------------------------------------------------------- 1 | // /** @file 2 | // CPU SMM driver. 3 | // 4 | // This SMM driver performs SMM initialization, deploy SMM Entry Vector, 5 | // provides CPU specific services in SMM. 6 | // 7 | // Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.
8 | // 9 | // This program and the accompanying materials are 10 | // licensed and made available under the terms and conditions of the BSD License 11 | // which accompanies this distribution. The full text of the license may be found at 12 | // http://opensource.org/licenses/bsd-license.php 13 | // 14 | // THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 15 | // WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 16 | // 17 | // **/ 18 | 19 | #string STR_MODULE_ABSTRACT #language en-US "CPU SMM driver" 20 | 21 | #string STR_MODULE_DESCRIPTION #language en-US "This SMM driver performs SMM initialization, deploys SMM Entry Vector, and provides CPU-specific services in SMM." 22 | -------------------------------------------------------------------------------- /ControlFlowPkg/Ibt/Override/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmmExtra.uni: -------------------------------------------------------------------------------- 1 | // /** @file 2 | // PiSmmCpuDxeSmm Localized Strings and Content 3 | // 4 | // Copyright (c) 2013 - 2015, Intel Corporation. All rights reserved.
5 | // 6 | // This program and the accompanying materials are 7 | // licensed and made available under the terms and conditions of the BSD License 8 | // which accompanies this distribution. The full text of the license may be found at 9 | // http://opensource.org/licenses/bsd-license.php 10 | // 11 | // THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 13 | // 14 | // **/ 15 | 16 | #string STR_PROPERTIES_MODULE_NAME 17 | #language en-US 18 | "Processor SMM Initialization DXE Driver" 19 | -------------------------------------------------------------------------------- /ControlFlowPkg/Ibt/Override/UefiCpuPkg/PiSmmCpuDxeSmm/X64/Cet.nasm: -------------------------------------------------------------------------------- 1 | ;------------------------------------------------------------------------------ ; 2 | ; Copyright (c) 2019, Intel Corporation. All rights reserved.
3 | ; This program and the accompanying materials 4 | ; are licensed and made available under the terms and conditions of the BSD License 5 | ; which accompanies this distribution. The full text of the license may be found at 6 | ; http://opensource.org/licenses/bsd-license.php. 7 | ; 8 | ; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 9 | ; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 10 | ; 11 | ;------------------------------------------------------------------------------- 12 | 13 | %include "Nasm.inc" 14 | 15 | DEFAULT REL 16 | SECTION .text 17 | 18 | global ASM_PFX(DisableCet) 19 | ASM_PFX(DisableCet): 20 | 21 | ; Skip the pushed data for call 22 | mov rax, 1 23 | INCSSP_RAX 24 | 25 | mov rax, cr4 26 | btr eax, 23 ; clear CET 27 | mov cr4, rax 28 | ret 29 | 30 | global ASM_PFX(EnableCet) 31 | ASM_PFX(EnableCet): 32 | 33 | mov rax, cr4 34 | bts eax, 23 ; set CET 35 | mov cr4, rax 36 | 37 | ; use jmp to skip the check for ret 38 | pop rax 39 | jmp rax 40 | 41 | -------------------------------------------------------------------------------- /ControlFlowPkg/Library/CfgStubLib/CfgProtocol.h: -------------------------------------------------------------------------------- 1 | /** @file 2 | 3 | Copyright (c) 2019, Intel Corporation. All rights reserved.
4 | This program and the accompanying materials 5 | are licensed and made available under the terms and conditions of the BSD License 6 | which accompanies this distribution. The full text of the license may be found at 7 | http://opensource.org/licenses/bsd-license.php. 8 | 9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | 12 | **/ 13 | 14 | #ifndef __CFG_PROTOCOL_H__ 15 | #define __CFG_PROTOCOL_H__ 16 | 17 | #define CFG_PROTOCOL_GUID \ 18 | { 0xa984b418, 0x8a15, 0x49c4, { 0xa0, 0x90, 0x67, 0x83, 0x99, 0xf8, 0xa6, 0x5d } } 19 | 20 | typedef struct { 21 | LIST_ENTRY Link; 22 | UINT32 *GuardCFFunctionTable; 23 | UINTN GuardCFFunctionCount; 24 | UINTN ImageBase; 25 | UINTN ImageSize; 26 | } CFG_NODE; 27 | 28 | typedef struct { 29 | LIST_ENTRY CfgNode; 30 | } CFG_PROTOCOL; 31 | 32 | extern EFI_GUID gCfgProtocolGuid; 33 | 34 | #endif -------------------------------------------------------------------------------- /ControlFlowPkg/Library/CfgStubLib/CfgStubLib.inf: -------------------------------------------------------------------------------- 1 | ## @file 2 | # 3 | # Copyright (c) 2010 Intel Corporation. All rights reserved.
4 | # This program and the accompanying materials are 5 | # licensed and made available under the terms and conditions of the BSD License 6 | # which accompanies this distribution. The full text of the license may be found at 7 | # http://opensource.org/licenses/bsd-license.php 8 | # 9 | # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | # 12 | ## 13 | 14 | [Defines] 15 | INF_VERSION = 0x00010005 16 | BASE_NAME = CfgLib 17 | FILE_GUID = 68E26A48-5625-49D3-8748-CAA4289EA686 18 | MODULE_TYPE = BASE 19 | VERSION_STRING = 1.0 20 | LIBRARY_CLASS = NULL 21 | CONSTRUCTOR = CfgLibConstructor 22 | DESTRUCTOR = CfgLibDestructor 23 | 24 | [Sources] 25 | CfgStub.c | MSFT 26 | UefiImage.c | MSFT 27 | WinNTServiceLibMsvc.c | MSFT # only for NT32 28 | CfiStub.c | GCC 29 | 30 | [Packages] 31 | MdePkg/MdePkg.dec 32 | 33 | [LibraryClasses] 34 | BaseLib 35 | UefiBootServicesTableLib 36 | 37 | [Protocols] 38 | gEfiLoadedImageProtocolGuid 39 | 40 | [BuildOptions] 41 | # warning C4054: 'type cast': from function pointer 'void (__fastcall *)(UINTN)' to data pointer 'void *' 42 | MSFT:*_*_*_CC_FLAGS = /Od /GL- /wd4054 /DWINNT 43 | GCC:*_*_*_CC_FLAGS = -O0 -------------------------------------------------------------------------------- /ControlFlowPkg/Library/CfgStubLib/CfiStub.c: -------------------------------------------------------------------------------- 1 | /** @file 2 | Entry point library instance to a UEFI application. 3 | 4 | Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.
5 | This program and the accompanying materials 6 | are licensed and made available under the terms and conditions of the BSD License 7 | which accompanies this distribution. The full text of the license may be found at 8 | http://opensource.org/licenses/bsd-license.php. 9 | 10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 12 | 13 | **/ 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include "PeLoadConfiguration.h" 23 | #include "CfgProtocol.h" 24 | 25 | #if defined(__GNUC__) || defined(__clang__) 26 | #define GLOBAL_USED __attribute__((used)) 27 | #else 28 | #define GLOBAL_USED 29 | #endif 30 | 31 | GLOBAL_USED 32 | VOID 33 | EFIAPI 34 | MyTrap ( 35 | VOID 36 | ) 37 | { 38 | DEBUG ((DEBUG_ERROR, "\n!!! cfi check fail !!!\n")); 39 | ASSERT (FALSE); 40 | 41 | CpuDeadLoop(); 42 | } 43 | 44 | RETURN_STATUS 45 | EFIAPI 46 | CfgLibConstructor( 47 | VOID 48 | ) 49 | { 50 | return RETURN_SUCCESS; 51 | } 52 | 53 | RETURN_STATUS 54 | EFIAPI 55 | CfgLibDestructor( 56 | VOID 57 | ) 58 | { 59 | return RETURN_SUCCESS; 60 | } 61 | -------------------------------------------------------------------------------- /ControlFlowPkg/Library/CfgStubLib/WinNTServiceLibMsvc.c: -------------------------------------------------------------------------------- 1 | /**@file 2 | 3 | Copyright (c) 2019, Intel Corporation. All rights reserved.
4 | This program and the accompanying materials 5 | are licensed and made available under the terms and conditions of the BSD License 6 | which accompanies this distribution. The full text of the license may be found at 7 | http://opensource.org/licenses/bsd-license.php 8 | 9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | 12 | **/ 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | EFI_WIN_NT_THUNK_PROTOCOL *gWinNt; 22 | 23 | EFI_GUID gEfiWinNtThunkProtocolGuid = EFI_WIN_NT_THUNK_PROTOCOL_GUID; 24 | 25 | VOID 26 | EFIAPI 27 | EnableReadOnlyProtection ( 28 | IN VOID *Buffer, 29 | IN UINTN Size 30 | ) 31 | { 32 | BOOL Result; 33 | DWORD OldProtect; 34 | if (gWinNt == NULL) { 35 | gBS->LocateProtocol (&gEfiWinNtThunkProtocolGuid, NULL, &gWinNt); 36 | } 37 | Result = gWinNt->VirtualProtect (Buffer, Size, PAGE_READONLY, &OldProtect); 38 | DEBUG ((DEBUG_INFO, "EnableReadOnlyProtection - %x\n", Result)); 39 | } 40 | 41 | VOID 42 | EFIAPI 43 | DisableReadOnlyProtection ( 44 | IN VOID *Buffer, 45 | IN UINTN Size 46 | ) 47 | { 48 | BOOL Result; 49 | DWORD OldProtect; 50 | if (gWinNt == NULL) { 51 | gBS->LocateProtocol (&gEfiWinNtThunkProtocolGuid, NULL, &gWinNt); 52 | } 53 | Result = gWinNt->VirtualProtect (Buffer, Size, PAGE_READWRITE, &OldProtect); 54 | DEBUG ((DEBUG_INFO, "DisableReadOnlyProtection - %x\n", Result)); 55 | } 56 | -------------------------------------------------------------------------------- /ControlFlowPkg/License.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012, Intel Corporation. All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions 5 | are met: 6 | 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above copyright 10 | notice, this list of conditions and the following disclaimer in 11 | the documentation and/or other materials provided with the 12 | distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 15 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 16 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 17 | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 18 | COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 19 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 20 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 24 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 | POSSIBILITY OF SUCH DAMAGE. 26 | -------------------------------------------------------------------------------- /ControlFlowPkg/Test/IndirectBranchTrackingTest/Ia32/EndBr.nasm: -------------------------------------------------------------------------------- 1 | ;------------------------------------------------------------------------------ ; 2 | ; Copyright (c) 2016, Intel Corporation. All rights reserved.
3 | ; This program and the accompanying materials 4 | ; are licensed and made available under the terms and conditions of the BSD License 5 | ; which accompanies this distribution. The full text of the license may be found at 6 | ; http://opensource.org/licenses/bsd-license.php. 7 | ; 8 | ; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 9 | ; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 10 | ; 11 | ;------------------------------------------------------------------------------- 12 | 13 | SECTION .text 14 | 15 | ASM_PFX(TargetFunc): 16 | DB 0xF3, 0x0F, 0x1E, 0xFB ; endbr32 17 | ret 18 | 19 | global ASM_PFX(EndBrTest) 20 | ASM_PFX(EndBrTest): 21 | mov eax, ASM_PFX(TargetFunc) 22 | add eax, 4 23 | call eax 24 | ret 25 | -------------------------------------------------------------------------------- /ControlFlowPkg/Test/IndirectBranchTrackingTest/IndirectBranchTrackingTest.c: -------------------------------------------------------------------------------- 1 | /** @file 2 | 3 | Copyright (c) 2016, Intel Corporation. All rights reserved.
4 | This program and the accompanying materials 5 | are licensed and made available under the terms and conditions of the BSD License 6 | which accompanies this distribution. The full text of the license may be found at 7 | http://opensource.org/licenses/bsd-license.php 8 | 9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | 12 | **/ 13 | 14 | #include 15 | 16 | #include 17 | #include 18 | #include 19 | 20 | UINTN 21 | EFIAPI 22 | EndBrTest ( 23 | VOID 24 | ); 25 | 26 | EFI_STATUS 27 | EFIAPI 28 | IndirectBranchTrackingTestInitialize( 29 | IN EFI_HANDLE ImageHandle, 30 | IN EFI_SYSTEM_TABLE *SystemTable 31 | ) 32 | { 33 | EndBrTest (); 34 | 35 | return EFI_SUCCESS; 36 | } 37 | -------------------------------------------------------------------------------- /ControlFlowPkg/Test/IndirectBranchTrackingTest/IndirectBranchTrackingTest.inf: -------------------------------------------------------------------------------- 1 | ## @file 2 | # 3 | # Copyright (c) 2016, Intel Corporation. All rights reserved.
4 | # This program and the accompanying materials are licensed and made available under 5 | # the terms and conditions of the BSD License that accompanies this distribution. 6 | # The full text of the license may be found at 7 | # http://opensource.org/licenses/bsd-license.php. 8 | # 9 | # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | # 12 | ## 13 | 14 | [Defines] 15 | INF_VERSION = 0x00010005 16 | BASE_NAME = IndirectBranchTrackingTest 17 | FILE_GUID = F1A30BDB-C3D1-4090-AA6B-5E5B085992BC 18 | MODULE_TYPE = UEFI_DRIVER 19 | VERSION_STRING = 1.0 20 | ENTRY_POINT = IndirectBranchTrackingTestInitialize 21 | 22 | [Sources] 23 | IndirectBranchTrackingTest.c 24 | 25 | [Sources.Ia32] 26 | Ia32/EndBr.nasm 27 | 28 | [Sources.X64] 29 | X64/EndBr.nasm 30 | 31 | [Packages] 32 | MdePkg/MdePkg.dec 33 | 34 | [LibraryClasses] 35 | UefiDriverEntryPoint 36 | 37 | [BuildOptions] 38 | -------------------------------------------------------------------------------- /ControlFlowPkg/Test/IndirectBranchTrackingTest/IndirectBranchTrackingTestSmm.c: -------------------------------------------------------------------------------- 1 | /** @file 2 | 3 | Copyright (c) 2016, Intel Corporation. All rights reserved.
4 | This program and the accompanying materials 5 | are licensed and made available under the terms and conditions of the BSD License 6 | which accompanies this distribution. The full text of the license may be found at 7 | http://opensource.org/licenses/bsd-license.php 8 | 9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | 12 | **/ 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | UINTN 20 | EFIAPI 21 | EndBrTest ( 22 | VOID 23 | ); 24 | 25 | EFI_STATUS 26 | EFIAPI 27 | SmmReadyToBootCallback ( 28 | IN CONST EFI_GUID *Protocol, 29 | IN VOID *Interface, 30 | IN EFI_HANDLE Handle 31 | ) 32 | { 33 | EndBrTest (); 34 | return EFI_SUCCESS; 35 | } 36 | 37 | EFI_STATUS 38 | EFIAPI 39 | IndirectBranchTrackingTestSmmInitialize( 40 | IN EFI_HANDLE ImageHandle, 41 | IN EFI_SYSTEM_TABLE *SystemTable 42 | ) 43 | { 44 | EFI_STATUS Status; 45 | VOID *SmmReadyToBootRegistration; 46 | 47 | Status = gSmst->SmmRegisterProtocolNotify ( 48 | &gEdkiiSmmReadyToBootProtocolGuid, 49 | SmmReadyToBootCallback, 50 | &SmmReadyToBootRegistration 51 | ); 52 | ASSERT_EFI_ERROR (Status); 53 | 54 | return EFI_SUCCESS; 55 | } 56 | -------------------------------------------------------------------------------- /ControlFlowPkg/Test/IndirectBranchTrackingTest/IndirectBranchTrackingTestSmm.inf: -------------------------------------------------------------------------------- 1 | ## @file 2 | # 3 | # Copyright (c) 2016, Intel Corporation. All rights reserved.
4 | # This program and the accompanying materials are licensed and made available under 5 | # the terms and conditions of the BSD License that accompanies this distribution. 6 | # The full text of the license may be found at 7 | # http://opensource.org/licenses/bsd-license.php. 8 | # 9 | # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | # 12 | ## 13 | 14 | [Defines] 15 | INF_VERSION = 0x00010005 16 | BASE_NAME = IndirectBranchTrackingTestSmm 17 | FILE_GUID = C819C245-C9B5-4CA8-9A93-7408335F58C9 18 | MODULE_TYPE = DXE_SMM_DRIVER 19 | VERSION_STRING = 1.0 20 | PI_SPECIFICATION_VERSION = 0x0001000A 21 | ENTRY_POINT = IndirectBranchTrackingTestSmmInitialize 22 | 23 | [Sources] 24 | IndirectBranchTrackingTestSmm.c 25 | 26 | [Sources.Ia32] 27 | Ia32/EndBr.nasm 28 | 29 | [Sources.X64] 30 | X64/EndBr.nasm 31 | 32 | [Packages] 33 | MdePkg/MdePkg.dec 34 | MdeModulePkg/MdeModulePkg.dec 35 | 36 | [LibraryClasses] 37 | UefiDriverEntryPoint 38 | BaseLib 39 | DebugLib 40 | SmmServicesTableLib 41 | 42 | [Protocols] 43 | gEdkiiSmmReadyToBootProtocolGuid 44 | 45 | [Depex] 46 | gEfiSmmCpuProtocolGuid 47 | -------------------------------------------------------------------------------- /ControlFlowPkg/Test/IndirectBranchTrackingTest/X64/EndBr.nasm: -------------------------------------------------------------------------------- 1 | ;------------------------------------------------------------------------------ ; 2 | ; Copyright (c) 2016, Intel Corporation. All rights reserved.
3 | ; This program and the accompanying materials 4 | ; are licensed and made available under the terms and conditions of the BSD License 5 | ; which accompanies this distribution. The full text of the license may be found at 6 | ; http://opensource.org/licenses/bsd-license.php. 7 | ; 8 | ; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 9 | ; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 10 | ; 11 | ;------------------------------------------------------------------------------- 12 | 13 | DEFAULT REL 14 | SECTION .text 15 | 16 | ASM_PFX(TargetFunc): 17 | DB 0xF3, 0x0F, 0x1E, 0xFA ; endbr64 18 | ret 19 | 20 | global ASM_PFX(EndBrTest) 21 | ASM_PFX(EndBrTest): 22 | mov rax, ASM_PFX(TargetFunc) 23 | add rax, 4 24 | call rax 25 | ret 26 | -------------------------------------------------------------------------------- /ControlFlowPkg/Test/ShadowStackTest/ShadowStackTest.c: -------------------------------------------------------------------------------- 1 | /** @file 2 | 3 | Copyright (c) 2016, Intel Corporation. All rights reserved.
4 | This program and the accompanying materials 5 | are licensed and made available under the terms and conditions of the BSD License 6 | which accompanies this distribution. The full text of the license may be found at 7 | http://opensource.org/licenses/bsd-license.php 8 | 9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | 12 | **/ 13 | 14 | #include 15 | 16 | #include 17 | #include 18 | #include 19 | 20 | VOID 21 | TestA ( 22 | IN CHAR16 *Test 23 | ) 24 | { 25 | CHAR16 Buffer[10]; 26 | 27 | StrCpyS (Buffer, 1000, Test); 28 | } 29 | 30 | EFI_STATUS 31 | EFIAPI 32 | ShadowStackTestInitialize ( 33 | IN EFI_HANDLE ImageHandle, 34 | IN EFI_SYSTEM_TABLE *SystemTable 35 | ) 36 | { 37 | TestA (L"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"); 38 | 39 | return EFI_SUCCESS; 40 | } -------------------------------------------------------------------------------- /ControlFlowPkg/Test/ShadowStackTest/ShadowStackTest.inf: -------------------------------------------------------------------------------- 1 | ## @file 2 | # 3 | # Copyright (c) 2016, Intel Corporation. All rights reserved.
4 | # This program and the accompanying materials are licensed and made available under 5 | # the terms and conditions of the BSD License that accompanies this distribution. 6 | # The full text of the license may be found at 7 | # http://opensource.org/licenses/bsd-license.php. 8 | # 9 | # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | # 12 | ## 13 | 14 | [Defines] 15 | INF_VERSION = 0x00010005 16 | BASE_NAME = ShadowStackTest 17 | FILE_GUID = C6E308DD-05B0-4E65-96DD-B7A82B4072D7 18 | MODULE_TYPE = UEFI_DRIVER 19 | VERSION_STRING = 1.0 20 | ENTRY_POINT = ShadowStackTestInitialize 21 | 22 | [Sources] 23 | ShadowStackTest.c 24 | 25 | [Packages] 26 | MdePkg/MdePkg.dec 27 | 28 | [LibraryClasses] 29 | UefiDriverEntryPoint 30 | 31 | [BuildOptions] 32 | -------------------------------------------------------------------------------- /ControlFlowPkg/Test/ShadowStackTest/ShadowStackTestSmm.c: -------------------------------------------------------------------------------- 1 | /** @file 2 | 3 | Copyright (c) 2016, Intel Corporation. All rights reserved.
4 | This program and the accompanying materials 5 | are licensed and made available under the terms and conditions of the BSD License 6 | which accompanies this distribution. The full text of the license may be found at 7 | http://opensource.org/licenses/bsd-license.php 8 | 9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | 12 | **/ 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | VOID 20 | TestA ( 21 | IN CHAR16 *Test 22 | ) 23 | { 24 | CHAR16 Buffer[10]; 25 | 26 | StrCpyS (Buffer, 1000, Test); 27 | } 28 | 29 | EFI_STATUS 30 | EFIAPI 31 | SmmReadyToBootCallback ( 32 | IN CONST EFI_GUID *Protocol, 33 | IN VOID *Interface, 34 | IN EFI_HANDLE Handle 35 | ) 36 | { 37 | TestA (L"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"); 38 | 39 | return EFI_SUCCESS; 40 | } 41 | 42 | EFI_STATUS 43 | EFIAPI 44 | ShadowStackTestSmmInitialize( 45 | IN EFI_HANDLE ImageHandle, 46 | IN EFI_SYSTEM_TABLE *SystemTable 47 | ) 48 | { 49 | EFI_STATUS Status; 50 | VOID *SmmReadyToBootRegistration; 51 | 52 | Status = gSmst->SmmRegisterProtocolNotify ( 53 | &gEdkiiSmmReadyToBootProtocolGuid, 54 | SmmReadyToBootCallback, 55 | &SmmReadyToBootRegistration 56 | ); 57 | ASSERT_EFI_ERROR (Status); 58 | 59 | return EFI_SUCCESS; 60 | } 61 | -------------------------------------------------------------------------------- /ControlFlowPkg/Test/ShadowStackTest/ShadowStackTestSmm.inf: -------------------------------------------------------------------------------- 1 | ## @file 2 | # 3 | # Copyright (c) 2016, Intel Corporation. All rights reserved.
4 | # This program and the accompanying materials are licensed and made available under 5 | # the terms and conditions of the BSD License that accompanies this distribution. 6 | # The full text of the license may be found at 7 | # http://opensource.org/licenses/bsd-license.php. 8 | # 9 | # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | # 12 | ## 13 | 14 | [Defines] 15 | INF_VERSION = 0x00010005 16 | BASE_NAME = ShadowStackTestSmm 17 | FILE_GUID = 197AA1A6-C7E7-4E9A-A5A3-73BCA81DC926 18 | MODULE_TYPE = DXE_SMM_DRIVER 19 | VERSION_STRING = 1.0 20 | PI_SPECIFICATION_VERSION = 0x0001000A 21 | ENTRY_POINT = ShadowStackTestSmmInitialize 22 | 23 | [Sources] 24 | ShadowStackTestSmm.c 25 | 26 | [Packages] 27 | MdePkg/MdePkg.dec 28 | MdeModulePkg/MdeModulePkg.dec 29 | 30 | [LibraryClasses] 31 | UefiDriverEntryPoint 32 | BaseLib 33 | DebugLib 34 | SmmServicesTableLib 35 | 36 | [Protocols] 37 | gEdkiiSmmReadyToBootProtocolGuid 38 | 39 | [Depex] 40 | gEfiSmmCpuProtocolGuid 41 | -------------------------------------------------------------------------------- /CppPkg/Library/UefiCppEntryPoint/CppCrt.inf: -------------------------------------------------------------------------------- 1 | ## @file 2 | # Module entry point library for UEFI Application. 3 | # 4 | # Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.
5 | # 6 | # This program and the accompanying materials 7 | # are licensed and made available under the terms and conditions of the BSD License 8 | # which accompanies this distribution. The full text of the license may be found at 9 | # http://opensource.org/licenses/bsd-license.php. 10 | # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 12 | # 13 | # 14 | ## 15 | 16 | [Defines] 17 | INF_VERSION = 0x00010005 18 | BASE_NAME = UefiCppCrt 19 | FILE_GUID = E2D32F74-37AE-4C86-B3D8-643781DEF31D 20 | MODULE_TYPE = UEFI_APPLICATION 21 | VERSION_STRING = 1.0 22 | LIBRARY_CLASS = NULL 23 | CONSTRUCTOR = EfiCRTInit 24 | DESTRUCTOR = EfiCRTDeinit 25 | 26 | # 27 | # VALID_ARCHITECTURES = IA32 X64 IPF EBC 28 | # 29 | 30 | [Sources] 31 | new_delete.cpp 32 | crt.c | MSFT 33 | ctors.cpp | GCC 34 | crtbegin.cpp | GCC 35 | crtend.cpp | GCC 36 | 37 | [Packages] 38 | MdePkg/MdePkg.dec 39 | 40 | [LibraryClasses] 41 | UefiBootServicesTableLib 42 | DebugLib 43 | MemoryAllocationLib 44 | 45 | [Protocols] 46 | gEfiLoadedImageProtocolGuid 47 | 48 | [BuildOptions] 49 | # warning C4804: '/' : unsafe use of type 'bool' in operation 50 | # warning C4164: '_ReturnAddress' : intrinsic function not declared 51 | MSFT:*_*_*_CC_FLAGS = /wd4804 /wd4164 /Od /GL- 52 | # -Wno-invalid-offsetof -fno-rtti : only for CPP 53 | GCC:*_*_*_CC_FLAGS = -Wno-invalid-offsetof -fno-rtti -fno-exceptions 54 | -------------------------------------------------------------------------------- /CppPkg/Library/UefiCppEntryPoint/Scripts/gcc-ld-script: -------------------------------------------------------------------------------- 1 | /* OUTPUT_FORMAT(efi-bsdrv-x86_64) */ 2 | SECTIONS 3 | { 4 | /* . = 0 + SIZEOF_HEADERS; */ 5 | /* 6 | * NOTE: using ". = SIZEOF_HEADERS" can make p_align be 0x1000. sh_align is always 4. 7 | * But we can not use this way, because EflConvert will convert ELF to PE image later, 8 | * which converts ELF section instead of ELF segment. 9 | * 10 | * PE section alignment can be 0x20 by default. 11 | * If .text is start from 0x1000, then PE section alignment is 0x1000. 12 | */ 13 | . = 0x280; 14 | .text ALIGN(0x1000) : 15 | { 16 | *(.text .stub .text.* .gnu.linkonce.t.*) 17 | . = ALIGN(0x20); 18 | } =0x90909090 19 | .data ALIGN(0x1000) : 20 | { 21 | *( 22 | .rodata .rodata.* .gnu.linkonce.r.* 23 | .data .data.* .gnu.linkonce.d.* 24 | .bss .bss.* 25 | *COM* 26 | ) 27 | /* Add crt dection to support C++ */ 28 | KEEP (*crtbegin.obj(.ctors)) 29 | KEEP (*(EXCLUDE_FILE (*crtend.obj) .ctors)) 30 | KEEP (*(SORT(.ctors.*))) 31 | KEEP (*(.ctors)) 32 | . = ALIGN(0x20); 33 | } 34 | .eh_frame ALIGN(0x1000) : 35 | { 36 | KEEP (*(.eh_frame)) 37 | } 38 | .got ALIGN(0x1000) : 39 | { 40 | *(.got .got.*) 41 | . = ALIGN(0x20); 42 | } 43 | .rela ALIGN(0x1000) : 44 | { 45 | *(.rela .rela.*) 46 | } 47 | } 48 | 49 | -------------------------------------------------------------------------------- /CppPkg/Library/UefiCppEntryPoint/crtbegin.cpp: -------------------------------------------------------------------------------- 1 | /** @file 2 | Entry point library instance to a UEFI application. 3 | 4 | Copyright (c) 2015, Intel Corporation. All rights reserved.
5 | This program and the accompanying materials 6 | are licensed and made available under the terms and conditions of the BSD License 7 | which accompanies this distribution. The full text of the license may be found at 8 | http://opensource.org/licenses/bsd-license.php. 9 | 10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 12 | 13 | **/ 14 | 15 | #ifdef __cplusplus 16 | extern "C" { 17 | #endif 18 | 19 | #include 20 | 21 | typedef void (__attribute__((cdecl)) *INIT_FUNC) (void); 22 | 23 | INIT_FUNC crtbegin[1] __attribute__ ((section(".ctors"))) = {(INIT_FUNC)(UINTN)-1}; 24 | 25 | #ifdef __cplusplus 26 | } 27 | #endif 28 | -------------------------------------------------------------------------------- /CppPkg/Library/UefiCppEntryPoint/crtend.cpp: -------------------------------------------------------------------------------- 1 | /** @file 2 | Entry point library instance to a UEFI application. 3 | 4 | Copyright (c) 2015, Intel Corporation. All rights reserved.
5 | This program and the accompanying materials 6 | are licensed and made available under the terms and conditions of the BSD License 7 | which accompanies this distribution. The full text of the license may be found at 8 | http://opensource.org/licenses/bsd-license.php. 9 | 10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 12 | 13 | **/ 14 | 15 | #ifdef __cplusplus 16 | extern "C" { 17 | #endif 18 | 19 | #include 20 | 21 | typedef void (__attribute__((cdecl)) *INIT_FUNC) (void); 22 | 23 | INIT_FUNC crtend[1] __attribute__ ((section(".ctors"))) = {(INIT_FUNC)(UINTN)-1}; 24 | 25 | #ifdef __cplusplus 26 | } 27 | #endif 28 | -------------------------------------------------------------------------------- /CppPkg/Library/UefiCppEntryPoint/new_delete.cpp: -------------------------------------------------------------------------------- 1 | /** @file 2 | Entry point library instance to a UEFI application. 3 | 4 | Copyright (c) 2015, Intel Corporation. All rights reserved.
5 | This program and the accompanying materials 6 | are licensed and made available under the terms and conditions of the BSD License 7 | which accompanies this distribution. The full text of the license may be found at 8 | http://opensource.org/licenses/bsd-license.php. 9 | 10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 12 | 13 | **/ 14 | 15 | #ifdef __cplusplus 16 | extern "C" { 17 | #endif 18 | 19 | #include 20 | #include 21 | 22 | #ifdef __cplusplus 23 | } 24 | #endif 25 | 26 | void operator delete(void *Ptr) 27 | { 28 | return FreePool (Ptr); 29 | } 30 | 31 | void operator delete[](void *Ptr) 32 | { 33 | return FreePool (Ptr); 34 | } 35 | 36 | void operator delete(void *Ptr, size_t Size) 37 | { 38 | return FreePool (Ptr); 39 | } 40 | 41 | void * operator new(size_t Size) 42 | { 43 | return AllocatePool (Size); 44 | } 45 | 46 | void * operator new[](size_t Size) 47 | { 48 | return AllocatePool (Size); 49 | } -------------------------------------------------------------------------------- /CppPkg/License.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012, Intel Corporation. All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions 5 | are met: 6 | 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above copyright 10 | notice, this list of conditions and the following disclaimer in 11 | the documentation and/or other materials provided with the 12 | distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 15 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 16 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 17 | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 18 | COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 19 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 20 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 24 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 | POSSIBILITY OF SUCH DAMAGE. 26 | -------------------------------------------------------------------------------- /CppPkg/TestCpp/TestCpp.cpp: -------------------------------------------------------------------------------- 1 | /** @file 2 | 3 | Copyright (c) 2014, Intel Corporation. All rights reserved.
4 | This software and associated documentation (if any) is furnished 5 | under a license and may only be used or copied in accordance 6 | with the terms of the license. Except as permitted by such 7 | license, no part of this software or documentation may be 8 | reproduced, stored in a retrieval system, or transmitted in any 9 | form or by any means without the express written consent of 10 | Intel Corporation. 11 | 12 | **/ 13 | 14 | 15 | #ifdef __cplusplus 16 | extern "C" { 17 | #endif 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | #ifdef __cplusplus 24 | } 25 | #endif 26 | 27 | class TestClass { 28 | private: 29 | UINTN Member1; 30 | UINTN *Addr; 31 | public: 32 | TestClass() 33 | { 34 | DEBUG ((EFI_D_INFO, "TestClass - 0x%x\n", Member1)); 35 | Member1 = 1; 36 | Addr = new UINTN; 37 | } 38 | ~TestClass() 39 | { 40 | Member1 = 0; 41 | delete Addr; 42 | DEBUG ((EFI_D_INFO, "TestClass(D) - 0x%x\n", Member1)); 43 | } 44 | VOID 45 | SetNumber ( 46 | IN UINTN Number 47 | ) 48 | { 49 | DEBUG ((EFI_D_INFO, "SetNumber - 0x%x\n", Number)); 50 | Member1 = Number; 51 | } 52 | UINTN 53 | GetNumber ( 54 | VOID 55 | ) 56 | { 57 | DEBUG ((EFI_D_INFO, "GetNumber - 0x%x\n", Member1)); 58 | return Member1; 59 | } 60 | }; 61 | 62 | typedef class TestClass TestClass; 63 | 64 | TestClass testClass; 65 | TestClass testClass2; 66 | 67 | UINTN DummySymbol; 68 | 69 | EFI_STATUS 70 | EFIAPI 71 | MainEntryPoint ( 72 | IN EFI_HANDLE ImageHandle, 73 | IN EFI_SYSTEM_TABLE *SystemTable 74 | ) 75 | { 76 | #if 1 77 | UINTN *Ptr; 78 | UINTN *Array; 79 | 80 | Ptr = new UINTN; 81 | Array = new UINTN[100]; 82 | 83 | *Ptr = 5; 84 | 85 | delete Ptr; 86 | delete[] Array; 87 | 88 | Print ((CHAR16 *)L"Number - 0x%x\n", testClass.GetNumber ()); 89 | testClass.SetNumber (2); 90 | Print ((CHAR16 *)L"Number - 0x%x\n", testClass.GetNumber ()); 91 | 92 | Print ((CHAR16 *)L"Number - 0x%x\n", testClass2.GetNumber ()); 93 | testClass2.SetNumber (3); 94 | Print ((CHAR16 *)L"Number - 0x%x\n", testClass2.GetNumber ()); 95 | #endif 96 | return EFI_SUCCESS; 97 | } 98 | -------------------------------------------------------------------------------- /CppPkg/TestCpp/TestCpp.inf: -------------------------------------------------------------------------------- 1 | ## @file 2 | # 3 | # Copyright (c) 2013, Intel Corporation. All rights reserved.
4 | # This software and associated documentation (if any) is furnished 5 | # under a license and may only be used or copied in accordance 6 | # with the terms of the license. Except as permitted by such 7 | # license, no part of this software or documentation may be 8 | # reproduced, stored in a retrieval system, or transmitted in any 9 | # form or by any means without the express written consent of 10 | # Intel Corporation. 11 | # 12 | ## 13 | 14 | [Defines] 15 | INF_VERSION = 0x00010005 16 | BASE_NAME = TestCpp 17 | FILE_GUID = D27D8778-A0F2-42a6-AD32-E28341D8A2F6 18 | MODULE_TYPE = UEFI_APPLICATION 19 | VERSION_STRING = 1.0 20 | ENTRY_POINT = MainEntryPoint 21 | 22 | # 23 | # The following information is for reference only and not required by the build tools. 24 | # 25 | # VALID_ARCHITECTURES = IA32 X64 IPF EBC 26 | # 27 | 28 | [Sources] 29 | TestCpp.cpp 30 | 31 | [Packages] 32 | MdePkg/MdePkg.dec 33 | 34 | [LibraryClasses] 35 | UefiApplicationEntryPoint 36 | MemoryAllocationLib 37 | UefiBootServicesTableLib 38 | UefiLib 39 | DebugLib 40 | 41 | [BuildOptions] 42 | # warning C4804: '/' : unsafe use of type 'bool' in operation 43 | # warning C4164: '_ReturnAddress' : intrinsic function not declared 44 | MSFT:*_*_*_CC_FLAGS = /wd4804 /wd4164 45 | -------------------------------------------------------------------------------- /OverflowDetectionPkg/Library/PageTableLibNull/PageTableLibNull.inf: -------------------------------------------------------------------------------- 1 | ## @file 2 | # 3 | # Copyright (c) 2012 Intel Corporation. All rights reserved.
4 | # This program and the accompanying materials are 5 | # licensed and made available under the terms and conditions of the BSD License 6 | # which accompanies this distribution. The full text of the license may be found at 7 | # http://opensource.org/licenses/bsd-license.php 8 | # 9 | # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | # 12 | ## 13 | 14 | [Defines] 15 | INF_VERSION = 0x00010005 16 | BASE_NAME = PageTableLibNull 17 | FILE_GUID = 0AD7C33E-5195-4808-A5A1-FD3D3F5933E6 18 | MODULE_TYPE = BASE 19 | VERSION_STRING = 1.0 20 | LIBRARY_CLASS = PageTableLib 21 | 22 | # 23 | # The following information is for reference only and not required by the build tools. 24 | # 25 | # VALID_ARCHITECTURES = IA32 X64 IPF EBC 26 | # 27 | 28 | [Sources] 29 | PageTableLibNull.c 30 | 31 | [Packages] 32 | MdePkg/MdePkg.dec 33 | OverflowDetectionPkg/OverflowDetectionPkg.dec 34 | 35 | [LibraryClasses] 36 | BaseLib 37 | DebugLib 38 | 39 | -------------------------------------------------------------------------------- /OverflowDetectionPkg/Library/PageTableLibX86Pae/PageTableLibX86Pae.inf: -------------------------------------------------------------------------------- 1 | ## @file 2 | # 3 | # Copyright (c) 2012 Intel Corporation. All rights reserved.
4 | # This program and the accompanying materials are 5 | # licensed and made available under the terms and conditions of the BSD License 6 | # which accompanies this distribution. The full text of the license may be found at 7 | # http://opensource.org/licenses/bsd-license.php 8 | # 9 | # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | # 12 | ## 13 | 14 | [Defines] 15 | INF_VERSION = 0x00010005 16 | BASE_NAME = PageTableLibX86Pae 17 | FILE_GUID = EB951700-C78D-4724-8141-646085A6C363 18 | MODULE_TYPE = BASE 19 | VERSION_STRING = 1.0 20 | LIBRARY_CLASS = PageTableLib 21 | 22 | # 23 | # The following information is for reference only and not required by the build tools. 24 | # 25 | # VALID_ARCHITECTURES = IA32 X64 26 | # 27 | 28 | [Sources] 29 | PageTableLibX86Pae.c 30 | 31 | [Packages] 32 | MdePkg/MdePkg.dec 33 | OverflowDetectionPkg/OverflowDetectionPkg.dec 34 | 35 | [LibraryClasses] 36 | BaseLib 37 | BaseMemoryLib 38 | DebugLib 39 | CpuLib 40 | -------------------------------------------------------------------------------- /OverflowDetectionPkg/License.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012, Intel Corporation. All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions 5 | are met: 6 | 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above copyright 10 | notice, this list of conditions and the following disclaimer in 11 | the documentation and/or other materials provided with the 12 | distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 15 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 16 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 17 | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 18 | COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 19 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 20 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 24 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 | POSSIBILITY OF SUCH DAMAGE. 26 | -------------------------------------------------------------------------------- /OverflowDetectionPkg/Test/DoubleFree/DoubleFreePage.c: -------------------------------------------------------------------------------- 1 | /** @file 2 | 3 | Copyright (c) 2016, Intel Corporation. All rights reserved.
4 | This program and the accompanying materials 5 | are licensed and made available under the terms and conditions of the BSD License 6 | which accompanies this distribution. The full text of the license may be found at 7 | http://opensource.org/licenses/bsd-license.php 8 | 9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | 12 | **/ 13 | 14 | #include 15 | #include 16 | 17 | EFI_STATUS 18 | EFIAPI 19 | DoubleFreePageEntrypoint( 20 | IN EFI_HANDLE ImageHandle, 21 | IN EFI_SYSTEM_TABLE *SystemTable 22 | ) 23 | { 24 | VOID *Buffer; 25 | 26 | Buffer = AllocatePages(0x2); 27 | 28 | FreePages (Buffer, 2); 29 | FreePages (Buffer, 2); 30 | return EFI_SUCCESS; 31 | } 32 | -------------------------------------------------------------------------------- /OverflowDetectionPkg/Test/DoubleFree/DoubleFreePage.inf: -------------------------------------------------------------------------------- 1 | ## @file 2 | # 3 | # Copyright (c) 2016, Intel Corporation. All rights reserved.
4 | # This program and the accompanying materials are licensed and made available under 5 | # the terms and conditions of the BSD License that accompanies this distribution. 6 | # The full text of the license may be found at 7 | # http://opensource.org/licenses/bsd-license.php. 8 | # 9 | # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | # 12 | ## 13 | 14 | [Defines] 15 | INF_VERSION = 0x00010005 16 | BASE_NAME = DoubleFreePage 17 | FILE_GUID = C472FF92-743F-41B6-96BB-951ACF1CBA9F 18 | MODULE_TYPE = UEFI_APPLICATION 19 | VERSION_STRING = 1.0 20 | ENTRY_POINT = DoubleFreePageEntrypoint 21 | 22 | [Sources] 23 | DoubleFreePage.c 24 | 25 | [Packages] 26 | MdePkg/MdePkg.dec 27 | 28 | [LibraryClasses] 29 | UefiApplicationEntryPoint 30 | BaseLib 31 | DebugLib 32 | MemoryAllocationLib 33 | -------------------------------------------------------------------------------- /OverflowDetectionPkg/Test/DoubleFree/DoubleFreePageSmm.inf: -------------------------------------------------------------------------------- 1 | ## @file 2 | # 3 | # Copyright (c) 2016, Intel Corporation. All rights reserved.
4 | # This program and the accompanying materials are licensed and made available under 5 | # the terms and conditions of the BSD License that accompanies this distribution. 6 | # The full text of the license may be found at 7 | # http://opensource.org/licenses/bsd-license.php. 8 | # 9 | # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | # 12 | ## 13 | 14 | [Defines] 15 | INF_VERSION = 0x00010005 16 | BASE_NAME = DoubleFreePageSmm 17 | FILE_GUID = E016781B-D220-440D-8B66-A5888DFB1D9B 18 | MODULE_TYPE = DXE_SMM_DRIVER 19 | VERSION_STRING = 1.0 20 | PI_SPECIFICATION_VERSION = 0x0001000A 21 | ENTRY_POINT = DoubleFreePageEntrypoint 22 | 23 | [Sources] 24 | DoubleFreePage.c 25 | 26 | [Packages] 27 | MdePkg/MdePkg.dec 28 | 29 | [LibraryClasses] 30 | UefiDriverEntryPoint 31 | BaseLib 32 | DebugLib 33 | MemoryAllocationLib 34 | 35 | [Depex] 36 | gEfiSmmCpuProtocolGuid 37 | -------------------------------------------------------------------------------- /OverflowDetectionPkg/Test/DoubleFree/DoubleFreePool.c: -------------------------------------------------------------------------------- 1 | /** @file 2 | 3 | Copyright (c) 2016, Intel Corporation. All rights reserved.
4 | This program and the accompanying materials 5 | are licensed and made available under the terms and conditions of the BSD License 6 | which accompanies this distribution. The full text of the license may be found at 7 | http://opensource.org/licenses/bsd-license.php 8 | 9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | 12 | **/ 13 | 14 | #include 15 | #include 16 | 17 | EFI_STATUS 18 | EFIAPI 19 | DoubleFreePoolEntrypoint( 20 | IN EFI_HANDLE ImageHandle, 21 | IN EFI_SYSTEM_TABLE *SystemTable 22 | ) 23 | { 24 | VOID *Buffer; 25 | 26 | Buffer = AllocatePool(0x800); 27 | 28 | FreePool (Buffer); 29 | FreePool (Buffer); 30 | return EFI_SUCCESS; 31 | } 32 | -------------------------------------------------------------------------------- /OverflowDetectionPkg/Test/DoubleFree/DoubleFreePool.inf: -------------------------------------------------------------------------------- 1 | ## @file 2 | # 3 | # Copyright (c) 2016, Intel Corporation. All rights reserved.
4 | # This program and the accompanying materials are licensed and made available under 5 | # the terms and conditions of the BSD License that accompanies this distribution. 6 | # The full text of the license may be found at 7 | # http://opensource.org/licenses/bsd-license.php. 8 | # 9 | # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | # 12 | ## 13 | 14 | [Defines] 15 | INF_VERSION = 0x00010005 16 | BASE_NAME = DoubleFreePool 17 | FILE_GUID = C472FF92-743F-41B6-96BB-951ACF1CBA9F 18 | MODULE_TYPE = UEFI_APPLICATION 19 | VERSION_STRING = 1.0 20 | ENTRY_POINT = DoubleFreePoolEntrypoint 21 | 22 | [Sources] 23 | DoubleFreePool.c 24 | 25 | [Packages] 26 | MdePkg/MdePkg.dec 27 | 28 | [LibraryClasses] 29 | UefiApplicationEntryPoint 30 | BaseLib 31 | DebugLib 32 | MemoryAllocationLib 33 | -------------------------------------------------------------------------------- /OverflowDetectionPkg/Test/DoubleFree/DoubleFreePoolSmm.inf: -------------------------------------------------------------------------------- 1 | ## @file 2 | # 3 | # Copyright (c) 2016, Intel Corporation. All rights reserved.
4 | # This program and the accompanying materials are licensed and made available under 5 | # the terms and conditions of the BSD License that accompanies this distribution. 6 | # The full text of the license may be found at 7 | # http://opensource.org/licenses/bsd-license.php. 8 | # 9 | # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | # 12 | ## 13 | 14 | [Defines] 15 | INF_VERSION = 0x00010005 16 | BASE_NAME = DoubleFreePoolSmm 17 | FILE_GUID = E016781B-D220-440D-8B66-A5888DFB1D9B 18 | MODULE_TYPE = DXE_SMM_DRIVER 19 | VERSION_STRING = 1.0 20 | PI_SPECIFICATION_VERSION = 0x0001000A 21 | ENTRY_POINT = DoubleFreePoolEntrypoint 22 | 23 | [Sources] 24 | DoubleFreePool.c 25 | 26 | [Packages] 27 | MdePkg/MdePkg.dec 28 | 29 | [LibraryClasses] 30 | UefiDriverEntryPoint 31 | BaseLib 32 | DebugLib 33 | MemoryAllocationLib 34 | 35 | [Depex] 36 | gEfiSmmCpuProtocolGuid 37 | -------------------------------------------------------------------------------- /OverflowDetectionPkg/Test/ExecDataSection/ExecDataSection.c: -------------------------------------------------------------------------------- 1 | /** @file 2 | 3 | Copyright (c) 2016, Intel Corporation. All rights reserved.
4 | This program and the accompanying materials 5 | are licensed and made available under the terms and conditions of the BSD License 6 | which accompanies this distribution. The full text of the license may be found at 7 | http://opensource.org/licenses/bsd-license.php 8 | 9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | 12 | **/ 13 | 14 | #include 15 | #include 16 | 17 | typedef 18 | VOID 19 | (*TEST_FUNC) ( 20 | VOID 21 | ); 22 | 23 | UINT8 mTestCode[] = { 24 | 0xEB, 0xFE, 25 | }; 26 | 27 | EFI_STATUS 28 | EFIAPI 29 | ExecDataSectionEntrypoint( 30 | IN EFI_HANDLE ImageHandle, 31 | IN EFI_SYSTEM_TABLE *SystemTable 32 | ) 33 | { 34 | TEST_FUNC TestFunc; 35 | 36 | TestFunc = (TEST_FUNC)(UINTN)mTestCode; 37 | TestFunc(); 38 | return EFI_SUCCESS; 39 | } 40 | -------------------------------------------------------------------------------- /OverflowDetectionPkg/Test/ExecDataSection/ExecDataSection.inf: -------------------------------------------------------------------------------- 1 | ## @file 2 | # 3 | # Copyright (c) 2016, Intel Corporation. All rights reserved.
4 | # This program and the accompanying materials are licensed and made available under 5 | # the terms and conditions of the BSD License that accompanies this distribution. 6 | # The full text of the license may be found at 7 | # http://opensource.org/licenses/bsd-license.php. 8 | # 9 | # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | # 12 | ## 13 | 14 | [Defines] 15 | INF_VERSION = 0x00010005 16 | BASE_NAME = ExecDataSection 17 | FILE_GUID = B6EA7888-7EE3-4724-8480-0CBE0B8D8C0E 18 | MODULE_TYPE = UEFI_APPLICATION 19 | VERSION_STRING = 1.0 20 | PI_SPECIFICATION_VERSION = 0x0001000A 21 | ENTRY_POINT = ExecDataSectionEntrypoint 22 | 23 | [Sources] 24 | ExecDataSection.c 25 | 26 | [Packages] 27 | MdePkg/MdePkg.dec 28 | 29 | [LibraryClasses] 30 | UefiApplicationEntryPoint 31 | BaseLib 32 | DebugLib 33 | -------------------------------------------------------------------------------- /OverflowDetectionPkg/Test/ExecDataSection/ExecDataSectionSmm.c: -------------------------------------------------------------------------------- 1 | /** @file 2 | 3 | Copyright (c) 2016, Intel Corporation. All rights reserved.
4 | This program and the accompanying materials 5 | are licensed and made available under the terms and conditions of the BSD License 6 | which accompanies this distribution. The full text of the license may be found at 7 | http://opensource.org/licenses/bsd-license.php 8 | 9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | 12 | **/ 13 | 14 | #include 15 | #include 16 | #include 17 | 18 | typedef 19 | VOID 20 | (*TEST_FUNC) ( 21 | VOID 22 | ); 23 | 24 | UINT8 mTestCode[] = { 25 | 0xEB, 0xFE, 26 | }; 27 | 28 | EFI_STATUS 29 | EFIAPI 30 | SmmReadyToBootCallback ( 31 | IN CONST EFI_GUID *Protocol, 32 | IN VOID *Interface, 33 | IN EFI_HANDLE Handle 34 | ) 35 | { 36 | TEST_FUNC TestFunc; 37 | 38 | TestFunc = (TEST_FUNC)(UINTN)mTestCode; 39 | TestFunc(); 40 | return EFI_SUCCESS; 41 | } 42 | 43 | EFI_STATUS 44 | EFIAPI 45 | ExecDataSectionEntrypoint( 46 | IN EFI_HANDLE ImageHandle, 47 | IN EFI_SYSTEM_TABLE *SystemTable 48 | ) 49 | { 50 | EFI_STATUS Status; 51 | VOID *SmmReadyToBootRegistration; 52 | 53 | Status = gSmst->SmmRegisterProtocolNotify ( 54 | &gEdkiiSmmReadyToBootProtocolGuid, 55 | SmmReadyToBootCallback, 56 | &SmmReadyToBootRegistration 57 | ); 58 | ASSERT_EFI_ERROR (Status); 59 | 60 | return EFI_SUCCESS; 61 | } 62 | -------------------------------------------------------------------------------- /OverflowDetectionPkg/Test/ExecDataSection/ExecDataSectionSmm.inf: -------------------------------------------------------------------------------- 1 | ## @file 2 | # 3 | # Copyright (c) 2016, Intel Corporation. All rights reserved.
4 | # This program and the accompanying materials are licensed and made available under 5 | # the terms and conditions of the BSD License that accompanies this distribution. 6 | # The full text of the license may be found at 7 | # http://opensource.org/licenses/bsd-license.php. 8 | # 9 | # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | # 12 | ## 13 | 14 | [Defines] 15 | INF_VERSION = 0x00010005 16 | BASE_NAME = ExecDataSectionSmm 17 | FILE_GUID = CFEC9A02-1074-4F89-AAEE-DE376E1F062A 18 | MODULE_TYPE = DXE_SMM_DRIVER 19 | VERSION_STRING = 1.0 20 | PI_SPECIFICATION_VERSION = 0x0001000A 21 | ENTRY_POINT = ExecDataSectionEntrypoint 22 | 23 | [Sources] 24 | ExecDataSectionSmm.c 25 | 26 | [Packages] 27 | MdePkg/MdePkg.dec 28 | MdeModulePkg/MdeModulePkg.dec 29 | 30 | [LibraryClasses] 31 | UefiDriverEntryPoint 32 | BaseLib 33 | DebugLib 34 | SmmServicesTableLib 35 | 36 | [Protocols] 37 | gEdkiiSmmReadyToBootProtocolGuid 38 | 39 | [Depex] 40 | gEfiSmmCpuProtocolGuid 41 | -------------------------------------------------------------------------------- /OverflowDetectionPkg/Test/HeapOverflow/HeapOverflowDownPage.c: -------------------------------------------------------------------------------- 1 | /** @file 2 | 3 | Copyright (c) 2016, Intel Corporation. All rights reserved.
4 | This program and the accompanying materials 5 | are licensed and made available under the terms and conditions of the BSD License 6 | which accompanies this distribution. The full text of the license may be found at 7 | http://opensource.org/licenses/bsd-license.php 8 | 9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | 12 | **/ 13 | 14 | #include 15 | #include 16 | #include 17 | 18 | EFI_STATUS 19 | EFIAPI 20 | HeapOverflowDownPageEntrypoint( 21 | IN EFI_HANDLE ImageHandle, 22 | IN EFI_SYSTEM_TABLE *SystemTable 23 | ) 24 | { 25 | VOID *Buffer; 26 | 27 | Buffer = AllocatePages(0x2); 28 | 29 | ZeroMem((VOID *)((UINTN)Buffer + EFI_PAGES_TO_SIZE(2)), EFI_PAGES_TO_SIZE(2)); 30 | 31 | FreePages (Buffer, 2); 32 | return EFI_SUCCESS; 33 | } 34 | -------------------------------------------------------------------------------- /OverflowDetectionPkg/Test/HeapOverflow/HeapOverflowDownPage.inf: -------------------------------------------------------------------------------- 1 | ## @file 2 | # 3 | # Copyright (c) 2016, Intel Corporation. All rights reserved.
4 | # This program and the accompanying materials are licensed and made available under 5 | # the terms and conditions of the BSD License that accompanies this distribution. 6 | # The full text of the license may be found at 7 | # http://opensource.org/licenses/bsd-license.php. 8 | # 9 | # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | # 12 | ## 13 | 14 | [Defines] 15 | INF_VERSION = 0x00010005 16 | BASE_NAME = HeapOverflowDownPage 17 | FILE_GUID = EFEF9248-914D-42AF-BD96-52EB6FC5C405 18 | MODULE_TYPE = UEFI_APPLICATION 19 | VERSION_STRING = 1.0 20 | ENTRY_POINT = HeapOverflowDownPageEntrypoint 21 | 22 | [Sources] 23 | HeapOverflowDownPage.c 24 | 25 | [Packages] 26 | MdePkg/MdePkg.dec 27 | 28 | [LibraryClasses] 29 | UefiApplicationEntryPoint 30 | BaseLib 31 | DebugLib 32 | MemoryAllocationLib 33 | BaseMemoryLib 34 | -------------------------------------------------------------------------------- /OverflowDetectionPkg/Test/HeapOverflow/HeapOverflowDownPageSmm.inf: -------------------------------------------------------------------------------- 1 | ## @file 2 | # 3 | # Copyright (c) 2016, Intel Corporation. All rights reserved.
4 | # This program and the accompanying materials are licensed and made available under 5 | # the terms and conditions of the BSD License that accompanies this distribution. 6 | # The full text of the license may be found at 7 | # http://opensource.org/licenses/bsd-license.php. 8 | # 9 | # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | # 12 | ## 13 | 14 | [Defines] 15 | INF_VERSION = 0x00010005 16 | BASE_NAME = HeapOverflowDownPageSmm 17 | FILE_GUID = BA57F63F-155F-4BEE-874E-D7AECDBCBE53 18 | MODULE_TYPE = DXE_SMM_DRIVER 19 | VERSION_STRING = 1.0 20 | PI_SPECIFICATION_VERSION = 0x0001000A 21 | ENTRY_POINT = HeapOverflowDownPageEntrypoint 22 | 23 | [Sources] 24 | HeapOverflowDownPage.c 25 | 26 | [Packages] 27 | MdePkg/MdePkg.dec 28 | 29 | [LibraryClasses] 30 | UefiDriverEntryPoint 31 | BaseLib 32 | DebugLib 33 | MemoryAllocationLib 34 | BaseMemoryLib 35 | 36 | [Depex] 37 | gEfiSmmCpuProtocolGuid 38 | -------------------------------------------------------------------------------- /OverflowDetectionPkg/Test/HeapOverflow/HeapOverflowDownPool.c: -------------------------------------------------------------------------------- 1 | /** @file 2 | 3 | Copyright (c) 2016, Intel Corporation. All rights reserved.
4 | This program and the accompanying materials 5 | are licensed and made available under the terms and conditions of the BSD License 6 | which accompanies this distribution. The full text of the license may be found at 7 | http://opensource.org/licenses/bsd-license.php 8 | 9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | 12 | **/ 13 | 14 | #include 15 | #include 16 | #include 17 | 18 | EFI_STATUS 19 | EFIAPI 20 | HeapOverflowDownPoolEntrypoint( 21 | IN EFI_HANDLE ImageHandle, 22 | IN EFI_SYSTEM_TABLE *SystemTable 23 | ) 24 | { 25 | VOID *Buffer; 26 | 27 | Buffer = AllocatePool(0x800); 28 | ZeroMem((VOID *)((UINTN)Buffer + 0x800), 0x20); 29 | 30 | FreePool (Buffer); 31 | return EFI_SUCCESS; 32 | } 33 | -------------------------------------------------------------------------------- /OverflowDetectionPkg/Test/HeapOverflow/HeapOverflowDownPool.inf: -------------------------------------------------------------------------------- 1 | ## @file 2 | # 3 | # Copyright (c) 2016, Intel Corporation. All rights reserved.
4 | # This program and the accompanying materials are licensed and made available under 5 | # the terms and conditions of the BSD License that accompanies this distribution. 6 | # The full text of the license may be found at 7 | # http://opensource.org/licenses/bsd-license.php. 8 | # 9 | # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | # 12 | ## 13 | 14 | [Defines] 15 | INF_VERSION = 0x00010005 16 | BASE_NAME = HeapOverflowDownPool 17 | FILE_GUID = 93DF78FC-68F4-41D7-AAF7-859D39F29D2F 18 | MODULE_TYPE = UEFI_APPLICATION 19 | VERSION_STRING = 1.0 20 | ENTRY_POINT = HeapOverflowDownPoolEntrypoint 21 | 22 | [Sources] 23 | HeapOverflowDownPool.c 24 | 25 | [Packages] 26 | MdePkg/MdePkg.dec 27 | 28 | [LibraryClasses] 29 | UefiApplicationEntryPoint 30 | BaseLib 31 | DebugLib 32 | MemoryAllocationLib 33 | BaseMemoryLib 34 | -------------------------------------------------------------------------------- /OverflowDetectionPkg/Test/HeapOverflow/HeapOverflowDownPoolSmm.inf: -------------------------------------------------------------------------------- 1 | ## @file 2 | # 3 | # Copyright (c) 2016, Intel Corporation. All rights reserved.
4 | # This program and the accompanying materials are licensed and made available under 5 | # the terms and conditions of the BSD License that accompanies this distribution. 6 | # The full text of the license may be found at 7 | # http://opensource.org/licenses/bsd-license.php. 8 | # 9 | # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | # 12 | ## 13 | 14 | [Defines] 15 | INF_VERSION = 0x00010005 16 | BASE_NAME = HeapOverflowDownPoolSmm 17 | FILE_GUID = 8C81BE89-0E3A-43E7-9407-6EB231FF8460 18 | MODULE_TYPE = DXE_SMM_DRIVER 19 | VERSION_STRING = 1.0 20 | PI_SPECIFICATION_VERSION = 0x0001000A 21 | ENTRY_POINT = HeapOverflowDownPoolEntrypoint 22 | 23 | [Sources] 24 | HeapOverflowDownPool.c 25 | 26 | [Packages] 27 | MdePkg/MdePkg.dec 28 | 29 | [LibraryClasses] 30 | UefiDriverEntryPoint 31 | BaseLib 32 | DebugLib 33 | MemoryAllocationLib 34 | BaseMemoryLib 35 | 36 | [Depex] 37 | gEfiSmmCpuProtocolGuid 38 | -------------------------------------------------------------------------------- /OverflowDetectionPkg/Test/HeapOverflow/HeapOverflowUpPage.c: -------------------------------------------------------------------------------- 1 | /** @file 2 | 3 | Copyright (c) 2016, Intel Corporation. All rights reserved.
4 | This program and the accompanying materials 5 | are licensed and made available under the terms and conditions of the BSD License 6 | which accompanies this distribution. The full text of the license may be found at 7 | http://opensource.org/licenses/bsd-license.php 8 | 9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | 12 | **/ 13 | 14 | #include 15 | #include 16 | #include 17 | 18 | EFI_STATUS 19 | EFIAPI 20 | HeapOverflowUpPageEntrypoint( 21 | IN EFI_HANDLE ImageHandle, 22 | IN EFI_SYSTEM_TABLE *SystemTable 23 | ) 24 | { 25 | VOID *Buffer; 26 | 27 | Buffer = AllocatePages(0x2); 28 | 29 | ZeroMem((VOID *)((UINTN)Buffer - EFI_PAGES_TO_SIZE(2)), EFI_PAGES_TO_SIZE(2)); 30 | 31 | FreePages (Buffer, 2); 32 | return EFI_SUCCESS; 33 | } 34 | -------------------------------------------------------------------------------- /OverflowDetectionPkg/Test/HeapOverflow/HeapOverflowUpPage.inf: -------------------------------------------------------------------------------- 1 | ## @file 2 | # 3 | # Copyright (c) 2016, Intel Corporation. All rights reserved.
4 | # This program and the accompanying materials are licensed and made available under 5 | # the terms and conditions of the BSD License that accompanies this distribution. 6 | # The full text of the license may be found at 7 | # http://opensource.org/licenses/bsd-license.php. 8 | # 9 | # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | # 12 | ## 13 | 14 | [Defines] 15 | INF_VERSION = 0x00010005 16 | BASE_NAME = HeapOverflowUpPage 17 | FILE_GUID = FD7C64E6-4D70-4FE9-9BB6-AF9E4F04D276 18 | MODULE_TYPE = UEFI_APPLICATION 19 | VERSION_STRING = 1.0 20 | ENTRY_POINT = HeapOverflowUpPageEntrypoint 21 | 22 | [Sources] 23 | HeapOverflowUpPage.c 24 | 25 | [Packages] 26 | MdePkg/MdePkg.dec 27 | 28 | [LibraryClasses] 29 | UefiApplicationEntryPoint 30 | BaseLib 31 | DebugLib 32 | MemoryAllocationLib 33 | BaseMemoryLib 34 | -------------------------------------------------------------------------------- /OverflowDetectionPkg/Test/HeapOverflow/HeapOverflowUpPageSmm.inf: -------------------------------------------------------------------------------- 1 | ## @file 2 | # 3 | # Copyright (c) 2016, Intel Corporation. All rights reserved.
4 | # This program and the accompanying materials are licensed and made available under 5 | # the terms and conditions of the BSD License that accompanies this distribution. 6 | # The full text of the license may be found at 7 | # http://opensource.org/licenses/bsd-license.php. 8 | # 9 | # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | # 12 | ## 13 | 14 | [Defines] 15 | INF_VERSION = 0x00010005 16 | BASE_NAME = HeapOverflowUpPageSmm 17 | FILE_GUID = BA97E152-C470-436B-8D01-C53F9D17B62C 18 | MODULE_TYPE = DXE_SMM_DRIVER 19 | VERSION_STRING = 1.0 20 | PI_SPECIFICATION_VERSION = 0x0001000A 21 | ENTRY_POINT = HeapOverflowUpPageEntrypoint 22 | 23 | [Sources] 24 | HeapOverflowUpPage.c 25 | 26 | [Packages] 27 | MdePkg/MdePkg.dec 28 | 29 | [LibraryClasses] 30 | UefiDriverEntryPoint 31 | BaseLib 32 | DebugLib 33 | MemoryAllocationLib 34 | BaseMemoryLib 35 | 36 | [Depex] 37 | gEfiSmmCpuProtocolGuid 38 | -------------------------------------------------------------------------------- /OverflowDetectionPkg/Test/HeapOverflow/HeapOverflowUpPool.c: -------------------------------------------------------------------------------- 1 | /** @file 2 | 3 | Copyright (c) 2016, Intel Corporation. All rights reserved.
4 | This program and the accompanying materials 5 | are licensed and made available under the terms and conditions of the BSD License 6 | which accompanies this distribution. The full text of the license may be found at 7 | http://opensource.org/licenses/bsd-license.php 8 | 9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | 12 | **/ 13 | 14 | #include 15 | #include 16 | #include 17 | 18 | EFI_STATUS 19 | EFIAPI 20 | HeapOverflowUpPoolEntrypoint( 21 | IN EFI_HANDLE ImageHandle, 22 | IN EFI_SYSTEM_TABLE *SystemTable 23 | ) 24 | { 25 | VOID *Buffer; 26 | 27 | Buffer = AllocatePool(0x800); 28 | ZeroMem((VOID *)((UINTN)Buffer - 0x20), 0x20); 29 | 30 | FreePool (Buffer); 31 | return EFI_SUCCESS; 32 | } 33 | -------------------------------------------------------------------------------- /OverflowDetectionPkg/Test/HeapOverflow/HeapOverflowUpPool.inf: -------------------------------------------------------------------------------- 1 | ## @file 2 | # 3 | # Copyright (c) 2016, Intel Corporation. All rights reserved.
4 | # This program and the accompanying materials are licensed and made available under 5 | # the terms and conditions of the BSD License that accompanies this distribution. 6 | # The full text of the license may be found at 7 | # http://opensource.org/licenses/bsd-license.php. 8 | # 9 | # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | # 12 | ## 13 | 14 | [Defines] 15 | INF_VERSION = 0x00010005 16 | BASE_NAME = HeapOverflowUpPool 17 | FILE_GUID = 0447144B-80C0-4A96-A74B-292E7C0032D0 18 | MODULE_TYPE = UEFI_APPLICATION 19 | VERSION_STRING = 1.0 20 | ENTRY_POINT = HeapOverflowUpPoolEntrypoint 21 | 22 | [Sources] 23 | HeapOverflowUpPool.c 24 | 25 | [Packages] 26 | MdePkg/MdePkg.dec 27 | 28 | [LibraryClasses] 29 | UefiApplicationEntryPoint 30 | BaseLib 31 | DebugLib 32 | MemoryAllocationLib 33 | BaseMemoryLib 34 | -------------------------------------------------------------------------------- /OverflowDetectionPkg/Test/HeapOverflow/HeapOverflowUpPoolSmm.inf: -------------------------------------------------------------------------------- 1 | ## @file 2 | # 3 | # Copyright (c) 2016, Intel Corporation. All rights reserved.
4 | # This program and the accompanying materials are licensed and made available under 5 | # the terms and conditions of the BSD License that accompanies this distribution. 6 | # The full text of the license may be found at 7 | # http://opensource.org/licenses/bsd-license.php. 8 | # 9 | # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | # 12 | ## 13 | 14 | [Defines] 15 | INF_VERSION = 0x00010005 16 | BASE_NAME = HeapOverflowUpPoolSmm 17 | FILE_GUID = 7B3BCD58-84DE-4241-9862-E6EF601C01BA 18 | MODULE_TYPE = DXE_SMM_DRIVER 19 | VERSION_STRING = 1.0 20 | PI_SPECIFICATION_VERSION = 0x0001000A 21 | ENTRY_POINT = HeapOverflowUpPoolEntrypoint 22 | 23 | [Sources] 24 | HeapOverflowUpPool.c 25 | 26 | [Packages] 27 | MdePkg/MdePkg.dec 28 | 29 | [LibraryClasses] 30 | UefiDriverEntryPoint 31 | BaseLib 32 | DebugLib 33 | MemoryAllocationLib 34 | BaseMemoryLib 35 | 36 | [Depex] 37 | gEfiSmmCpuProtocolGuid 38 | -------------------------------------------------------------------------------- /OverflowDetectionPkg/Test/PartialFree/PartialFreePage.c: -------------------------------------------------------------------------------- 1 | /** @file 2 | 3 | Copyright (c) 2016, Intel Corporation. All rights reserved.
4 | This program and the accompanying materials 5 | are licensed and made available under the terms and conditions of the BSD License 6 | which accompanies this distribution. The full text of the license may be found at 7 | http://opensource.org/licenses/bsd-license.php 8 | 9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | 12 | **/ 13 | 14 | #include 15 | #include 16 | 17 | EFI_STATUS 18 | EFIAPI 19 | PartialFreePageEntrypoint( 20 | IN EFI_HANDLE ImageHandle, 21 | IN EFI_SYSTEM_TABLE *SystemTable 22 | ) 23 | { 24 | VOID *Buffer; 25 | 26 | Buffer = AllocatePages(0x5); 27 | 28 | FreePages ((VOID *)((UINTN)Buffer+EFI_PAGES_TO_SIZE(1)), 1); 29 | FreePages ((VOID *)((UINTN)Buffer+EFI_PAGES_TO_SIZE(3)), 1); 30 | 31 | // 32 | FreePages ((VOID *)((UINTN)Buffer+EFI_PAGES_TO_SIZE(0)), 1); 33 | FreePages ((VOID *)((UINTN)Buffer+EFI_PAGES_TO_SIZE(2)), 1); 34 | FreePages ((VOID *)((UINTN)Buffer+EFI_PAGES_TO_SIZE(4)), 1); 35 | 36 | return EFI_SUCCESS; 37 | } 38 | -------------------------------------------------------------------------------- /OverflowDetectionPkg/Test/PartialFree/PartialFreePage.inf: -------------------------------------------------------------------------------- 1 | ## @file 2 | # 3 | # Copyright (c) 2016, Intel Corporation. All rights reserved.
4 | # This program and the accompanying materials are licensed and made available under 5 | # the terms and conditions of the BSD License that accompanies this distribution. 6 | # The full text of the license may be found at 7 | # http://opensource.org/licenses/bsd-license.php. 8 | # 9 | # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | # 12 | ## 13 | 14 | [Defines] 15 | INF_VERSION = 0x00010005 16 | BASE_NAME = PartialFreePage 17 | FILE_GUID = 87425E14-609B-497F-A9B6-764C5D151269 18 | MODULE_TYPE = UEFI_APPLICATION 19 | VERSION_STRING = 1.0 20 | ENTRY_POINT = PartialFreePageEntrypoint 21 | 22 | [Sources] 23 | PartialFreePage.c 24 | 25 | [Packages] 26 | MdePkg/MdePkg.dec 27 | 28 | [LibraryClasses] 29 | UefiApplicationEntryPoint 30 | BaseLib 31 | DebugLib 32 | MemoryAllocationLib 33 | -------------------------------------------------------------------------------- /OverflowDetectionPkg/Test/PartialFree/PartialFreePageSmm.inf: -------------------------------------------------------------------------------- 1 | ## @file 2 | # 3 | # Copyright (c) 2016, Intel Corporation. All rights reserved.
4 | # This program and the accompanying materials are licensed and made available under 5 | # the terms and conditions of the BSD License that accompanies this distribution. 6 | # The full text of the license may be found at 7 | # http://opensource.org/licenses/bsd-license.php. 8 | # 9 | # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | # 12 | ## 13 | 14 | [Defines] 15 | INF_VERSION = 0x00010005 16 | BASE_NAME = PartialFreePageSmm 17 | FILE_GUID = 062ABB58-6EC2-4986-BFE2-7532C7F810FC 18 | MODULE_TYPE = DXE_SMM_DRIVER 19 | VERSION_STRING = 1.0 20 | PI_SPECIFICATION_VERSION = 0x0001000A 21 | ENTRY_POINT = PartialFreePageEntrypoint 22 | 23 | [Sources] 24 | PartialFreePage.c 25 | 26 | [Packages] 27 | MdePkg/MdePkg.dec 28 | 29 | [LibraryClasses] 30 | UefiDriverEntryPoint 31 | BaseLib 32 | DebugLib 33 | MemoryAllocationLib 34 | 35 | [Depex] 36 | gEfiSmmCpuProtocolGuid 37 | -------------------------------------------------------------------------------- /OverflowDetectionPkg/Test/RingSwitch/Communication.h: -------------------------------------------------------------------------------- 1 | /** @file 2 | 3 | The common header file for SMM SPI module and SMM SPI DXE Module. 4 | 5 | Copyright (c) 2011, Intel Corporation. All rights reserved.
6 | This program and the accompanying materials 7 | are licensed and made available under the terms and conditions of the BSD License 8 | which accompanies this distribution. The full text of the license may be found at 9 | http://opensource.org/licenses/bsd-license.php 10 | 11 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 13 | 14 | **/ 15 | 16 | #ifndef __COMMUNICATION_H__ 17 | #define __COMMUNICATION_H__ 18 | 19 | #include 20 | 21 | #pragma pack(1) 22 | 23 | #define FUNCTION_TEST_PERF 1 24 | 25 | typedef struct { 26 | UINTN Function; 27 | EFI_STATUS ReturnStatus; 28 | UINT8 Data[1]; 29 | } SMM_TEST_COMMUNICATE_FUNCTION_HEADER; 30 | 31 | /// 32 | /// Size of SMM communicate header, without including the payload. 33 | /// 34 | #define SMM_COMMUNICATE_HEADER_SIZE (OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER, Data)) 35 | 36 | /// 37 | /// Size of SMM test communicate function header, without including the payload. 38 | /// 39 | #define SMM_TEST_COMMUNICATE_HEADER_SIZE (OFFSET_OF (SMM_TEST_COMMUNICATE_FUNCTION_HEADER, Data)) 40 | 41 | typedef struct { 42 | UINT64 StartTsc; 43 | UINT64 EndTsc; 44 | } SMM_TEST_PERF; 45 | 46 | #pragma pack() 47 | 48 | 49 | #define SMM_TEST_GUID \ 50 | {0x9df336f9, 0x450a, 0x4867, {0xa2, 0x40, 0x40, 0xdd, 0x4d, 0x6a, 0x1a, 0x76}} 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /OverflowDetectionPkg/Test/RingSwitch/Ia32/Ring.nasm: -------------------------------------------------------------------------------- 1 | ;------------------------------------------------------------------------------ ; 2 | ; Copyright (c) 2016, Intel Corporation. All rights reserved.
3 | ; This program and the accompanying materials 4 | ; are licensed and made available under the terms and conditions of the BSD License 5 | ; which accompanies this distribution. The full text of the license may be found at 6 | ; http://opensource.org/licenses/bsd-license.php. 7 | ; 8 | ; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 9 | ; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 10 | ; 11 | ;------------------------------------------------------------------------------- 12 | 13 | %define MSR_IA32_SYSENTER_CS 0x174 14 | %define MSR_IA32_SYSENTER_ESP 0x175 15 | %define MSR_IA32_SYSENTER_EIP 0x176 16 | 17 | SECTION .text 18 | 19 | global ASM_PFX(RingSwitch) 20 | ASM_PFX(RingSwitch): 21 | cli 22 | mov ecx, MSR_IA32_SYSENTER_CS 23 | mov eax, cs 24 | xor edx, edx 25 | wrmsr 26 | mov ecx, MSR_IA32_SYSENTER_EIP 27 | mov eax, ASM_PFX(SmiRing0ExitProc) 28 | xor edx, edx 29 | wrmsr 30 | mov ecx, MSR_IA32_SYSENTER_ESP 31 | mov eax, esp 32 | xor edx, edx 33 | wrmsr 34 | 35 | ; prepare enter ring 3 36 | mov edx, Ring3 ; RIP for Ring3 37 | mov ecx, esp ; RSP for Ring3 38 | SYSEXIT 39 | Ring3: 40 | ; we are in ring 3 now 41 | mov eax, ss 42 | mov ds, eax 43 | mov es, eax 44 | mov fs, eax 45 | mov gs, eax 46 | 47 | ; prepare enter ring 0 48 | SYSENTER 49 | 50 | ASM_PFX(SmiRing0ExitProc): 51 | ; we are in ring 0 now 52 | mov eax, ss 53 | mov ds, eax 54 | mov es, eax 55 | mov fs, eax 56 | mov gs, eax 57 | 58 | ret -------------------------------------------------------------------------------- /OverflowDetectionPkg/Test/RingSwitch/RingSwitch.inf: -------------------------------------------------------------------------------- 1 | ## @file 2 | # 3 | # Copyright (c) 2016, Intel Corporation. All rights reserved.
4 | # This program and the accompanying materials are licensed and made available under 5 | # the terms and conditions of the BSD License that accompanies this distribution. 6 | # The full text of the license may be found at 7 | # http://opensource.org/licenses/bsd-license.php. 8 | # 9 | # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | # 12 | ## 13 | 14 | [Defines] 15 | INF_VERSION = 0x00010005 16 | BASE_NAME = RingSwitch 17 | FILE_GUID = EC9D96CC-9010-4761-93B7-5CB9B30B9A68 18 | MODULE_TYPE = UEFI_APPLICATION 19 | VERSION_STRING = 1.0 20 | ENTRY_POINT = RingSwitchEntrypoint 21 | 22 | [Sources] 23 | RingSwitch.c 24 | CpuDump.c 25 | 26 | [Sources.Ia32] 27 | Ia32/Ring.nasm 28 | 29 | [Sources.X64] 30 | X64/Ring.nasm 31 | 32 | [Packages] 33 | MdePkg/MdePkg.dec 34 | MdeModulePkg/MdeModulePkg.dec 35 | 36 | [LibraryClasses] 37 | UefiApplicationEntryPoint 38 | BaseLib 39 | DebugLib 40 | BaseMemoryLib 41 | MemoryAllocationLib 42 | UefiLib 43 | 44 | [Guids] 45 | gPerformanceProtocolGuid 46 | -------------------------------------------------------------------------------- /OverflowDetectionPkg/Test/RingSwitch/RingSwitchSmm.inf: -------------------------------------------------------------------------------- 1 | ## @file 2 | # 3 | # Copyright (c) 2016, Intel Corporation. All rights reserved.
4 | # This program and the accompanying materials are licensed and made available under 5 | # the terms and conditions of the BSD License that accompanies this distribution. 6 | # The full text of the license may be found at 7 | # http://opensource.org/licenses/bsd-license.php. 8 | # 9 | # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | # 12 | ## 13 | 14 | [Defines] 15 | INF_VERSION = 0x00010005 16 | BASE_NAME = RingSwitchSmm 17 | FILE_GUID = EC9D96CC-9010-4761-93B7-5CB9B30B9A68 18 | MODULE_TYPE = DXE_SMM_DRIVER 19 | VERSION_STRING = 1.0 20 | PI_SPECIFICATION_VERSION = 0x0001000A 21 | ENTRY_POINT = RingSwitchEntrypoint 22 | 23 | [Sources] 24 | RingSwitchSmm.c 25 | CpuDump.c 26 | 27 | [Sources.Ia32] 28 | Ia32/Ring.nasm 29 | 30 | [Sources.X64] 31 | X64/Ring.nasm 32 | 33 | [Packages] 34 | MdePkg/MdePkg.dec 35 | MdeModulePkg/MdeModulePkg.dec 36 | 37 | [LibraryClasses] 38 | UefiDriverEntryPoint 39 | BaseLib 40 | DebugLib 41 | BaseMemoryLib 42 | MemoryAllocationLib 43 | SmmServicesTableLib 44 | 45 | [Depex] 46 | gEfiSmmCpuProtocolGuid -------------------------------------------------------------------------------- /OverflowDetectionPkg/Test/RingSwitch/RingSwitchSmmApp.inf: -------------------------------------------------------------------------------- 1 | ## @file 2 | # 3 | # Copyright (c) 2016, Intel Corporation. All rights reserved.
4 | # This program and the accompanying materials are licensed and made available under 5 | # the terms and conditions of the BSD License that accompanies this distribution. 6 | # The full text of the license may be found at 7 | # http://opensource.org/licenses/bsd-license.php. 8 | # 9 | # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | # 12 | ## 13 | 14 | [Defines] 15 | INF_VERSION = 0x00010005 16 | BASE_NAME = RingSwitchSmmApp 17 | FILE_GUID = EC9D96CC-9010-4761-93B7-5CB9B30B9A68 18 | MODULE_TYPE = UEFI_APPLICATION 19 | VERSION_STRING = 1.0 20 | ENTRY_POINT = RingSwitchEntrypoint 21 | 22 | [Sources] 23 | RingSwitchSmmApp.c 24 | CpuDump.c 25 | 26 | [Packages] 27 | MdePkg/MdePkg.dec 28 | MdeModulePkg/MdeModulePkg.dec 29 | 30 | [LibraryClasses] 31 | UefiApplicationEntryPoint 32 | BaseLib 33 | DebugLib 34 | BaseMemoryLib 35 | MemoryAllocationLib 36 | UefiLib 37 | 38 | [Guids] 39 | gPerformanceProtocolGuid 40 | gEdkiiPiSmmCommunicationRegionTableGuid 41 | 42 | [Protocols] 43 | gEfiSmmCommunicationProtocolGuid 44 | -------------------------------------------------------------------------------- /OverflowDetectionPkg/Test/RingSwitch/X64/Ring.nasm: -------------------------------------------------------------------------------- 1 | ;------------------------------------------------------------------------------ ; 2 | ; Copyright (c) 2016, Intel Corporation. All rights reserved.
3 | ; This program and the accompanying materials 4 | ; are licensed and made available under the terms and conditions of the BSD License 5 | ; which accompanies this distribution. The full text of the license may be found at 6 | ; http://opensource.org/licenses/bsd-license.php. 7 | ; 8 | ; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 9 | ; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 10 | ; 11 | ;------------------------------------------------------------------------------- 12 | 13 | %define MSR_IA32_SYSENTER_CS 0x174 14 | %define MSR_IA32_SYSENTER_ESP 0x175 15 | %define MSR_IA32_SYSENTER_EIP 0x176 16 | 17 | SECTION .text 18 | 19 | global ASM_PFX(RingSwitch) 20 | ASM_PFX(RingSwitch): 21 | cli 22 | mov ecx, MSR_IA32_SYSENTER_CS 23 | mov eax, cs 24 | xor edx, edx 25 | wrmsr 26 | mov ecx, MSR_IA32_SYSENTER_EIP 27 | mov rax, ASM_PFX(SmiRing0ExitProc) 28 | xor edx, edx 29 | wrmsr 30 | mov ecx, MSR_IA32_SYSENTER_ESP 31 | mov rax, rsp 32 | xor edx, edx 33 | wrmsr 34 | 35 | ; prepare enter ring 3 36 | mov rdx, Ring3 ; RIP for Ring3 37 | mov rcx, rsp ; RSP for Ring3 38 | SYSEXIT64 39 | Ring3: 40 | ; we are in ring 3 now 41 | mov eax, ss 42 | mov ds, eax 43 | mov es, eax 44 | mov fs, eax 45 | mov gs, eax 46 | 47 | ; prepare enter ring 0 48 | SYSENTER 49 | 50 | ASM_PFX(SmiRing0ExitProc): 51 | ; we are in ring 0 now 52 | mov eax, ss 53 | mov ds, eax 54 | mov es, eax 55 | mov fs, eax 56 | mov gs, eax 57 | 58 | ret -------------------------------------------------------------------------------- /OverflowDetectionPkg/Test/StackOverflow/Ia32/Stack.nasm: -------------------------------------------------------------------------------- 1 | ;------------------------------------------------------------------------------ ; 2 | ; Copyright (c) 2016, Intel Corporation. All rights reserved.
3 | ; This program and the accompanying materials 4 | ; are licensed and made available under the terms and conditions of the BSD License 5 | ; which accompanies this distribution. The full text of the license may be found at 6 | ; http://opensource.org/licenses/bsd-license.php. 7 | ; 8 | ; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 9 | ; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 10 | ; 11 | ;------------------------------------------------------------------------------- 12 | 13 | SECTION .text 14 | 15 | global ASM_PFX(TestCode) 16 | ASM_PFX(TestCode): 17 | @@: 18 | push eax 19 | jmp @@ 20 | 21 | -------------------------------------------------------------------------------- /OverflowDetectionPkg/Test/StackOverflow/StackOverflow.c: -------------------------------------------------------------------------------- 1 | /** @file 2 | 3 | Copyright (c) 2016, Intel Corporation. All rights reserved.
4 | This program and the accompanying materials 5 | are licensed and made available under the terms and conditions of the BSD License 6 | which accompanies this distribution. The full text of the license may be found at 7 | http://opensource.org/licenses/bsd-license.php 8 | 9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | 12 | **/ 13 | 14 | #include 15 | 16 | VOID 17 | DumpArchStatus( 18 | VOID 19 | ); 20 | 21 | VOID 22 | EFIAPI 23 | TestCode ( 24 | VOID 25 | ); 26 | 27 | EFI_STATUS 28 | EFIAPI 29 | StackOverflowEntrypoint( 30 | IN EFI_HANDLE ImageHandle, 31 | IN EFI_SYSTEM_TABLE *SystemTable 32 | ) 33 | { 34 | DumpArchStatus(); 35 | 36 | TestCode(); 37 | return EFI_SUCCESS; 38 | } 39 | -------------------------------------------------------------------------------- /OverflowDetectionPkg/Test/StackOverflow/StackOverflow.inf: -------------------------------------------------------------------------------- 1 | ## @file 2 | # 3 | # Copyright (c) 2016, Intel Corporation. All rights reserved.
4 | # This program and the accompanying materials are licensed and made available under 5 | # the terms and conditions of the BSD License that accompanies this distribution. 6 | # The full text of the license may be found at 7 | # http://opensource.org/licenses/bsd-license.php. 8 | # 9 | # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | # 12 | ## 13 | 14 | [Defines] 15 | INF_VERSION = 0x00010005 16 | BASE_NAME = StackOverflow 17 | FILE_GUID = 77C57384-61A2-4F8A-9D3E-5BAA02BCEE87 18 | MODULE_TYPE = UEFI_APPLICATION 19 | VERSION_STRING = 1.0 20 | ENTRY_POINT = StackOverflowEntrypoint 21 | 22 | [Sources] 23 | StackOverflow.c 24 | CpuDump.c 25 | 26 | [Sources.Ia32] 27 | Ia32/Stack.nasm 28 | 29 | [Sources.X64] 30 | X64/Stack.nasm 31 | 32 | [Packages] 33 | MdePkg/MdePkg.dec 34 | 35 | [LibraryClasses] 36 | UefiApplicationEntryPoint 37 | BaseLib 38 | DebugLib 39 | -------------------------------------------------------------------------------- /OverflowDetectionPkg/Test/StackOverflow/StackOverflowSmm.c: -------------------------------------------------------------------------------- 1 | /** @file 2 | 3 | Copyright (c) 2016, Intel Corporation. All rights reserved.
4 | This program and the accompanying materials 5 | are licensed and made available under the terms and conditions of the BSD License 6 | which accompanies this distribution. The full text of the license may be found at 7 | http://opensource.org/licenses/bsd-license.php 8 | 9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | 12 | **/ 13 | 14 | #include 15 | #include 16 | #include 17 | 18 | VOID 19 | DumpArchStatus( 20 | VOID 21 | ); 22 | 23 | VOID 24 | EFIAPI 25 | TestCode ( 26 | VOID 27 | ); 28 | 29 | EFI_STATUS 30 | EFIAPI 31 | SmmReadyToBootCallback ( 32 | IN CONST EFI_GUID *Protocol, 33 | IN VOID *Interface, 34 | IN EFI_HANDLE Handle 35 | ) 36 | { 37 | //DumpArchStatus(); 38 | 39 | TestCode(); 40 | return EFI_SUCCESS; 41 | } 42 | 43 | EFI_STATUS 44 | EFIAPI 45 | StackOverflowEntrypoint( 46 | IN EFI_HANDLE ImageHandle, 47 | IN EFI_SYSTEM_TABLE *SystemTable 48 | ) 49 | { 50 | EFI_STATUS Status; 51 | VOID *SmmReadyToBootRegistration; 52 | 53 | Status = gSmst->SmmRegisterProtocolNotify ( 54 | &gEdkiiSmmReadyToBootProtocolGuid, 55 | SmmReadyToBootCallback, 56 | &SmmReadyToBootRegistration 57 | ); 58 | ASSERT_EFI_ERROR (Status); 59 | 60 | return EFI_SUCCESS; 61 | } 62 | -------------------------------------------------------------------------------- /OverflowDetectionPkg/Test/StackOverflow/StackOverflowSmm.inf: -------------------------------------------------------------------------------- 1 | ## @file 2 | # 3 | # Copyright (c) 2016, Intel Corporation. All rights reserved.
4 | # This program and the accompanying materials are licensed and made available under 5 | # the terms and conditions of the BSD License that accompanies this distribution. 6 | # The full text of the license may be found at 7 | # http://opensource.org/licenses/bsd-license.php. 8 | # 9 | # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | # 12 | ## 13 | 14 | [Defines] 15 | INF_VERSION = 0x00010005 16 | BASE_NAME = StackOverflowSmm 17 | FILE_GUID = 5AD9B89A-249A-4E98-8975-61E421E663AA 18 | MODULE_TYPE = DXE_SMM_DRIVER 19 | VERSION_STRING = 1.0 20 | PI_SPECIFICATION_VERSION = 0x0001000A 21 | ENTRY_POINT = StackOverflowEntrypoint 22 | 23 | [Sources] 24 | StackOverflowSmm.c 25 | CpuDump.c 26 | 27 | [Sources.Ia32] 28 | Ia32/Stack.nasm 29 | 30 | [Sources.X64] 31 | X64/Stack.nasm 32 | 33 | [Packages] 34 | MdePkg/MdePkg.dec 35 | MdeModulePkg/MdeModulePkg.dec 36 | 37 | [LibraryClasses] 38 | UefiDriverEntryPoint 39 | BaseLib 40 | DebugLib 41 | SmmServicesTableLib 42 | 43 | [Protocols] 44 | gEdkiiSmmReadyToBootProtocolGuid 45 | 46 | [Depex] 47 | gEfiSmmCpuProtocolGuid 48 | -------------------------------------------------------------------------------- /OverflowDetectionPkg/Test/StackOverflow/X64/Stack.nasm: -------------------------------------------------------------------------------- 1 | ;------------------------------------------------------------------------------ ; 2 | ; Copyright (c) 2016, Intel Corporation. All rights reserved.
3 | ; This program and the accompanying materials 4 | ; are licensed and made available under the terms and conditions of the BSD License 5 | ; which accompanies this distribution. The full text of the license may be found at 6 | ; http://opensource.org/licenses/bsd-license.php. 7 | ; 8 | ; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 9 | ; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 10 | ; 11 | ;------------------------------------------------------------------------------- 12 | 13 | SECTION .text 14 | 15 | global ASM_PFX(TestCode) 16 | ASM_PFX(TestCode): 17 | @@: 18 | push rax 19 | jmp @@ 20 | 21 | -------------------------------------------------------------------------------- /OverflowDetectionPkg/Test/WriteCodeSection/WriteCodeSection.c: -------------------------------------------------------------------------------- 1 | /** @file 2 | 3 | Copyright (c) 2016, Intel Corporation. All rights reserved.
4 | This program and the accompanying materials 5 | are licensed and made available under the terms and conditions of the BSD License 6 | which accompanies this distribution. The full text of the license may be found at 7 | http://opensource.org/licenses/bsd-license.php 8 | 9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | 12 | **/ 13 | 14 | #include 15 | #include 16 | 17 | EFI_STATUS 18 | EFIAPI 19 | WriteCodeSectionEntrypoint( 20 | IN EFI_HANDLE ImageHandle, 21 | IN EFI_SYSTEM_TABLE *SystemTable 22 | ) 23 | { 24 | VOID *Buffer; 25 | 26 | Buffer = (VOID *)(UINTN)WriteCodeSectionEntrypoint; 27 | *(UINT16 *)Buffer = 0xFEEB; 28 | return EFI_SUCCESS; 29 | } 30 | -------------------------------------------------------------------------------- /OverflowDetectionPkg/Test/WriteCodeSection/WriteCodeSection.inf: -------------------------------------------------------------------------------- 1 | ## @file 2 | # 3 | # Copyright (c) 2016, Intel Corporation. All rights reserved.
4 | # This program and the accompanying materials are licensed and made available under 5 | # the terms and conditions of the BSD License that accompanies this distribution. 6 | # The full text of the license may be found at 7 | # http://opensource.org/licenses/bsd-license.php. 8 | # 9 | # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | # 12 | ## 13 | 14 | [Defines] 15 | INF_VERSION = 0x00010005 16 | BASE_NAME = WriteCodeSection 17 | FILE_GUID = E2EEBAE9-6C77-4375-8888-0AE2E163F0A9 18 | MODULE_TYPE = UEFI_APPLICATION 19 | VERSION_STRING = 1.0 20 | PI_SPECIFICATION_VERSION = 0x0001000A 21 | ENTRY_POINT = WriteCodeSectionEntrypoint 22 | 23 | [Sources] 24 | WriteCodeSection.c 25 | 26 | [Packages] 27 | MdePkg/MdePkg.dec 28 | 29 | [LibraryClasses] 30 | UefiApplicationEntryPoint 31 | BaseLib 32 | DebugLib 33 | -------------------------------------------------------------------------------- /OverflowDetectionPkg/Test/WriteCodeSection/WriteCodeSectionSmm.c: -------------------------------------------------------------------------------- 1 | /** @file 2 | 3 | Copyright (c) 2016, Intel Corporation. All rights reserved.
4 | This program and the accompanying materials 5 | are licensed and made available under the terms and conditions of the BSD License 6 | which accompanies this distribution. The full text of the license may be found at 7 | http://opensource.org/licenses/bsd-license.php 8 | 9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | 12 | **/ 13 | 14 | #include 15 | #include 16 | #include 17 | 18 | EFI_STATUS 19 | EFIAPI 20 | SmmReadyToBootCallback ( 21 | IN CONST EFI_GUID *Protocol, 22 | IN VOID *Interface, 23 | IN EFI_HANDLE Handle 24 | ) 25 | { 26 | VOID *Buffer; 27 | 28 | Buffer = (VOID *)(UINTN)SmmReadyToBootCallback; 29 | *(UINT16 *)Buffer = 0xFEEB; 30 | return EFI_SUCCESS; 31 | } 32 | 33 | EFI_STATUS 34 | EFIAPI 35 | WriteCodeSectionEntrypoint( 36 | IN EFI_HANDLE ImageHandle, 37 | IN EFI_SYSTEM_TABLE *SystemTable 38 | ) 39 | { 40 | EFI_STATUS Status; 41 | VOID *SmmReadyToBootRegistration; 42 | 43 | Status = gSmst->SmmRegisterProtocolNotify ( 44 | &gEdkiiSmmReadyToBootProtocolGuid, 45 | SmmReadyToBootCallback, 46 | &SmmReadyToBootRegistration 47 | ); 48 | ASSERT_EFI_ERROR (Status); 49 | 50 | return EFI_SUCCESS; 51 | } 52 | -------------------------------------------------------------------------------- /OverflowDetectionPkg/Test/WriteCodeSection/WriteCodeSectionSmm.inf: -------------------------------------------------------------------------------- 1 | ## @file 2 | # 3 | # Copyright (c) 2016, Intel Corporation. All rights reserved.
4 | # This program and the accompanying materials are licensed and made available under 5 | # the terms and conditions of the BSD License that accompanies this distribution. 6 | # The full text of the license may be found at 7 | # http://opensource.org/licenses/bsd-license.php. 8 | # 9 | # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | # 12 | ## 13 | 14 | [Defines] 15 | INF_VERSION = 0x00010005 16 | BASE_NAME = WriteCodeSectionSmm 17 | FILE_GUID = 612EEA55-1873-4515-9B41-281BF9AC3E26 18 | MODULE_TYPE = DXE_SMM_DRIVER 19 | VERSION_STRING = 1.0 20 | PI_SPECIFICATION_VERSION = 0x0001000A 21 | ENTRY_POINT = WriteCodeSectionEntrypoint 22 | 23 | [Sources] 24 | WriteCodeSectionSmm.c 25 | 26 | [Packages] 27 | MdePkg/MdePkg.dec 28 | MdeModulePkg/MdeModulePkg.dec 29 | 30 | [LibraryClasses] 31 | UefiDriverEntryPoint 32 | BaseLib 33 | DebugLib 34 | SmmServicesTableLib 35 | 36 | [Protocols] 37 | gEdkiiSmmReadyToBootProtocolGuid 38 | 39 | [Depex] 40 | gEfiSmmCpuProtocolGuid 41 | -------------------------------------------------------------------------------- /StackCheckPkg/Library/StackCheckLib/GSStub.c: -------------------------------------------------------------------------------- 1 | /** 2 | 3 | Copyright (c) 2012, Intel Corporation 4 | All rights reserved. This program and the accompanying materials 5 | are licensed and made available under the terms and conditions of the BSD License 6 | which accompanies this distribution. The full text of the license may be found at 7 | http://opensource.org/licenses/bsd-license.php 8 | 9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | 12 | **/ 13 | 14 | #include 15 | 16 | #include 17 | #include 18 | #include 19 | 20 | // 21 | // Below data structure is from vcruntime.h and gs_report.c (Microsoft Visual Studio) 22 | // 23 | 24 | UINTN __security_cookie = 0; 25 | 26 | void __security_init_cookie(void) 27 | { 28 | UINT64 Cookie; 29 | GetRandomNumber64(&Cookie); 30 | __security_cookie = (UINTN)Cookie; 31 | } 32 | 33 | static void __cdecl __report_gsfailure(UINTN StackCookie) 34 | { 35 | DEBUG ((EFI_D_ERROR, "\n!!! stack overflow check failed in cookie checker!!!\n")); 36 | ASSERT (FALSE); 37 | 38 | CpuDeadLoop(); 39 | return ; 40 | } 41 | 42 | __declspec(noreturn) void __cdecl __report_rangecheckfailure() 43 | { 44 | DEBUG((EFI_D_ERROR, "\n!!! range check check failed in cookie checker!!!\n")); 45 | ASSERT(FALSE); 46 | 47 | CpuDeadLoop(); 48 | } 49 | 50 | void __fastcall __security_check_cookie(UINTN cookie) 51 | { 52 | if (cookie == __security_cookie) { 53 | return; 54 | } 55 | 56 | __report_gsfailure(cookie); 57 | return ; 58 | } 59 | 60 | void __GSHandlerCheck(void) 61 | { 62 | // dummy 63 | CpuDeadLoop (); 64 | return ; 65 | } 66 | 67 | RETURN_STATUS 68 | EFIAPI 69 | StackCheckLibConstructor( 70 | VOID 71 | ) 72 | { 73 | __security_init_cookie(); 74 | return RETURN_SUCCESS; 75 | } -------------------------------------------------------------------------------- /StackCheckPkg/Library/StackCheckLib/MSanStub.c: -------------------------------------------------------------------------------- 1 | /** 2 | 3 | Copyright (c) 2012, Intel Corporation 4 | All rights reserved. This program and the accompanying materials 5 | are licensed and made available under the terms and conditions of the BSD License 6 | which accompanies this distribution. The full text of the license may be found at 7 | http://opensource.org/licenses/bsd-license.php 8 | 9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | 12 | **/ 13 | 14 | #include 15 | 16 | #include 17 | #include 18 | #include 19 | 20 | VOID 21 | __msan_warning_noreturn () 22 | { 23 | DEBUG ((DEBUG_ERROR, "\n!!! __msan_warning_noreturn !!!\n")); 24 | ASSERT (FALSE); 25 | CpuDeadLoop(); 26 | } -------------------------------------------------------------------------------- /StackCheckPkg/Library/StackCheckLib/RTCStub.c: -------------------------------------------------------------------------------- 1 | /** 2 | 3 | Copyright (c) 2012, Intel Corporation 4 | All rights reserved. This program and the accompanying materials 5 | are licensed and made available under the terms and conditions of the BSD License 6 | which accompanies this distribution. The full text of the license may be found at 7 | http://opensource.org/licenses/bsd-license.php 8 | 9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | 12 | **/ 13 | 14 | #include 15 | 16 | #include 17 | #include 18 | 19 | void __cdecl _RTC_Shutdown(void) 20 | { 21 | // dummy 22 | return ; 23 | } 24 | 25 | void __cdecl _RTC_InitBase(void) 26 | { 27 | // dummy 28 | return ; 29 | } 30 | -------------------------------------------------------------------------------- /StackCheckPkg/Library/StackCheckLib/RTCcStub.c: -------------------------------------------------------------------------------- 1 | /** 2 | 3 | Copyright (c) 2012, Intel Corporation 4 | All rights reserved. This program and the accompanying materials 5 | are licensed and made available under the terms and conditions of the BSD License 6 | which accompanies this distribution. The full text of the license may be found at 7 | http://opensource.org/licenses/bsd-license.php 8 | 9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | 12 | **/ 13 | 14 | #include 15 | 16 | #include 17 | #include 18 | 19 | // 20 | // Below data structure is from rtcapi.h (Microsoft Visual Studio) 21 | // 22 | 23 | void _RTCc_Failure () { 24 | DEBUG ((EFI_D_ERROR, "\n!!! small type check failed!!!\n")); 25 | ASSERT (FALSE); 26 | 27 | CpuDeadLoop(); 28 | return ; 29 | } 30 | 31 | char __fastcall _RTC_Check_2_to_1(short _Src) 32 | { 33 | if ((_Src & 0xFF00) != 0) { 34 | _RTCc_Failure (); 35 | } 36 | return (char)(_Src & 0xFF); 37 | } 38 | 39 | char __fastcall _RTC_Check_4_to_1(int _Src) 40 | { 41 | if ((_Src & 0xFFFFFF00) != 0) { 42 | _RTCc_Failure (); 43 | } 44 | return (char)(_Src & 0xFF); 45 | } 46 | 47 | char __fastcall _RTC_Check_8_to_1(__int64 _Src) 48 | { 49 | if ((_Src & 0xFFFFFFFFFFFFFF00) != 0) { 50 | _RTCc_Failure (); 51 | } 52 | return (char)(_Src & 0xFF); 53 | } 54 | 55 | short __fastcall _RTC_Check_4_to_2(int _Src) 56 | { 57 | if ((_Src & 0xFFFF0000) != 0) { 58 | _RTCc_Failure (); 59 | } 60 | return (short)(_Src & 0xFFFF); 61 | } 62 | 63 | short __fastcall _RTC_Check_8_to_2(__int64 _Src) 64 | { 65 | if ((_Src & 0xFFFFFFFFFFFF0000) != 0) { 66 | _RTCc_Failure (); 67 | } 68 | return (short)(_Src & 0xFFFF); 69 | } 70 | 71 | int __fastcall _RTC_Check_8_to_4(__int64 _Src) 72 | { 73 | if ((_Src & 0xFFFFFFFF00000000) != 0) { 74 | _RTCc_Failure (); 75 | } 76 | return (int)(_Src & 0xFFFFFFFF); 77 | } 78 | -------------------------------------------------------------------------------- /StackCheckPkg/Library/StackCheckLib/RTCsStub.c: -------------------------------------------------------------------------------- 1 | /** 2 | 3 | Copyright (c) 2012, Intel Corporation 4 | All rights reserved. This program and the accompanying materials 5 | are licensed and made available under the terms and conditions of the BSD License 6 | which accompanies this distribution. The full text of the license may be found at 7 | http://opensource.org/licenses/bsd-license.php 8 | 9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | 12 | **/ 13 | 14 | #include 15 | 16 | #include 17 | #include 18 | 19 | // 20 | // Below data structure is from rtcapi.h (Microsoft Visual Studio) 21 | // 22 | 23 | typedef struct _RTC_vardesc { 24 | int addr; 25 | int size; 26 | char *name; 27 | } _RTC_vardesc; 28 | 29 | typedef struct _RTC_framedesc { 30 | int varCount; 31 | _RTC_vardesc *variables; 32 | } _RTC_framedesc; 33 | 34 | #define RTC_STACK_CHECK_COOKIE 0xCCCCCCCC 35 | 36 | #ifdef MDE_CPU_IA32 37 | 38 | static void _RTC_Failure () 39 | { 40 | DEBUG ((EFI_D_ERROR, "\n!!! stack pointer check failed in StackChecker!!!\n")); 41 | ASSERT (FALSE); 42 | 43 | CpuDeadLoop(); 44 | return ; 45 | } 46 | 47 | void __declspec(naked) __cdecl _RTC_CheckEsp() 48 | { 49 | __asm { 50 | jne CheckEspFail 51 | ret 52 | CheckEspFail: 53 | call _RTC_Failure 54 | ret 55 | } 56 | } 57 | #endif 58 | 59 | static void _RTC_StackFailure (char *name) 60 | { 61 | DEBUG ((EFI_D_ERROR, "\n!!! stack variable check failed in StackChecker!!!\n")); 62 | ASSERT (FALSE); 63 | 64 | CpuDeadLoop(); 65 | return ; 66 | } 67 | 68 | void __fastcall _RTC_CheckStackVars (void *_Esp, _RTC_framedesc *_Fd) 69 | { 70 | int Index; 71 | UINT8 *Addr; 72 | 73 | for (Index = 0; Index < _Fd->varCount; Index++) { 74 | Addr = (UINT8 *)_Esp + _Fd->variables[Index].addr - sizeof(UINT32); 75 | if (*(int *)Addr != RTC_STACK_CHECK_COOKIE) { 76 | _RTC_StackFailure (_Fd->variables[Index].name); 77 | } 78 | 79 | Addr = (UINT8 *)_Esp + _Fd->variables[Index].addr + _Fd->variables[Index].size; 80 | if (*(int *)Addr != RTC_STACK_CHECK_COOKIE) { 81 | _RTC_StackFailure (_Fd->variables[Index].name); 82 | } 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /StackCheckPkg/Library/StackCheckLib/RTCuStub.c: -------------------------------------------------------------------------------- 1 | /** 2 | 3 | Copyright (c) 2012, Intel Corporation 4 | All rights reserved. This program and the accompanying materials 5 | are licensed and made available under the terms and conditions of the BSD License 6 | which accompanies this distribution. The full text of the license may be found at 7 | http://opensource.org/licenses/bsd-license.php 8 | 9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | 12 | **/ 13 | 14 | #include 15 | 16 | #include 17 | #include 18 | 19 | // 20 | // Below data structure is from rtcapi.h (Microsoft Visual Studio) 21 | // 22 | 23 | void __cdecl _RTC_UninitUse(const char *VarName) 24 | { 25 | DEBUG ((EFI_D_ERROR, "\n!!! uninitialized var \"%a\" is used!!!\n", VarName)); 26 | ASSERT (FALSE); 27 | 28 | CpuDeadLoop(); 29 | return ; 30 | } 31 | -------------------------------------------------------------------------------- /StackCheckPkg/Library/StackCheckLib/StackCheckLib.inf: -------------------------------------------------------------------------------- 1 | ## @file 2 | # 3 | # Copyright (c) 2010 Intel Corporation. All rights reserved.
4 | # This program and the accompanying materials are 5 | # licensed and made available under the terms and conditions of the BSD License 6 | # which accompanies this distribution. The full text of the license may be found at 7 | # http://opensource.org/licenses/bsd-license.php 8 | # 9 | # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | # 12 | ## 13 | 14 | [Defines] 15 | INF_VERSION = 0x00010005 16 | BASE_NAME = StackCheckLib 17 | FILE_GUID = AAC7C825-4866-4a27-824C-31E9B1DD3BCF 18 | MODULE_TYPE = BASE 19 | VERSION_STRING = 1.0 20 | LIBRARY_CLASS = NULL 21 | CONSTRUCTOR = StackCheckLibConstructor 22 | 23 | [Sources] 24 | GSStub.c | MSFT 25 | RTCStub.c | MSFT 26 | RTCsStub.c | MSFT 27 | RTCcStub.c | MSFT 28 | RTCuStub.c | MSFT 29 | StackProtectorStub.c | GCC 30 | ASanStub.c | GCC 31 | UBSanStub.c | GCC 32 | 33 | [Packages] 34 | MdePkg/MdePkg.dec 35 | 36 | [LibraryClasses] 37 | BaseLib 38 | DebugLib 39 | RngLib 40 | 41 | [BuildOptions] 42 | MSFT:*_*_*_CC_FLAGS = /Od /GL- 43 | GCC:*_*_*_CC_FLAGS = -O0 -------------------------------------------------------------------------------- /StackCheckPkg/Library/StackCheckLib/StackProtectorStub.c: -------------------------------------------------------------------------------- 1 | /** 2 | 3 | Copyright (c) 2012, Intel Corporation 4 | All rights reserved. This program and the accompanying materials 5 | are licensed and made available under the terms and conditions of the BSD License 6 | which accompanies this distribution. The full text of the license may be found at 7 | http://opensource.org/licenses/bsd-license.php 8 | 9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | 12 | **/ 13 | 14 | #include 15 | 16 | #include 17 | #include 18 | #include 19 | 20 | VOID 21 | EFIAPI 22 | ASanLibConstructor( 23 | VOID 24 | ); 25 | 26 | // 27 | // Implementation 28 | // 29 | 30 | UINTN __stack_chk_guard = 0; 31 | 32 | void __init_stack_check_guard(void) 33 | { 34 | UINT64 Guard; 35 | GetRandomNumber64(&Guard); 36 | __stack_chk_guard = (UINTN)Guard; 37 | } 38 | 39 | void __stack_chk_fail() 40 | { 41 | DEBUG ((EFI_D_ERROR, "\n!!! stack overflow check failed in stack protector!!!\n")); 42 | ASSERT (FALSE); 43 | 44 | CpuDeadLoop(); 45 | return ; 46 | } 47 | 48 | RETURN_STATUS 49 | EFIAPI 50 | StackCheckLibConstructor( 51 | VOID 52 | ) 53 | { 54 | __init_stack_check_guard(); 55 | ASanLibConstructor (); 56 | return RETURN_SUCCESS; 57 | } -------------------------------------------------------------------------------- /StackCheckPkg/License.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012, Intel Corporation. All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions 5 | are met: 6 | 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above copyright 10 | notice, this list of conditions and the following disclaimer in 11 | the documentation and/or other materials provided with the 12 | distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 15 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 16 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 17 | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 18 | COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 19 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 20 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 24 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 | POSSIBILITY OF SUCH DAMAGE. 26 | -------------------------------------------------------------------------------- /StackCheckPkg/StackCheckPkg.dec: -------------------------------------------------------------------------------- 1 | ## @file 2 | # 3 | # Copyright (c) 2012, Intel Corporation. All rights reserved.
4 | # 5 | # This program and the accompanying materials 6 | # are licensed and made available under the terms and conditions of the BSD License 7 | # which accompanies this distribution. The full text of the license may be found at 8 | # http://opensource.org/licenses/bsd-license.php 9 | # 10 | # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 12 | # 13 | ## 14 | 15 | [Defines] 16 | DEC_SPECIFICATION = 0x00010005 17 | PACKAGE_NAME = StackCheckPkg 18 | PACKAGE_GUID = A74B0CB1-017C-4213-B527-DFFE0CDA927A 19 | PACKAGE_VERSION = 0.1 20 | 21 | [Includes] 22 | -------------------------------------------------------------------------------- /StackCheckPkg/Test/SideChannelTest/SideChannelTest.c: -------------------------------------------------------------------------------- 1 | /** 2 | 3 | Copyright (c) 2007, Intel Corporation 4 | All rights reserved. This program and the accompanying materials 5 | are licensed and made available under the terms and conditions of the BSD License 6 | which accompanies this distribution. The full text of the license may be found at 7 | http://opensource.org/licenses/bsd-license.php 8 | 9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | 12 | **/ 13 | 14 | #include 15 | 16 | #include 17 | #include 18 | #include 19 | 20 | 21 | #define ARRAY1_NUM 256 22 | #define ARRAY2_NUM 256 23 | 24 | UINT8 Array1[ARRAY1_NUM]; 25 | UINT8 Array2[ARRAY1_NUM]; 26 | 27 | UINT8 28 | TestA ( 29 | IN UINTN UntrustedIndex 30 | ) 31 | { 32 | UINT8 Value; 33 | UINT8 Value2 = 0; 34 | 35 | if (UntrustedIndex < ARRAY1_NUM) { 36 | Value = Array1[UntrustedIndex]; 37 | Value2 = Array2[Value * 64]; 38 | } 39 | return Value2; 40 | } 41 | 42 | EFI_STATUS 43 | EFIAPI 44 | SideChannelTestInitialize ( 45 | IN EFI_HANDLE ImageHandle, 46 | IN EFI_SYSTEM_TABLE *SystemTable 47 | ) 48 | { 49 | CopyMem (Array1, SystemTable, sizeof(Array1)); 50 | CopyMem (Array2, SystemTable, sizeof(Array2)); 51 | return (UINTN)TestA ((UINTN)ImageHandle); 52 | } -------------------------------------------------------------------------------- /StackCheckPkg/Test/SideChannelTest/SideChannelTest.inf: -------------------------------------------------------------------------------- 1 | ## @file 2 | # 3 | # Copyright (c) 2010 Intel Corporation. All rights reserved.
4 | # This program and the accompanying materials are 5 | # licensed and made available under the terms and conditions of the BSD License 6 | # which accompanies this distribution. The full text of the license may be found at 7 | # http://opensource.org/licenses/bsd-license.php 8 | # 9 | # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | # 12 | ## 13 | 14 | [Defines] 15 | INF_VERSION = 0x00010005 16 | BASE_NAME = SideChannelTest 17 | FILE_GUID = 8A7F0476-717B-4004-B1E9-042E839AF8C0 18 | MODULE_TYPE = UEFI_DRIVER 19 | VERSION_STRING = 1.0 20 | ENTRY_POINT = SideChannelTestInitialize 21 | 22 | [Sources] 23 | SideChannelTest.c 24 | 25 | [Packages] 26 | MdePkg/MdePkg.dec 27 | 28 | [LibraryClasses] 29 | UefiDriverEntryPoint 30 | 31 | [BuildOptions] 32 | # /Qspectre-load 33 | # /Qspectre-load-cf 34 | MSFT:*_*_*_CC_FLAGS = /GL- /Qspectre 35 | GCC:*_CLANGPDB_*_CC_FLAGS = -O0 -mspeculative-load-hardening 36 | -------------------------------------------------------------------------------- /StackCheckPkg/Test/SmallTypeTest/SmallTypeTest.c: -------------------------------------------------------------------------------- 1 | /** 2 | 3 | Copyright (c) 2007, Intel Corporation 4 | All rights reserved. This program and the accompanying materials 5 | are licensed and made available under the terms and conditions of the BSD License 6 | which accompanies this distribution. The full text of the license may be found at 7 | http://opensource.org/licenses/bsd-license.php 8 | 9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | 12 | **/ 13 | 14 | #include 15 | 16 | #include 17 | #include 18 | #include 19 | 20 | UINT8 21 | TestA ( 22 | VOID 23 | ) 24 | { 25 | UINTN Data = 0xFFFFFFFF; 26 | UINT8 Data8 = 0; 27 | 28 | // 29 | // NOTE: warning C4244: '=': conversion from 'UINTN' to 'UINT8', possible loss of data 30 | // It can only catch data without cast - Data8 = (Data >> 8); 31 | // Data8 = (Data >> 8); 32 | 33 | Data8 = (CHAR8)(Data >> 8); 34 | // 35 | // NOTE: Using type case cannot resolve the error. 36 | // Need use explicit data truncate - (CHAR8)((Data >> 8) & 0xFF); 37 | // 38 | // Data8 = (CHAR8)((Data >> 8) & 0xFF); 39 | return Data8; 40 | } 41 | 42 | INT32 43 | TestB ( 44 | INT32 Test 45 | ) 46 | { 47 | INT32 Data = 0x7fffffff; 48 | Data += Test; 49 | return Data; 50 | } 51 | 52 | EFI_STATUS 53 | EFIAPI 54 | SmallTypeTestInitialize ( 55 | IN EFI_HANDLE ImageHandle, 56 | IN EFI_SYSTEM_TABLE *SystemTable 57 | ) 58 | { 59 | TestA (); 60 | 61 | TestB (3); 62 | 63 | return EFI_SUCCESS; 64 | } -------------------------------------------------------------------------------- /StackCheckPkg/Test/SmallTypeTest/SmallTypeTest.inf: -------------------------------------------------------------------------------- 1 | ## @file 2 | # 3 | # Copyright (c) 2010 Intel Corporation. All rights reserved.
4 | # This program and the accompanying materials are 5 | # licensed and made available under the terms and conditions of the BSD License 6 | # which accompanies this distribution. The full text of the license may be found at 7 | # http://opensource.org/licenses/bsd-license.php 8 | # 9 | # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | # 12 | ## 13 | 14 | [Defines] 15 | INF_VERSION = 0x00010005 16 | BASE_NAME = SmallTypeTest 17 | FILE_GUID = D447F72A-369D-465E-824B-336E8BB1B1D9 18 | MODULE_TYPE = UEFI_DRIVER 19 | VERSION_STRING = 1.0 20 | ENTRY_POINT = SmallTypeTestInitialize 21 | 22 | [Sources] 23 | SmallTypeTest.c 24 | 25 | [Packages] 26 | MdePkg/MdePkg.dec 27 | 28 | [LibraryClasses] 29 | UefiDriverEntryPoint 30 | 31 | [BuildOptions] 32 | # warning C4244: '=': conversion from 'UINTN' to 'UINT8', possible loss of data 33 | MSFT:*_*_*_CC_FLAGS = /Od /GL- /RTCc 34 | GCC:*_CLANGPDB_*_CC_FLAGS = -O0 -fsanitize=undefined 35 | -------------------------------------------------------------------------------- /StackCheckPkg/Test/StackCookieTest/StackCookieTest.c: -------------------------------------------------------------------------------- 1 | /** 2 | 3 | Copyright (c) 2007, Intel Corporation 4 | All rights reserved. This program and the accompanying materials 5 | are licensed and made available under the terms and conditions of the BSD License 6 | which accompanies this distribution. The full text of the license may be found at 7 | http://opensource.org/licenses/bsd-license.php 8 | 9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | 12 | **/ 13 | 14 | #include 15 | 16 | #include 17 | #include 18 | #include 19 | 20 | VOID 21 | TestA ( 22 | IN CHAR16 *Test 23 | ) 24 | { 25 | CHAR16 Buffer[10]; 26 | 27 | StrCpy (Buffer, Test); 28 | } 29 | 30 | EFI_STATUS 31 | EFIAPI 32 | StackCookieTestInitialize ( 33 | IN EFI_HANDLE ImageHandle, 34 | IN EFI_SYSTEM_TABLE *SystemTable 35 | ) 36 | { 37 | TestA (L"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"); 38 | 39 | return EFI_SUCCESS; 40 | } -------------------------------------------------------------------------------- /StackCheckPkg/Test/StackCookieTest/StackCookieTest.inf: -------------------------------------------------------------------------------- 1 | ## @file 2 | # 3 | # Copyright (c) 2010 Intel Corporation. All rights reserved.
4 | # This program and the accompanying materials are 5 | # licensed and made available under the terms and conditions of the BSD License 6 | # which accompanies this distribution. The full text of the license may be found at 7 | # http://opensource.org/licenses/bsd-license.php 8 | # 9 | # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | # 12 | ## 13 | 14 | [Defines] 15 | INF_VERSION = 0x00010005 16 | BASE_NAME = StackCookieTest 17 | FILE_GUID = 661FEA94-94B9-488c-9FED-B4B3BA43DE4F 18 | MODULE_TYPE = UEFI_DRIVER 19 | VERSION_STRING = 1.0 20 | ENTRY_POINT = StackCookieTestInitialize 21 | 22 | [Sources] 23 | StackCookieTest.c 24 | 25 | [Packages] 26 | MdePkg/MdePkg.dec 27 | 28 | [LibraryClasses] 29 | UefiDriverEntryPoint 30 | 31 | [BuildOptions] 32 | MSFT:*_*_*_CC_FLAGS = /Od /GL- /GS 33 | GCC:*_GCC5_*_CC_FLAGS = -O0 -fstack-protector-strong 34 | -------------------------------------------------------------------------------- /StackCheckPkg/Test/StackFrameTest/StackFrameTest.c: -------------------------------------------------------------------------------- 1 | /** 2 | 3 | Copyright (c) 2007, Intel Corporation 4 | All rights reserved. This program and the accompanying materials 5 | are licensed and made available under the terms and conditions of the BSD License 6 | which accompanies this distribution. The full text of the license may be found at 7 | http://opensource.org/licenses/bsd-license.php 8 | 9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | 12 | **/ 13 | 14 | #include 15 | 16 | #include 17 | #include 18 | #include 19 | 20 | VOID 21 | TestA ( 22 | UINTN Index 23 | ) 24 | { 25 | CHAR16 Buffer[10]; 26 | 27 | // NOTE: Some simple buffer overflow may be caught by C4789. 28 | // E.g if Index is an immediate value 29 | 30 | Buffer[Index] = 1; 31 | } 32 | 33 | EFI_STATUS 34 | EFIAPI 35 | StackFrameTestInitialize ( 36 | IN EFI_HANDLE ImageHandle, 37 | IN EFI_SYSTEM_TABLE *SystemTable 38 | ) 39 | { 40 | TestA (10); 41 | 42 | return EFI_SUCCESS; 43 | } -------------------------------------------------------------------------------- /StackCheckPkg/Test/StackFrameTest/StackFrameTest.inf: -------------------------------------------------------------------------------- 1 | ## @file 2 | # 3 | # Copyright (c) 2010 Intel Corporation. All rights reserved.
4 | # This program and the accompanying materials are 5 | # licensed and made available under the terms and conditions of the BSD License 6 | # which accompanies this distribution. The full text of the license may be found at 7 | # http://opensource.org/licenses/bsd-license.php 8 | # 9 | # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | # 12 | ## 13 | 14 | [Defines] 15 | INF_VERSION = 0x00010005 16 | BASE_NAME = StackFrameTest 17 | FILE_GUID = D447F72A-369D-465E-824B-336E8BB1B1D9 18 | MODULE_TYPE = UEFI_DRIVER 19 | VERSION_STRING = 1.0 20 | ENTRY_POINT = StackFrameTestInitialize 21 | 22 | [Sources] 23 | StackFrameTest.c 24 | 25 | [Packages] 26 | MdePkg/MdePkg.dec 27 | 28 | [LibraryClasses] 29 | UefiDriverEntryPoint 30 | 31 | [BuildOptions] 32 | # warning C4789: buffer 'Buffer' of size 20 bytes will be overrun; 2 bytes will be written starting at offset 20 33 | MSFT:*_*_*_CC_FLAGS = /Od /GL- /RTCs 34 | GCC:*_CLANGPDB_*_CC_FLAGS = -O0 -fsanitize=address 35 | -------------------------------------------------------------------------------- /StackCheckPkg/Test/UninitializedVariableTest/UninitializedVariableTest.c: -------------------------------------------------------------------------------- 1 | /** 2 | 3 | Copyright (c) 2007, Intel Corporation 4 | All rights reserved. This program and the accompanying materials 5 | are licensed and made available under the terms and conditions of the BSD License 6 | which accompanies this distribution. The full text of the license may be found at 7 | http://opensource.org/licenses/bsd-license.php 8 | 9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | 12 | **/ 13 | 14 | #include 15 | 16 | #include 17 | #include 18 | #include 19 | 20 | #if defined(_MSC_EXTENSIONS) 21 | //#pragma warning ( once : 4701 ) 22 | //#pragma warning ( once : 4703 ) 23 | #endif 24 | 25 | 26 | UINTN 27 | TestA ( 28 | UINTN Index 29 | ) 30 | { 31 | UINTN Data; 32 | 33 | // NOTE: Some simple unitialization can be caught by C4700 34 | // e.g. without conditional check 35 | 36 | if (Index > 10) { 37 | Data = 0; 38 | } 39 | 40 | Data ++; 41 | 42 | return Data; 43 | } 44 | 45 | EFI_STATUS 46 | EFIAPI 47 | UninitializedVariableTestInitialize ( 48 | IN EFI_HANDLE ImageHandle, 49 | IN EFI_SYSTEM_TABLE *SystemTable 50 | ) 51 | { 52 | TestA (0); 53 | 54 | return EFI_SUCCESS; 55 | } -------------------------------------------------------------------------------- /StackCheckPkg/Test/UninitializedVariableTest/UninitializedVariableTest.inf: -------------------------------------------------------------------------------- 1 | ## @file 2 | # 3 | # Copyright (c) 2010 Intel Corporation. All rights reserved.
4 | # This program and the accompanying materials are 5 | # licensed and made available under the terms and conditions of the BSD License 6 | # which accompanies this distribution. The full text of the license may be found at 7 | # http://opensource.org/licenses/bsd-license.php 8 | # 9 | # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | # 12 | ## 13 | 14 | [Defines] 15 | INF_VERSION = 0x00010005 16 | BASE_NAME = UninitializedVariableTest 17 | FILE_GUID = 752EDD2F-ECC0-4585-837C-B65BBD8542A8 18 | MODULE_TYPE = UEFI_DRIVER 19 | VERSION_STRING = 1.0 20 | ENTRY_POINT = UninitializedVariableTestInitialize 21 | 22 | [Sources] 23 | UninitializedVariableTest.c 24 | 25 | [Packages] 26 | MdePkg/MdePkg.dec 27 | 28 | [LibraryClasses] 29 | UefiDriverEntryPoint 30 | 31 | [BuildOptions] 32 | # warning C4700: uninitialized local variable 'Data' used 33 | # 4701 and 4703 are already disabled by EDKII. Need enable in the code to detect at build time. 34 | MSFT:*_*_*_CC_FLAGS = /Od /GL- /GS /RTCu 35 | # MSan does not support windows platform 36 | GCC:*_CLANGPDB_*_CC_FLAGS = -O0 -Wno-sometimes-uninitialized # -fsanitize=memory 37 | -------------------------------------------------------------------------------- /StackCheckPkg/Test/Variant1Test/Variant1App/Variant1App.inf: -------------------------------------------------------------------------------- 1 | ## @file 2 | # 3 | # Copyright (c) 2016, Intel Corporation. All rights reserved.
4 | # This program and the accompanying materials are licensed and made available under 5 | # the terms and conditions of the BSD License that accompanies this distribution. 6 | # The full text of the license may be found at 7 | # http://opensource.org/licenses/bsd-license.php. 8 | # 9 | # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | # 12 | ## 13 | 14 | [Defines] 15 | INF_VERSION = 0x00010005 16 | BASE_NAME = Variant1App 17 | FILE_GUID = 77C57384-61A2-4F8A-9D3E-5BAA02BCEE87 18 | MODULE_TYPE = UEFI_APPLICATION 19 | VERSION_STRING = 1.0 20 | ENTRY_POINT = Variant1AppEntrypoint 21 | 22 | [Sources] 23 | Variant1App.c 24 | 25 | [Packages] 26 | MdePkg/MdePkg.dec 27 | SideChannelPkg/SideChannelPkg.dec 28 | 29 | [LibraryClasses] 30 | UefiApplicationEntryPoint 31 | BaseLib 32 | DebugLib 33 | UefiLib 34 | BaseMemoryLib 35 | -------------------------------------------------------------------------------- /StackCheckPkg/Test/Variant1Test/Variant1App/spectre.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jyao1/SecurityEx/8ad717380af5c72038fcd0d8d3fb1091b5a31791/StackCheckPkg/Test/Variant1Test/Variant1App/spectre.c -------------------------------------------------------------------------------- /StackCheckPkg/Test/Variant1Test/Variant1Smm/Variant1Smm.inf: -------------------------------------------------------------------------------- 1 | ## @file 2 | # 3 | # Copyright (c) 2016, Intel Corporation. All rights reserved.
4 | # This program and the accompanying materials are licensed and made available under 5 | # the terms and conditions of the BSD License that accompanies this distribution. 6 | # The full text of the license may be found at 7 | # http://opensource.org/licenses/bsd-license.php. 8 | # 9 | # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | # 12 | ## 13 | 14 | [Defines] 15 | INF_VERSION = 0x00010005 16 | BASE_NAME = Variant1Smm 17 | FILE_GUID = A6237046-0A00-4E9F-AF30-B12BF10F8713 18 | MODULE_TYPE = DXE_SMM_DRIVER 19 | VERSION_STRING = 1.0 20 | PI_SPECIFICATION_VERSION = 0x0001000A 21 | ENTRY_POINT = Variant1SmmEntrypoint 22 | 23 | [Sources] 24 | Variant1Smm.c 25 | 26 | [Packages] 27 | MdePkg/MdePkg.dec 28 | SideChannelPkg/SideChannelPkg.dec 29 | 30 | [LibraryClasses] 31 | UefiDriverEntryPoint 32 | BaseLib 33 | DebugLib 34 | SmmServicesTableLib 35 | 36 | [Depex] 37 | gEfiSmmCpuProtocolGuid 38 | -------------------------------------------------------------------------------- /StackCheckPkg/Test/Variant1Test/Variant1Smm/Variant1SmmApp.inf: -------------------------------------------------------------------------------- 1 | ## @file 2 | # 3 | # Copyright (c) 2016, Intel Corporation. All rights reserved.
4 | # This program and the accompanying materials are licensed and made available under 5 | # the terms and conditions of the BSD License that accompanies this distribution. 6 | # The full text of the license may be found at 7 | # http://opensource.org/licenses/bsd-license.php. 8 | # 9 | # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | # 12 | ## 13 | 14 | [Defines] 15 | INF_VERSION = 0x00010005 16 | BASE_NAME = Variant1SmmApp 17 | FILE_GUID = 253FC3DE-39DC-4EEA-81F8-C78E6CD371B7 18 | MODULE_TYPE = UEFI_APPLICATION 19 | VERSION_STRING = 1.0 20 | ENTRY_POINT = Variant1SmmAppEntrypoint 21 | 22 | [Sources] 23 | Variant1SmmApp.c 24 | 25 | [Packages] 26 | MdePkg/MdePkg.dec 27 | MdeModulePkg/MdeModulePkg.dec 28 | SideChannelPkg/SideChannelPkg.dec 29 | 30 | [LibraryClasses] 31 | UefiApplicationEntryPoint 32 | BaseLib 33 | DebugLib 34 | UefiBootServicesTableLib 35 | UefiLib 36 | BaseMemoryLib 37 | 38 | [Guids] 39 | gEdkiiPiSmmCommunicationRegionTableGuid 40 | 41 | [Protocols] 42 | gEfiSmmCommunicationProtocolGuid -------------------------------------------------------------------------------- /StackCheckPkg/Test/Variant1Test/Variant1Smm/Variant1SmmCommBuffer.h: -------------------------------------------------------------------------------- 1 | /** @file 2 | 3 | Copyright (c) 2016, Intel Corporation. All rights reserved.
4 | This program and the accompanying materials 5 | are licensed and made available under the terms and conditions of the BSD License 6 | which accompanies this distribution. The full text of the license may be found at 7 | http://opensource.org/licenses/bsd-license.php 8 | 9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | 12 | **/ 13 | 14 | #ifndef _VARIANT1_SMM_COMM_BUFFER_H_ 15 | #define _VARIANT1_SMM_COMM_BUFFER_H_ 16 | 17 | /// 18 | /// Size of SMM communicate header, without including the payload. 19 | /// 20 | #define SMM_COMMUNICATE_HEADER_SIZE (OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER, Data)) 21 | 22 | #define FUNCTION_GET_SECRET_ADDRESS 1 23 | #define FUNCTION_COMMUNICATION 2 24 | 25 | typedef struct { 26 | UINTN Function; 27 | EFI_STATUS ReturnStatus; 28 | UINT64 Address; 29 | UINT64 Offset; 30 | } SMM_VARIANT1_COMMUNICATE_FUNCTION_HEADER; 31 | 32 | #pragma pack(1) 33 | typedef struct arrays { 34 | UINT64 array1_size; 35 | UINT8 unused1[64]; 36 | UINT8 array1[160]; 37 | UINT8 unused2[64]; 38 | UINT8 array2[256 * 512]; 39 | } VARIANT1_SMM_COMM_BUFFER; 40 | #pragma pack() 41 | 42 | #define VARIANT1_SMM_COMM_GUID \ 43 | {0x19d505a3, 0xe2c, 0x4efb, {0xb1, 0x4f, 0x89, 0x50, 0xc2, 0x9b, 0xa2, 0x96}} 44 | 45 | #endif -------------------------------------------------------------------------------- /UserModePkg/Include/Protocol/UserModeThunk.h: -------------------------------------------------------------------------------- 1 | /** @file 2 | 3 | Copyright (c) 2017, Intel Corporation. All rights reserved.
4 | This program and the accompanying materials 5 | are licensed and made available under the terms and conditions of the BSD License 6 | which accompanies this distribution. The full text of the license may be found at 7 | http://opensource.org/licenses/bsd-license.php. 8 | 9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | 12 | **/ 13 | 14 | #ifndef _USER_MODE_THUNK_H_ 15 | #define _USER_MODE_THUNK_H_ 16 | 17 | #define USER_MODE_THUNK_PROTOCOL_GUID \ 18 | { \ 19 | 0x44109850, 0xc259, 0x4e95, { 0x87, 0x59, 0xcc, 0xd4, 0xf3, 0xd5, 0x24, 0xed } \ 20 | } 21 | 22 | typedef struct _USER_MODE_THUNK_PROTOCOL USER_MODE_THUNK_PROTOCOL; 23 | 24 | typedef 25 | EFI_STATUS 26 | (EFIAPI *USER_MODE_THUNK_ENTER) ( 27 | IN USER_MODE_THUNK_PROTOCOL *This 28 | ); 29 | 30 | typedef 31 | EFI_STATUS 32 | (EFIAPI *USER_MODE_THUNK_EXIT) ( 33 | IN USER_MODE_THUNK_PROTOCOL *This 34 | ); 35 | 36 | typedef 37 | EFI_STATUS 38 | (EFIAPI *USER_MODE_THUNK_FUNCTION) ( 39 | IN UINTN Param1, 40 | IN UINTN Param2 41 | ); 42 | 43 | typedef 44 | EFI_STATUS 45 | (EFIAPI *USER_MODE_THUNK_CALL)( 46 | IN USER_MODE_THUNK_PROTOCOL *This, 47 | IN USER_MODE_THUNK_FUNCTION EntryPoint, 48 | IN UINTN Param1, 49 | IN UINTN Param2, 50 | OUT EFI_STATUS *RetStatus 51 | ); 52 | 53 | struct _USER_MODE_THUNK_PROTOCOL { 54 | USER_MODE_THUNK_ENTER UserModeEnter; 55 | USER_MODE_THUNK_EXIT UserModeExit; 56 | USER_MODE_THUNK_CALL UserModeCall; 57 | }; 58 | 59 | extern EFI_GUID gUserModeThunkProtocolGuid; 60 | 61 | #endif 62 | -------------------------------------------------------------------------------- /UserModePkg/License.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012, Intel Corporation. All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions 5 | are met: 6 | 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above copyright 10 | notice, this list of conditions and the following disclaimer in 11 | the documentation and/or other materials provided with the 12 | distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 15 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 16 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 17 | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 18 | COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 19 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 20 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 24 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 | POSSIBILITY OF SUCH DAMAGE. 26 | -------------------------------------------------------------------------------- /UserModePkg/UserModePkg.dec: -------------------------------------------------------------------------------- 1 | ## @file 2 | # 3 | # Copyright (c) 2020, Intel Corporation. All rights reserved.
4 | # 5 | # This program and the accompanying materials 6 | # are licensed and made available under the terms and conditions of the BSD License 7 | # which accompanies this distribution. The full text of the license may be found at 8 | # http://opensource.org/licenses/bsd-license.php 9 | # 10 | # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 12 | # 13 | ## 14 | 15 | [Defines] 16 | DEC_SPECIFICATION = 0x00010005 17 | PACKAGE_NAME = UserModePkg 18 | PACKAGE_GUID = 06733196-5DB0-4B32-B8AD-69769A17B793 19 | PACKAGE_VERSION = 0.1 20 | 21 | [Includes] 22 | Include 23 | 24 | [Protocols] 25 | gUserModeThunkProtocolGuid = {0x44109850, 0xc259, 0x4e95, { 0x87, 0x59, 0xcc, 0xd4, 0xf3, 0xd5, 0x24, 0xed }} 26 | -------------------------------------------------------------------------------- /UserModePkg/UserModeThunk/Ia32/UserMode.asm: -------------------------------------------------------------------------------- 1 | ;------------------------------------------------------------------------------ 2 | ; 3 | ; Copyright (c) 2017, Intel Corporation. All rights reserved.
4 | ; This program and the accompanying materials 5 | ; are licensed and made available under the terms and conditions of the BSD License 6 | ; which accompanies this distribution. The full text of the license may be found at 7 | ; http://opensource.org/licenses/bsd-license.php. 8 | ; 9 | ; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | ; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | ; 12 | ; Module Name: 13 | ; 14 | ; UserMode.asm 15 | ; 16 | ;------------------------------------------------------------------------------ 17 | 18 | .686P 19 | .MMX 20 | .MODEL FLAT,C 21 | 22 | MSR_IA32_SYSENTER_ESP EQU 175h 23 | 24 | EXTERNDEF AsmUserDs:DWORD 25 | EXTERNDEF AsmSystemDs:DWORD 26 | 27 | .CODE 28 | 29 | AsmUserModeEnter PROC PUBLIC 30 | ; update IOPL 31 | pushfd 32 | pop eax 33 | or eax, 0x3000 ; set IOPL [BIT12~BIT13] to ring 3 34 | push eax 35 | popfd 36 | 37 | ; update RSP 38 | mov ecx, MSR_IA32_SYSENTER_ESP 39 | mov eax, esp 40 | xor edx, edx 41 | wrmsr 42 | 43 | ; prepare enter ring 3 44 | ; jmp $ 45 | mov edx, Ring3 ; RIP for Ring3 46 | mov ecx, esp ; RSP for Ring3 47 | DB 0fh,35h ; SYSEXIT 48 | Ring3: 49 | ; we are in ring 3 now 50 | ; jmp $ 51 | DB 0b8h ; mov eax, USER_DATA_SEGMENT + 3 52 | AsmUserDs DD 00000000h 53 | mov ds, eax 54 | mov es, eax 55 | mov fs, eax 56 | mov gs, eax 57 | 58 | ret 59 | AsmUserModeEnter ENDP 60 | 61 | AsmUserModeExit PROC PUBLIC 62 | ; prepare enter ring 0 63 | ; jmp $ 64 | DB 0fh, 34h ; SYSENTER 65 | jmp $ 66 | AsmUserModeExit ENDP 67 | 68 | AsmSystemModeEnter PROC PUBLIC 69 | DB 0b8h ; mov eax, SYSTEM_DATA_SEGMENT 70 | AsmSystemDs DD 00000000h 71 | mov ds, eax 72 | mov es, eax 73 | mov ss, eax 74 | 75 | ret 76 | AsmSystemModeEnter ENDP 77 | 78 | END 79 | -------------------------------------------------------------------------------- /UserModePkg/UserModeThunk/UserModeThunk.inf: -------------------------------------------------------------------------------- 1 | ## @file 2 | # 3 | # Copyright (c) 2017, Intel Corporation. All rights reserved.
4 | # This program and the accompanying materials 5 | # are licensed and made available under the terms and conditions of the BSD License 6 | # which accompanies this distribution. The full text of the license may be found at 7 | # http://opensource.org/licenses/bsd-license.php. 8 | # 9 | # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | # 12 | ## 13 | 14 | [Defines] 15 | INF_VERSION = 0x00010005 16 | BASE_NAME = UserModeThunk 17 | FILE_GUID = BFB968E2-EAAF-4B2E-8743-6EB9AA162226 18 | MODULE_TYPE = DXE_DRIVER 19 | VERSION_STRING = 1.0 20 | ENTRY_POINT = UserModeThunkEntryPoint 21 | 22 | # 23 | # VALID_ARCHITECTURES = IA32 X64 24 | # 25 | 26 | [Sources] 27 | UserModeThunk.c 28 | 29 | [Sources.Ia32] 30 | Ia32\Context.c 31 | Ia32\UserMode.asm 32 | Ia32\ExceptionHandlerAsm.nasm 33 | 34 | [Sources.x64] 35 | x64\Context.c 36 | x64\UserMode.asm 37 | x64\ExceptionHandlerAsm.nasm 38 | 39 | [Packages] 40 | MdePkg/MdePkg.dec 41 | UefiCpuPkg/UefiCpuPkg.dec 42 | UserModePkg/UserModePkg.dec 43 | 44 | [LibraryClasses] 45 | UefiDriverEntryPoint 46 | BaseMemoryLib 47 | MemoryAllocationLib 48 | DebugLib 49 | 50 | [Protocols] 51 | gUserModeThunkProtocolGuid 52 | gEfiCpuArchProtocolGuid 53 | 54 | [Depex] 55 | gEfiCpuArchProtocolGuid 56 | 57 | -------------------------------------------------------------------------------- /UserModePkg/UserModeThunk/x64/UserMode.asm: -------------------------------------------------------------------------------- 1 | ;------------------------------------------------------------------------------ 2 | ; 3 | ; Copyright (c) 2017, Intel Corporation. All rights reserved.
4 | ; This program and the accompanying materials 5 | ; are licensed and made available under the terms and conditions of the BSD License 6 | ; which accompanies this distribution. The full text of the license may be found at 7 | ; http://opensource.org/licenses/bsd-license.php. 8 | ; 9 | ; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 | ; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 | ; 12 | ; Module Name: 13 | ; 14 | ; UserMode.asm 15 | ; 16 | ;------------------------------------------------------------------------------ 17 | 18 | MSR_IA32_SYSENTER_ESP EQU 175h 19 | 20 | EXTERNDEF AsmUserDs:DWORD 21 | EXTERNDEF AsmSystemDs:DWORD 22 | 23 | .CODE 24 | 25 | AsmUserModeEnter PROC PUBLIC 26 | ; update IOPL 27 | pushfq 28 | pop rax 29 | or rax, 0x3000 ; set IOPL [BIT12~BIT13] to ring 3 30 | push rax 31 | popfq 32 | 33 | ; update RSP 34 | mov ecx, MSR_IA32_SYSENTER_ESP 35 | mov rax, rsp 36 | mov rdx, rax 37 | shr rdx, 0x20 38 | wrmsr 39 | 40 | ; prepare enter ring 3 41 | ; jmp $ 42 | mov rdx, Ring3 ; RIP for Ring3 43 | mov rcx, rsp ; RSP for Ring3 44 | DB 48h 45 | DB 0fh,35h ; SYSEXIT 46 | Ring3: 47 | ; we are in ring 3 now 48 | ; jmp $ 49 | DB 0b8h ; mov eax, USER_DATA_SEGMENT + 3 50 | AsmUserDs DD 00000000h 51 | mov ds, eax 52 | mov es, eax 53 | mov fs, eax 54 | mov gs, eax 55 | 56 | ret 57 | AsmUserModeEnter ENDP 58 | 59 | AsmUserModeExit PROC PUBLIC 60 | ; prepare enter ring 0 61 | ; jmp $ 62 | DB 0fh, 34h ; SYSENTER 63 | jmp $ 64 | AsmUserModeExit ENDP 65 | 66 | AsmSystemModeEnter PROC PUBLIC 67 | DB 0b8h ; mov eax, SYSTEM_DATA_SEGMENT 68 | AsmSystemDs DD 00000000h 69 | mov ds, eax 70 | mov es, eax 71 | mov ss, eax 72 | 73 | ret 74 | AsmSystemModeEnter ENDP 75 | 76 | END 77 | -------------------------------------------------------------------------------- /doc/A_Tour_Beyond_BIOS_Securiy_Enhancement_to_Mitigate_Buffer_Overflow_in_UEFI.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jyao1/SecurityEx/8ad717380af5c72038fcd0d8d3fb1091b5a31791/doc/A_Tour_Beyond_BIOS_Securiy_Enhancement_to_Mitigate_Buffer_Overflow_in_UEFI.pdf --------------------------------------------------------------------------------