forked from microsoft/mu_basecore
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Stack Cookie Support for IA32, ARM, and AARCH64
Description This update replaces StackCheckLib with StackCheckLibStaticInit and StackCheckLibDynamicInit. The new libraries have GCC support for ARM, AARCH64, IA32 and X64 builds. The libraries have MSVC support for IA32 and X64 builds. StackCheckLibStaticInit does not have a library constructor and should be used whenever the stack cookie value cannot be updated during driver execution (i.e. when the stack cookie is not in a writable or no RNG library is available). StackCheckLibDynamicInit has a library constructor and should be used whenever the stack cookie value can be updated at runtime (i.e. for DXE modules and shadowed PEIMs). This update also removes the stack cookie library definitions from MdeLibs.dsc.inc due to GCC build issues when the instanced versions are used during CI builds. The instanced versions will need to be explicitly added to the platform DSC files, and this is acceptable because platforms will likely want to mix and match the static and dynamic versions of the library for each module type. - [x] Impacts functionality? - **Functionality** - Does the change ultimately impact how firmware functions? - Examples: Add a new library, publish a new PPI, update an algorithm, ... - [x] Impacts security? - **Security** - Does the change have a direct security impact on an application, flow, or firmware? - Examples: Crypto algorithm change, buffer overflow fix, parameter validation improvement, ... - [x] Breaking change? - **Breaking change** - Will anyone consuming this change experience a break in build or boot behavior? - Examples: Add a new library class, move a module to a different repo, call a function in a new library class in a pre-existing module, ... - [ ] Includes tests? - **Tests** - Does the change include any explicit test code? - Examples: Unit tests, integration tests, robot tests, ... - [ ] Includes documentation? - **Documentation** - Does the change contain explicit documentation additions outside direct code modifications (and comments)? - Examples: Update readme file, add feature readme file, link to documentation on an a separate Web page, ... How This Was Tested Tested on a Q35 GCC and MSVC builds, and on an SBSA GCC build by purposefully performing a stack overflow. Integration Instructions Platforms will need to explicitly declare the StackCheckLib and StackCheckFailureLib instances for their platforms. EXAMPLE: ``` StackCheckFailureLib|MdePkg/Library/StackCheckFailureLibNull/StackCheckFailureLibNull.inf [LibraryClasses.common.SEC, LibraryClasses.common.PEI_CORE] NULL|MdePkg/Library/StackCheckLibNull/StackCheckLibNull.inf [LibraryClasses.common.PEIM, LibraryClasses.common.MM_CORE_STANDALONE, LibraryClasses.common.MM_STANDALONE] NULL|MdePkg/Library/StackCheckLib/StackCheckLibStaticInit.inf [LibraryClasses.common.DXE_CORE, LibraryClasses.common.SMM_CORE, LibraryClasses.common.DXE_SMM_DRIVER, LibraryClasses.common.DXE_DRIVER, LibraryClasses.common.DXE_RUNTIME_DRIVER, LibraryClasses.common.DXE_SAL_DRIVER, LibraryClasses.common.UEFI_DRIVER, LibraryClasses.common.UEFI_APPLICATION] NULL|MdePkg/Library/StackCheckLib/StackCheckLibDynamicInit.inf ```
- Loading branch information
1 parent
9222414
commit 2ffdb64
Showing
23 changed files
with
230 additions
and
138 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
MdePkg/Library/StackCheckLib/AArch64/StackCookieInterrupt.S
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
//------------------------------------------------------------------------------ | ||
// AArch64/StackCookieInterrupt.S | ||
// | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// SPDX-License-Identifier: BSD-2-Clause-Patent | ||
//------------------------------------------------------------------------------ | ||
|
||
.text | ||
|
||
//------------------------------------------------------------------------------ | ||
// Calls an interrupt using the vector specified by PcdStackCookieExceptionVector | ||
// | ||
// VOID | ||
// TriggerStackCookieInterrupt ( | ||
// VOID | ||
// ); | ||
//------------------------------------------------------------------------------ | ||
.global ASM_PFX(TriggerStackCookieInterrupt) | ||
ASM_PFX(TriggerStackCookieInterrupt): | ||
smc FixedPcdGet8 (PcdStackCookieExceptionVector) | ||
ret |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
//------------------------------------------------------------------------------ | ||
// Arm/StackCookieInterrupt.S | ||
// | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// SPDX-License-Identifier: BSD-2-Clause-Patent | ||
//------------------------------------------------------------------------------ | ||
|
||
.text | ||
|
||
//------------------------------------------------------------------------------ | ||
// Calls an interrupt using the vector specified by PcdStackCookieExceptionVector | ||
// | ||
// VOID | ||
// TriggerStackCookieInterrupt ( | ||
// VOID | ||
// ); | ||
//------------------------------------------------------------------------------ | ||
.global ASM_PFX(TriggerStackCookieInterrupt) | ||
ASM_PFX(TriggerStackCookieInterrupt): | ||
swi FixedPcdGet8 (PcdStackCookieExceptionVector) | ||
bx lr |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
MdePkg/Library/StackCheckLib/IA32/StackCookieInterrupt.nasm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
;------------------------------------------------------------------------------ | ||
; IA32/StackCookieInterrupt.nasm | ||
; | ||
; Copyright (c) Microsoft Corporation. All rights reserved. | ||
; SPDX-License-Identifier: BSD-2-Clause-Patent | ||
;------------------------------------------------------------------------------ | ||
|
||
DEFAULT REL | ||
SECTION .text | ||
|
||
;------------------------------------------------------------------------------ | ||
; Checks the stack cookie value against __security_cookie and calls the | ||
; stack cookie failure handler if there is a mismatch. | ||
; | ||
; VOID | ||
; TriggerStackCookieInterrupt ( | ||
; VOID | ||
; ); | ||
;------------------------------------------------------------------------------ | ||
global ASM_PFX(TriggerStackCookieInterrupt) | ||
ASM_PFX(TriggerStackCookieInterrupt): | ||
int FixedPcdGet8 (PcdStackCookieExceptionVector) | ||
ret |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/** @file | ||
Provides the required functionality for handling stack | ||
cookie check failures. | ||
Copyright (c) Microsoft Corporation. All rights reserved. | ||
SPDX-License-Identifier: BSD-2-Clause-Patent | ||
**/ | ||
|
||
#include <Base.h> | ||
|
||
#include <Library/BaseLib.h> | ||
#include <Library/DebugLib.h> | ||
|
||
/** | ||
Calls an interrupt using the vector specified by PcdStackCookieExceptionVector | ||
**/ | ||
VOID | ||
TriggerStackCookieInterrupt ( | ||
VOID | ||
); | ||
|
||
#if defined (__GNUC__) || defined (__clang__) | ||
|
||
VOID *__stack_chk_guard = (VOID *)(UINTN)STACK_COOKIE_VALUE; | ||
|
||
VOID | ||
__stack_chk_fail ( | ||
VOID | ||
) | ||
{ | ||
TriggerStackCookieInterrupt (); | ||
} | ||
|
||
#elif defined (_MSC_VER) | ||
VOID *__security_cookie = (VOID *)(UINTN)STACK_COOKIE_VALUE; | ||
|
||
NORETURN VOID __cdecl | ||
__report_rangecheckfailure ( | ||
VOID | ||
) | ||
{ | ||
CpuDeadLoop (); | ||
} | ||
|
||
NORETURN VOID __cdecl | ||
__GSHandlerCheck ( | ||
VOID | ||
) | ||
{ | ||
CpuDeadLoop (); | ||
} | ||
|
||
VOID | ||
StackCheckFailure ( | ||
VOID *ActualCookieValue | ||
) | ||
{ | ||
TriggerStackCookieInterrupt (); | ||
} | ||
|
||
#endif |
14 changes: 5 additions & 9 deletions
14
MdePkg/Library/StackCheckLib/StackCheckLib.c → .../StackCheckLib/StackCheckLibDynamicInit.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.