Skip to content

Commit

Permalink
Stack Cookie Changes
Browse files Browse the repository at this point in the history
  • Loading branch information
TaylorBeebe authored and kenlautner committed May 4, 2023
1 parent 3111360 commit 728eb0e
Show file tree
Hide file tree
Showing 16 changed files with 94 additions and 41 deletions.
15 changes: 8 additions & 7 deletions BaseTools/Conf/tools_def.template
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@
# 2.40 - Move GccLto files to a tools path to be more repository layout agnostic
# 2.41 - Can't have comment inline as it breaks concatenation see - # MU_CHANGE - Move GccLto to tools dir for better alignment
# 2.42 - VS2022 toolchain incorrectly defined for ASL
# 2.43 - Enable stack cookies to VS2019 and VS20222 X64 builds via /GS flag
#
#!VERSION=2.42
#!VERSION=2.43

IDENTIFIER = Default TOOL_CHAIN_CONF

Expand Down Expand Up @@ -1767,9 +1768,9 @@ NOOPT_VS2019_IA32_DLINK_FLAGS = /NOLOGO /NODEFAULTLIB /IGNORE:4001 /OPT:REF /O
*_VS2019_X64_DLINK_PATH = DEF(VS2019_BIN_X64)\link.exe
*_VS2019_X64_ASLDLINK_PATH = DEF(VS2019_BIN_X64)\link.exe

DEBUG_VS2019_X64_CC_FLAGS = /nologo /c /WX /GS- /W4 /Gs32768 /D UNICODE /O1b2s /GL /Gy /FIAutoGen.h /EHs-c- /GR- /GF /Z7 /Gw
RELEASE_VS2019_X64_CC_FLAGS = /nologo /c /WX /GS- /W4 /Gs32768 /D UNICODE /O1b2s /GL /Gy /FIAutoGen.h /EHs-c- /GR- /GF /Gw
NOOPT_VS2019_X64_CC_FLAGS = /nologo /c /WX /GS- /W4 /Gs32768 /D UNICODE /Gy /FIAutoGen.h /EHs-c- /GR- /GF /Z7 /Od
DEBUG_VS2019_X64_CC_FLAGS = /nologo /c /WX /GS /W4 /Gs32768 /D UNICODE /O1b2s /GL /Gy /FIAutoGen.h /EHs-c- /GR- /GF /Z7 /Gw
RELEASE_VS2019_X64_CC_FLAGS = /nologo /c /WX /GS /W4 /Gs32768 /D UNICODE /O1b2s /GL /Gy /FIAutoGen.h /EHs-c- /GR- /GF /Gw
NOOPT_VS2019_X64_CC_FLAGS = /nologo /c /WX /GS /W4 /Gs32768 /D UNICODE /Gy /FIAutoGen.h /EHs-c- /GR- /GF /Z7 /Od

DEBUG_VS2019_X64_ASM_FLAGS = /nologo /c /WX /W3 /Cx /Zd /Zi
RELEASE_VS2019_X64_ASM_FLAGS = /nologo /c /WX /W3 /Cx /Zd
Expand Down Expand Up @@ -1926,9 +1927,9 @@ NOOPT_VS2022_IA32_DLINK_FLAGS = /NOLOGO /NODEFAULTLIB /IGNORE:4001 /OPT:REF /O
*_VS2022_X64_DLINK_PATH = DEF(VS2022_BIN_X64)\link.exe
*_VS2022_X64_ASLDLINK_PATH = DEF(VS2022_BIN_X64)\link.exe

DEBUG_VS2022_X64_CC_FLAGS = /nologo /c /WX /GS- /W4 /Gs32768 /D UNICODE /O1b2s /GL /Gy /FIAutoGen.h /EHs-c- /GR- /GF /Z7 /Gw
RELEASE_VS2022_X64_CC_FLAGS = /nologo /c /WX /GS- /W4 /Gs32768 /D UNICODE /O1b2s /GL /Gy /FIAutoGen.h /EHs-c- /GR- /GF /Gw
NOOPT_VS2022_X64_CC_FLAGS = /nologo /c /WX /GS- /W4 /Gs32768 /D UNICODE /Gy /FIAutoGen.h /EHs-c- /GR- /GF /Z7 /Od
DEBUG_VS2022_X64_CC_FLAGS = /nologo /c /WX /GS /W4 /Gs32768 /D UNICODE /O1b2s /GL /Gy /FIAutoGen.h /EHs-c- /GR- /GF /Z7 /Gw
RELEASE_VS2022_X64_CC_FLAGS = /nologo /c /WX /GS /W4 /Gs32768 /D UNICODE /O1b2s /GL /Gy /FIAutoGen.h /EHs-c- /GR- /GF /Gw
NOOPT_VS2022_X64_CC_FLAGS = /nologo /c /WX /GS /W4 /Gs32768 /D UNICODE /Gy /FIAutoGen.h /EHs-c- /GR- /GF /Z7 /Od

DEBUG_VS2022_X64_ASM_FLAGS = /nologo /c /WX /W3 /Cx /Zd /Zi
RELEASE_VS2022_X64_ASM_FLAGS = /nologo /c /WX /W3 /Cx /Zd
Expand Down
5 changes: 3 additions & 2 deletions CryptoPkg/CryptoPkg.dsc
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,12 @@
[LibraryClasses.common.DXE_DRIVER, LibraryClasses.common.UEFI_APPLICATION]
RngLib|MdePkg/Library/DxeRngLib/DxeRngLib.inf

!if $(TOOLCHAIN) == VS2017 or $(TOOLCHAIN) == VS2019 or $(TOOLCHAIN) == VS2022 ## MU_CHANGE
!if $(TOOL_CHAIN_TAG) == VS2019 or $(TOOL_CHAIN_TAG) == VS2022 ## MU_CHANGE
[LibraryClasses.IA32]
NULL|MdePkg/Library/VsIntrinsicLib/VsIntrinsicLib.inf
ReportStatusCodeLib|MdePkg/Library/BaseReportStatusCodeLibNull/BaseReportStatusCodeLibNull.inf
[LibraryClasses.X64, LibraryClasses.IA32]
[LibraryClasses.X64]
# Provide StackCookie support lib so that we can link to /GS exports for VS builds
NULL|MdePkg/Library/BaseBinSecurityLibRng/BaseBinSecurityLibRng.inf
BaseBinSecurityLib|MdePkg/Library/BaseBinSecurityLibRng/BaseBinSecurityLibRng.inf
[LibraryClasses.X64.DXE_CORE, LibraryClasses.X64.UEFI_DRIVER, LibraryClasses.X64.DXE_DRIVER, LibraryClasses.X64.UEFI_APPLICATION]
Expand Down
1 change: 1 addition & 0 deletions MdeModulePkg/Core/PiSmmCore/PiSmmCore.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
#include <Library/PerformanceLib.h>
#include <Library/HobLib.h>
#include <Library/SmmMemLib.h>
#include <Library/BaseBinSecurityLib.h> // MS_CHANGE_?
#include <Library/MmMemoryProtectionHobLib.h> // MU_CHANGE

#include "PiSmmCorePrivateData.h"
Expand Down
8 changes: 3 additions & 5 deletions MdeModulePkg/MdeModulePkg.dsc
Original file line number Diff line number Diff line change
Expand Up @@ -134,16 +134,14 @@
##MSCHANGE Begin
[LibraryClasses.common]
BaseBinSecurityLib|MdePkg/Library/BaseBinSecurityLibNull/BaseBinSecurityLibNull.inf
!if $(TOOL_CHAIN_TAG) == VS2017 or $(TOOL_CHAIN_TAG) == VS2015 or $(TOOL_CHAIN_TAG) == VS2019
!if $(TARGET) == DEBUG
[LibraryClasses.X64, LibraryClasses.IA32]
#if debug is enabled provide StackCookie support lib so that we can link to /GS exports on MSVC
!if $(TOOL_CHAIN_TAG) == VS2019 or $(TOOL_CHAIN_TAG) == VS2022
[LibraryClasses.X64]
# Provide StackCookie support lib so that we can link to /GS exports for VS builds
RngLib|MdePkg/Library/BaseRngLib/BaseRngLib.inf
[LibraryClasses.X64]
BaseBinSecurityLib|MdePkg/Library/BaseBinSecurityLibRng/BaseBinSecurityLibRng.inf
NULL|MdePkg/Library/BaseBinSecurityLibRng/BaseBinSecurityLibRng.inf
!endif
!endif
##MSCHANGE End

[LibraryClasses.EBC.PEIM]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,7 @@
DebugLib
BaseLib
RngLib
PcdLib

[FixedPcd]
gEfiMdePkgTokenSpaceGuid.PcdStackCookieExceptionVector
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ __security_check_cookie PROC PUBLIC
ret

__security_check_cookie_Failure:
int 3
int FixedPcdGet8 (PcdStackCookieExceptionVector)
ret
__security_check_cookie ENDP

Expand Down
5 changes: 5 additions & 0 deletions MdePkg/MdePkg.dec
Original file line number Diff line number Diff line change
Expand Up @@ -2255,6 +2255,11 @@
# @Prompt Speculation Barrier Type.
gEfiMdePkgTokenSpaceGuid.PcdSpeculationBarrierType|0x01|UINT8|0x30001018

## MU_CHANGE START: Add Stack Cookie Exception Vector
## This PCD specifies the interrupt vector for stack cookie check failures
gEfiMdePkgTokenSpaceGuid.PcdStackCookieExceptionVector|0x42|UINT8|0x30001019
## MU_CHANGE END

[PcdsFixedAtBuild,PcdsPatchableInModule]
## Indicates the maximum length of unicode string used in the following
# BaseLib functions: StrLen(), StrSize(), StrCmp(), StrnCmp(), StrCpy(), StrnCpy()<BR><BR>
Expand Down
12 changes: 11 additions & 1 deletion MdePkg/MdePkg.dsc
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@

[LibraryClasses]
SafeIntLib|MdePkg/Library/BaseSafeIntLib/BaseSafeIntLib.inf
# MU_CHANGE START
BaseBinSecurityLib|MdePkg/Library/BaseBinSecurityLibNull/BaseBinSecurityLibNull.inf
!if $(TOOL_CHAIN_TAG) == VS2019 or $(TOOL_CHAIN_TAG) == VS2022
[LibraryClasses.X64]
# Provide StackCookie support lib so that we can link to /GS exports for VS builds
RngLib|MdePkg/Library/BaseRngLib/BaseRngLib.inf
BaseBinSecurityLib|MdePkg/Library/BaseBinSecurityLibRng/BaseBinSecurityLibRng.inf
NULL|MdePkg/Library/BaseBinSecurityLibRng/BaseBinSecurityLibRng.inf
!endif
# MU_CHANGE END

[Components]
MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.inf
Expand Down Expand Up @@ -179,7 +189,7 @@
MdePkg/Library/SmmMemLib/SmmMemLib.inf
MdePkg/Library/SmmIoLib/SmmIoLib.inf
##MSCHANGE Begin
!if $(TOOLCHAIN) == VS2017 or $(TOOLCHAIN) == VS2019
!if $(TOOL_CHAIN_TAG) == VS2017 or $(TOOL_CHAIN_TAG) == VS2015 or $(TOOL_CHAIN_TAG) == VS2019 or $(TOOL_CHAIN_TAG) == VS2022
MdePkg/Library/BaseBinSecurityLibNull/BaseBinSecurityLibNull.inf
MdePkg/Library/BaseBinSecurityLibRng/BaseBinSecurityLibRng.inf
!endif
Expand Down
6 changes: 2 additions & 4 deletions NetworkPkg/NetworkPkg.dsc
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,12 @@
IntrinsicLib|CryptoPkg/Library/IntrinsicLib/IntrinsicLib.inf

##MSCHANGE Begin
!if $(TARGET) == DEBUG
!if $(TOOL_CHAIN_TAG) == VS2017 or $(TOOL_CHAIN_TAG) == VS2015 or $(TOOL_CHAIN_TAG) == VS2019
!if $(TOOL_CHAIN_TAG) == VS2019 or $(TOOL_CHAIN_TAG) == VS2022
[LibraryClasses.X64]
#if debug is enabled provide StackCookie support lib so that we can link to /GS exports
# Provide StackCookie support lib so that we can link to /GS exports for VS builds
RngLib|MdePkg/Library/BaseRngLib/BaseRngLib.inf
NULL|MdePkg/Library/BaseBinSecurityLibRng/BaseBinSecurityLibRng.inf
!endif
!endif
##MSCHANGE End

[LibraryClasses.common.UEFI_DRIVER]
Expand Down
8 changes: 3 additions & 5 deletions NetworkPkg/SharedNetworking/SharedNetworkPkg.dsc
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,11 @@
TlsLib|CryptoPkg/Library/BaseCryptLibOnProtocolPpi/SmmCryptLib.inf

##MSCHANGE Begin
!if $(TARGET) == DEBUG
#!if $(TOOL_CHAIN_TAG) == VS2017 or $(TOOL_CHAIN_TAG) == VS2015 or $(TOOL_CHAIN_TAG) == VS2019
!if $(TOOL_CHAIN_TAG) == VS2019 or $(TOOL_CHAIN_TAG) == VS2022
[LibraryClasses.X64]
#if debug is enabled provide StackCookie support lib so that we can link to /GS exports
# Provide StackCookie support lib so that we can link to /GS exports for VS builds
NULL|MdePkg/Library/BaseBinSecurityLibRng/BaseBinSecurityLibRng.inf
BaseBinSecurityLib|MdePkg/Library/BaseBinSecurityLibRng/BaseBinSecurityLibRng.inf
#!endif
!endif
##MSCHANGE End
[LibraryClasses.DXE_RUNTIME_DRIVER, LibraryClasses.DXE_CORE]
Expand Down Expand Up @@ -128,7 +126,7 @@
# This library provides the instrinsic functions generated by a given compiler.
# [LibraryClasses.ARM] and NULL mean link this library into all ARM images.
#
!if $(TOOL_CHAIN_TAG) != VS2017 or $(TOOL_CHAIN_TAG) != VS2015 or $(TOOL_CHAIN_TAG) != VS2019 ## MS_CHANGE only applies to ARM compiler
!if $(TOOL_CHAIN_TAG) != VS2017 or $(TOOL_CHAIN_TAG) != VS2015 or $(TOOL_CHAIN_TAG) != VS2019 or $(TOOL_CHAIN_TAG) != VS2022 ## MS_CHANGE only applies to ARM compiler
# NULL|ArmPkg/Library/CompilerIntrinsicsLib/CompilerIntrinsicsLib.inf # MU_CHANGE
NULL|MdePkg/Library/CompilerIntrinsicsLib/ArmCompilerIntrinsicsLib.inf # MU_CHANGE
BaseMemoryLib|MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf # while building with MSVC, we can't process the s files
Expand Down
8 changes: 3 additions & 5 deletions PcAtChipsetPkg/PcAtChipsetPkg.dsc
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,12 @@
VariablePolicyHelperLib|MdeModulePkg/Library/VariablePolicyHelperLib/VariablePolicyHelperLib.inf # MU_CHANGE

## MS_CHANGE Begin
[LibraryClasses.X64, LibraryClasses.IA32]
!if $(TARGET) == DEBUG
!if $(TOOL_CHAIN_TAG) == VS2017 or $(TOOL_CHAIN_TAG) == VS2015 or $(TOOL_CHAIN_TAG) == VS2019
#if debug is enabled provide StackCookie support lib so that we can link to /GS exports
[LibraryClasses.X64]
!if $(TOOL_CHAIN_TAG) == VS2019 or $(TOOL_CHAIN_TAG) == VS2022
# Provide StackCookie support lib so that we can link to /GS exports for VS builds
RngLib|MdePkg/Library/BaseRngLib/BaseRngLib.inf
NULL|MdePkg/Library/BaseBinSecurityLibRng/BaseBinSecurityLibRng.inf
!endif
!endif
## MS_CHANGE End

[Components]
Expand Down
17 changes: 16 additions & 1 deletion PolicyServicePkg/PolicyServicePkg.dsc
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,22 @@
DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf
UefiRuntimeServicesTableLib|MdePkg/Library/UefiRuntimeServicesTableLib/UefiRuntimeServicesTableLib.inf
PeiServicesLib|MdePkg/Library/PeiServicesLib/PeiServicesLib.inf
PeiServicesTablePointerLib|MdePkg/Library/PeiServicesTablePointerLibIdt/PeiServicesTablePointerLibIdt.inf

## MU_CHANGE START
[LibraryClasses.common]
BaseBinSecurityLib|MdePkg/Library/BaseBinSecurityLibNull/BaseBinSecurityLibNull.inf
!if $(TOOL_CHAIN_TAG) == VS2019 or $(TOOL_CHAIN_TAG) == VS2022
[LibraryClasses.X64]
# Provide StackCookie support lib so that we can link to /GS exports for VS builds
RngLib|MdePkg/Library/BaseRngLib/BaseRngLib.inf
[LibraryClasses.X64]
BaseBinSecurityLib|MdePkg/Library/BaseBinSecurityLibRng/BaseBinSecurityLibRng.inf
NULL|MdePkg/Library/BaseBinSecurityLibRng/BaseBinSecurityLibRng.inf
!endif
## MU_CHANGE END

[LibraryClasses.ARM, LibraryClasses.AARCH64]
NULL|MdePkg/Library/BaseStackCheckLib/BaseStackCheckLib.inf

[LibraryClasses.common.PEIM]
MemoryAllocationLib|MdePkg/Library/PeiMemoryAllocationLib/PeiMemoryAllocationLib.inf
Expand Down
8 changes: 3 additions & 5 deletions ShellPkg/ShellPkg.dsc
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,14 @@
## MU_CHANGE Begin
[LibraryClasses.common]
BaseBinSecurityLib|MdePkg/Library/BaseBinSecurityLibNull/BaseBinSecurityLibNull.inf
!if $(TOOL_CHAIN_TAG) == VS2017 or $(TOOL_CHAIN_TAG) == VS2015 or $(TOOL_CHAIN_TAG) == VS2019
!if $(TARGET) == DEBUG
[LibraryClasses.X64, LibraryClasses.IA32]
#if debug is enabled provide StackCookie support lib so that we can link to /GS exports on MSVC
!if $(TOOL_CHAIN_TAG) == VS2019 or $(TOOL_CHAIN_TAG) == VS2022
[LibraryClasses.X64]
# Provide StackCookie support lib so that we can link to /GS exports for VS builds
RngLib|MdePkg/Library/BaseRngLib/BaseRngLib.inf
[LibraryClasses.X64]
BaseBinSecurityLib|MdePkg/Library/BaseBinSecurityLibRng/BaseBinSecurityLibRng.inf
NULL|MdePkg/Library/BaseBinSecurityLibRng/BaseBinSecurityLibRng.inf
!endif
!endif
## MU_CHANGE End

[LibraryClasses.ARM,LibraryClasses.AARCH64]
Expand Down
13 changes: 13 additions & 0 deletions StandaloneMmPkg/StandaloneMmPkg.dsc
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,19 @@
VariableMmDependency|StandaloneMmPkg/Library/VariableMmDependency/VariableMmDependency.inf
MmuLib|MdePkg/Library/BaseMmuLibNull/BaseMmuLibNull.inf # MU_CHANGE

## MU_CHANGE START
[LibraryClasses.common]
BaseBinSecurityLib|MdePkg/Library/BaseBinSecurityLibNull/BaseBinSecurityLibNull.inf
!if $(TOOL_CHAIN_TAG) == VS2019 or $(TOOL_CHAIN_TAG) == VS2022
[LibraryClasses.X64]
# Provide StackCookie support lib so that we can link to /GS exports for VS builds
RngLib|MdePkg/Library/BaseRngLib/BaseRngLib.inf
[LibraryClasses.X64]
BaseBinSecurityLib|MdePkg/Library/BaseBinSecurityLibRng/BaseBinSecurityLibRng.inf
NULL|MdePkg/Library/BaseBinSecurityLibRng/BaseBinSecurityLibRng.inf
!endif
## MU_CHANGE END

[LibraryClasses.X64] # MU_CHANGE
StandaloneMmCoreEntryPoint|StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/StandaloneMmCoreEntryPoint.inf # MU_CHANGE

Expand Down
11 changes: 6 additions & 5 deletions UefiCpuPkg/UefiCpuPkg.dsc
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,16 @@
##MSCHANGE Begin
DxeMemoryProtectionHobLib|MdeModulePkg/Library/MemoryProtectionHobLibNull/DxeMemoryProtectionHobLibNull.inf
MmMemoryProtectionHobLib|MdeModulePkg/Library/MemoryProtectionHobLibNull/MmMemoryProtectionHobLibNull.inf
BaseBinSecurityLib|MdePkg/Library/BaseBinSecurityLibNull/BaseBinSecurityLibNull.inf
[LibraryClasses.X64, LibraryClasses.IA32]
!if $(TARGET) == DEBUG
!if $(TOOL_CHAIN_TAG) == VS2017 or $(TOOL_CHAIN_TAG) == VS2015 or $(TOOL_CHAIN_TAG) == VS2019
#if debug is enabled provide StackCookie support lib so that we can link to /GS exports
HwResetSystemLib|MdeModulePkg/Library/BaseResetSystemLibNull/BaseResetSystemLibNull.inf
!if $(TOOL_CHAIN_TAG) == VS2019 or $(TOOL_CHAIN_TAG) == VS2022
[LibraryClasses.X64]
# Provide StackCookie support lib so that we can link to /GS exports for VS builds
RngLib|MdePkg/Library/BaseRngLib/BaseRngLib.inf
BaseBinSecurityLib|MdePkg/Library/BaseBinSecurityLibRng/BaseBinSecurityLibRng.inf
NULL|MdePkg/Library/BaseBinSecurityLibRng/BaseBinSecurityLibRng.inf
!endif
!endif
HwResetSystemLib|MdeModulePkg/Library/BaseResetSystemLibNull/BaseResetSystemLibNull.inf
##MSCHANGE End

[LibraryClasses.common.SEC]
Expand Down
13 changes: 13 additions & 0 deletions UnitTestFrameworkPkg/UnitTestFrameworkPkg.dsc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,19 @@
[PcdsPatchableInModule]
gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask|0x17

## MU_CHANGE START
[LibraryClasses.common]
BaseBinSecurityLib|MdePkg/Library/BaseBinSecurityLibNull/BaseBinSecurityLibNull.inf
!if $(TOOL_CHAIN_TAG) == VS2019 or $(TOOL_CHAIN_TAG) == VS2022
[LibraryClasses.X64]
# Provide StackCookie support lib so that we can link to /GS exports for VS builds
RngLib|MdePkg/Library/BaseRngLib/BaseRngLib.inf
[LibraryClasses.X64]
BaseBinSecurityLib|MdePkg/Library/BaseBinSecurityLibRng/BaseBinSecurityLibRng.inf
NULL|MdePkg/Library/BaseBinSecurityLibRng/BaseBinSecurityLibRng.inf
!endif
## MU_CHANGE END

[Components]
UnitTestFrameworkPkg/Library/UnitTestLib/UnitTestLib.inf
UnitTestFrameworkPkg/Library/UnitTestPersistenceLibNull/UnitTestPersistenceLibNull.inf
Expand Down

0 comments on commit 728eb0e

Please sign in to comment.