Skip to content

Commit

Permalink
Update all DSC files, update null lib, update comments
Browse files Browse the repository at this point in the history
  • Loading branch information
TaylorBeebe committed Nov 3, 2023
1 parent 7ddeddc commit db58249
Show file tree
Hide file tree
Showing 22 changed files with 127 additions and 180 deletions.
10 changes: 6 additions & 4 deletions BaseTools/Source/Python/AutoGen/GenC.py
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,7 @@
${FunctionCall}${END}
}
"""),

# MU_CHANGE [BEGIN]: Add StackCookieSupport marker for stack cookie support.
'PEI' : TemplateString("""
${BEGIN}${FunctionPrototype}${END}
Expand Down Expand Up @@ -743,7 +743,7 @@
${FunctionCall}${END}
}
"""),

# MU_CHANGE [END]: Add StackCookieSupport marker for stack cookie support.
'MM' : TemplateString("""
${BEGIN}${FunctionPrototype}${END}
Expand Down Expand Up @@ -1361,13 +1361,14 @@ def CreateLibraryConstructorCode(Info, AutoGenC, AutoGenH):
ConstructorCallingList = []
else:
ConstructorCallingList = [str(ConstructorCallingString)]

# MU_CHANGE [BEGIN]: Add StackCookieSupport marker for stack cookie support.
Dict = {
'Type' : 'Constructor',
'FunctionPrototype' : ConstructorPrototypeList,
'FunctionCall' : ConstructorCallingList,
"StackCookieSupport": "#ifdef __GNUC__\n__attribute__ ((no_stack_protector))\n#else\n__declspec(safebuffers)\n#endif"
}
# MU_CHANGE [END]: Add StackCookieSupport marker for stack cookie support.
if Info.IsLibrary:
AutoGenH.Append("${BEGIN}${FunctionPrototype}${END}", Dict)
else:
Expand Down Expand Up @@ -1425,13 +1426,14 @@ def CreateLibraryDestructorCode(Info, AutoGenC, AutoGenH):
DestructorCallingList = []
else:
DestructorCallingList = [str(DestructorCallingString)]

# MU_CHANGE [BEGIN]: Add StackCookieSupport marker for stack cookie support.
Dict = {
'Type' : 'Destructor',
'FunctionPrototype' : DestructorPrototypeList,
'FunctionCall' : DestructorCallingList,
"StackCookieSupport": ""
}
# MU_CHANGE [END]: Add StackCookieSupport marker for stack cookie support.
if Info.IsLibrary:
AutoGenH.Append("${BEGIN}${FunctionPrototype}${END}", Dict)
else:
Expand Down
11 changes: 6 additions & 5 deletions CryptoPkg/CryptoPkg.dsc
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@

##MSCHANGE Begin
FltUsedLib|MdePkg/Library/FltUsedLib/FltUsedLib.inf
BaseBinSecurityLibRng|MdePkg/Library/BaseBinSecurityLibNull/BaseBinSecurityLibNull.inf
UnitTestLib|UnitTestFrameworkPkg/Library/UnitTestLib/UnitTestLib.inf
UnitTestPersistenceLib|UnitTestFrameworkPkg/Library/UnitTestPersistenceLibNull/UnitTestPersistenceLibNull.inf
UnitTestBootLib|UnitTestFrameworkPkg/Library/UnitTestBootLibNull/UnitTestBootLibNull.inf
Expand All @@ -78,16 +77,18 @@
[LibraryClasses.IA32]
NULL|MdePkg/Library/VsIntrinsicLib/VsIntrinsicLib.inf
ReportStatusCodeLib|MdePkg/Library/BaseReportStatusCodeLibNull/BaseReportStatusCodeLibNull.inf
[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]
# this is currently X64 only because MSVC doesn't support BaseMemoryLibOptDxe for AARCH64
BaseMemoryLib|MdePkg/Library/BaseMemoryLibOptDxe/BaseMemoryLibOptDxe.inf
!endif ##MSCHANGE
# MU_CHANGE [END]

# MU_CHANGE [BEGIN] - Add Stack Cookie Support
[LibraryClasses.X64]
NULL|MdePkg/Library/StackCheckLib/StackCheckLib.inf
StackCheckFailureLib|MdePkg/Library/StackCheckFailureLibNull/StackCheckFailureLibNull.inf
# MU_CHANGE [END] - Add Stack Cookie Support

[LibraryClasses.ARM, LibraryClasses.AARCH64]

#ArmLib|ArmPkg/Library/ArmLib/ArmBaseLib.inf ## MU_CHANGE
Expand Down
15 changes: 4 additions & 11 deletions MdeModulePkg/MdeModulePkg.dsc
Original file line number Diff line number Diff line change
Expand Up @@ -132,18 +132,11 @@

# MU_CHANGE END

##MSCHANGE Begin
[LibraryClasses.common]
BaseBinSecurityLib|MdePkg/Library/BaseBinSecurityLibNull/BaseBinSecurityLibNull.inf
!if $(TOOL_CHAIN_TAG) == VS2019 or $(TOOL_CHAIN_TAG) == VS2022
# MU_CHANGE [BEGIN] - Add Stack Cookie Support
[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
##MSCHANGE End
NULL|MdePkg/Library/StackCheckLib/StackCheckLib.inf
StackCheckFailureLib|MdePkg/Library/StackCheckFailureLibNull/StackCheckFailureLibNull.inf
# MU_CHANGE [END] - Add Stack Cookie Support

[LibraryClasses.EBC.PEIM]
IoLib|MdePkg/Library/PeiIoLibCpuIo/PeiIoLibCpuIo.inf
Expand Down
1 change: 0 additions & 1 deletion MdeModulePkg/Test/MdeModulePkgHostTest.dsc
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@
DxeServicesLib|MdePkg/Library/DxeServicesLib/DxeServicesLib.inf
DebugAgentLib|MdeModulePkg/Library/DebugAgentLibNull/DebugAgentLibNull.inf
CpuExceptionHandlerLib|MdeModulePkg/Library/CpuExceptionHandlerLibNull/CpuExceptionHandlerLibNull.inf
BaseBinSecurityLib|MdePkg/Library/BaseBinSecurityLibNull/BaseBinSecurityLibNull.inf
UefiRuntimeServicesTableLib|MdePkg/Library/UefiRuntimeServicesTableLib/UefiRuntimeServicesTableLib.inf
MemoryBinOverrideLib|MdeModulePkg/Library/MemoryBinOverrideLibNull/MemoryBinOverrideLibNull.inf # MU_CHANGE

Expand Down
18 changes: 6 additions & 12 deletions MdePkg/Library/StackCheckLib/IA32/StackCheckFunctionsMsvc.nasm
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
;------------------------------------------------------------------------------
; IA32/StackCheckFunctionsMsvc.asm
; IA32/StackCheckFunctionsMsvc.nasm
;------------------------------------------------------------------------------

DEFAULT REL
Expand All @@ -9,21 +9,15 @@ extern ASM_PFX(__security_cookie)
extern ASM_PFX(StackCheckFailure)
extern ASM_PFX(CpuDeadLoop)

;------------------------------------------------------------------------------
; VOID
; EFIAPI
; __report_rangecheckfailure (VOID);
;------------------------------------------------------------------------------
; Called when a buffer check fails. This functionality is dependent on MSVC
; C runtime libraries and so is unsupported in UEFI.
global ASM_PFX(__report_rangecheckfailure)
ASM_PFX(__report_rangecheckfailure):
call ASM_PFX(CpuDeadLoop)
ret

;------------------------------------------------------------------------------
; VOID
; EFIAPI
; __GSHandlerCheck (VOID);
;------------------------------------------------------------------------------
; The GS handler is for checking the stack cookie during SEH or
; EH exceptions and is unsupported in UEFI.
global ASM_PFX(__GSHandlerCheck)
ASM_PFX(__GSHandlerCheck):
call ASM_PFX(CpuDeadLoop)
Expand All @@ -32,7 +26,7 @@ ASM_PFX(__GSHandlerCheck):
;------------------------------------------------------------------------------
; Checks the stack cookie value against __security_cookie and calls the
; stack cookie failure handler if there is a mismatch.
;------------------------------------------------------------------------------
;
; VOID
; EFIAPI
; __security_check_cookie (
Expand Down
4 changes: 4 additions & 0 deletions MdePkg/Library/StackCheckLib/StackCheckFunctionsGcc.nasm
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
;------------------------------------------------------------------------------
; StackCheckFunctionsGcc.nasm
;------------------------------------------------------------------------------
DEFAULT REL
SECTION .text

extern ASM_PFX(StackCheckFailure)

; Called when a stack cookie check fails.
global ASM_PFX(__stack_chk_fail)
ASM_PFX(__stack_chk_fail):
call StackCheckFailure
Expand Down
18 changes: 6 additions & 12 deletions MdePkg/Library/StackCheckLib/X64/StackCheckFunctionsMsvc.nasm
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
;------------------------------------------------------------------------------
; X64/StackCheckFunctionsMsvc.asm
; X64/StackCheckFunctionsMsvc.nasm
;------------------------------------------------------------------------------

DEFAULT REL
Expand All @@ -9,21 +9,15 @@ extern ASM_PFX(StackCheckFailure)
extern ASM_PFX(__security_cookie)
extern ASM_PFX(CpuDeadLoop)

;------------------------------------------------------------------------------
; VOID
; EFIAPI
; __report_rangecheckfailure (VOID);
;------------------------------------------------------------------------------
; Called when a buffer check fails. This functionality is dependent on MSVC
; C runtime libraries and so is unsupported in UEFI.
global ASM_PFX(__report_rangecheckfailure)
ASM_PFX(__report_rangecheckfailure):
call ASM_PFX(CpuDeadLoop)
ret

;------------------------------------------------------------------------------
; VOID
; EFIAPI
; __GSHandlerCheck (VOID);
;------------------------------------------------------------------------------
; The GS handler is for checking the stack cookie during SEH or
; EH exceptions and is unsupported in UEFI.
global ASM_PFX(__GSHandlerCheck)
ASM_PFX(__GSHandlerCheck):
call ASM_PFX(CpuDeadLoop)
Expand All @@ -33,7 +27,7 @@ ASM_PFX(__GSHandlerCheck):
;------------------------------------------------------------------------------
; Checks the stack cookie value against __security_cookie and calls the
; stack cookie failure handler if there is a mismatch.
;------------------------------------------------------------------------------
;
; VOID
; EFIAPI
; __security_check_cookie (
Expand Down
4 changes: 4 additions & 0 deletions MdePkg/Library/StackCheckLibNull/StackCheckFunctionsGcc.nasm
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
;------------------------------------------------------------------------------
; StackCheckFunctionsGcc.nasm
;------------------------------------------------------------------------------
DEFAULT REL
SECTION .text

; Called when a stack cookie check fails.
global ASM_PFX(__stack_chk_fail)
ASM_PFX(__stack_chk_fail):
ret
44 changes: 0 additions & 44 deletions MdePkg/Library/StackCheckLibNull/StackCheckFunctionsMsvc.asm

This file was deleted.

30 changes: 30 additions & 0 deletions MdePkg/Library/StackCheckLibNull/StackCheckFunctionsMsvc.nasm
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
;------------------------------------------------------------------------------
; StackCheckFunctionsMsvc.nasm
;------------------------------------------------------------------------------
DEFAULT REL
SECTION .text

; Called when a buffer check fails. This functionality is dependent on MSVC
; C runtime libraries and so is unsupported in UEFI.
global ASM_PFX(__report_rangecheckfailure)
ASM_PFX(__report_rangecheckfailure):
ret

; The GS handler is for checking the stack cookie during SEH or
; EH exceptions and is unsupported in UEFI.
global ASM_PFX(__GSHandlerCheck)
ASM_PFX(__GSHandlerCheck):
ret

;------------------------------------------------------------------------------
; Checks the stack cookie value against __security_cookie and calls the
; stack cookie failure handler if there is a mismatch.
;
; VOID
; EFIAPI
; __security_check_cookie (
; IN UINTN CheckValue);
;------------------------------------------------------------------------------
global ASM_PFX(__security_check_cookie)
ASM_PFX(__security_check_cookie):
ret
3 changes: 1 addition & 2 deletions MdePkg/Library/StackCheckLibNull/StackCheckLibNull.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/** @file
Provides the required functionality for initializing and
checking the stack cookie.
Defines the stack cookie variable for GCC, Clang and MSVC compilers.
Copyright (c) Microsoft Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent
Expand Down
11 changes: 8 additions & 3 deletions MdePkg/Library/StackCheckLibNull/StackCheckLibNull.inf
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## @file
# Provides the required functionality for initializing and
# checking the stack cookie.
# Null library instance for StackCheckLib which can be included
# when a build needs to include stack check functions but does
# not want to generate stack check failures.
#
# Copyright (c) Microsoft Corporation. All rights reserved.
# SPDX-License-Identifier: BSD-2-Clause-Patent
Expand All @@ -17,7 +18,11 @@
[Sources]
StackCheckLibNull.c
StackCheckFunctionsGcc.nasm | GCC
StackCheckFunctionsVs.asm | MSFT
StackCheckFunctionsMsvc.nasm | MSFT

[Packages]
MdePkg/MdePkg.dec

[BuildOptions]
GCC:*_*_*_CC_FLAGS = -fno-lto
MSFT:*_*_*_CC_FLAGS = /GL-
10 changes: 6 additions & 4 deletions MdePkg/MdePkg.dec
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,12 @@
# All combinations of Unicode and ASCII strings are supported.
##
PrintLib|Include/Library/PrintLib.h
## MSCHANGE BEGIN
## @libraryclass Provides and interface to initialize security cookies
BaseBinSecurityLib|Include/Library/BaseBinSecurityLib.h
## MSCHANGE END

## MU_CHANGE [BEGIN]
## @libraryclass Provides a hook called when a stack cookie check fails.
StackCheckFailureLib|Include/Library/StackCheckFailureLib.h
## MU_CHANGE [END]

## @libraryclass Provides an ordered collection data structure.
OrderedCollectionLib|Include/Library/OrderedCollectionLib.h

Expand Down
25 changes: 11 additions & 14 deletions MdePkg/MdePkg.dsc
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,13 @@

[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

# MU_CHANGE [BEGIN] - Add Stack Cookie Support
[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
NULL|MdePkg/Library/StackCheckLib/StackCheckLib.inf
StackCheckFailureLib|MdePkg/Library/StackCheckFailureLibNull/StackCheckFailureLibNull.inf
# MU_CHANGE [END] - Add Stack Cookie Support

[Components]
MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.inf
Expand Down Expand Up @@ -190,18 +187,18 @@
MdePkg/Library/BaseS3StallLib/BaseS3StallLib.inf
MdePkg/Library/SmmMemLib/SmmMemLib.inf
MdePkg/Library/SmmIoLib/SmmIoLib.inf
##MSCHANGE Begin
!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
##MSCHANGE End
MdePkg/Library/SmmPciExpressLib/SmmPciExpressLib.inf
MdePkg/Library/SmiHandlerProfileLibNull/SmiHandlerProfileLibNull.inf
MdePkg/Library/MmServicesTableLib/MmServicesTableLib.inf
MdePkg/Library/MmUnblockMemoryLib/MmUnblockMemoryLibNull.inf
MdePkg/Library/TdxLib/TdxLib.inf

# MU_CHANGE [BEGIN] - Stack Cookie Support
[Components.X64]
MdePkg/Library/StackCheckLib/StackCheckLib.inf
MdePkg/Library/StackCheckFailureLibNull/StackCheckFailureLibNull.inf
# MU_CHANGE [END] - Add Stack Cookie Support



# MS_CHANGE Begin
Expand Down
Loading

0 comments on commit db58249

Please sign in to comment.