Commit graph

9 commits

Author SHA1 Message Date
Chao Li
8756401a02 MdePkg: Add LoongArch64 support for StackCheckLib
Added LoongArch64 stack cookie interrupt instance, calling `CpuBreakpoint`
to stop the CPU.

Signed-off-by: Chao Li <lichao@loongson.cn>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
2026-07-07 08:49:21 +00:00
Oliver Smith-Denny
59a6c3a4a7 MdePkg: StackCheckLib: Update __stack_chk_guard for GCC 17
GCC 17 (upcoming release) is updating the type of
__stack_chk_guard from a void * to a uintptr_t.

This is only a type change, not a size change. However,
it does cause the GCC 17 build to fail because of the
type mismatch.

uintptr_t is defined as unsigned long, which is not
a type edk2 defines. It has the same size as UINTN
on a given system, but on 64 bit systems we have the
same type issue because UINTN is defined as unsigned long long,
not unsigned long.

To work around this and avoid defining a new type in edk2,
use the compiler built in __UINTPTR_TYPE__ which is the
underlying definition in GCC.

This is a backwards compatible change with previous versions
of GCC and CLANGDWARF but also fixes the upcoming definition
change for GCC 17.

Signed-off-by: Oliver Smith-Denny <osde@microsoft.com>
2026-05-28 07:37:09 +00:00
Oliver Smith-Denny
abfe5b2869 MdePkg: Remove ARM32 Support from StackCheckLib
edk2 is dropping support for the ARM32 architecture. This
commit removes ARM32 code from StackCheckLib and moves the
AARCH64 files to the top level.

Signed-off-by: Oliver Smith-Denny <osde@microsoft.com>
2025-09-25 22:04:10 +00:00
Ard Biesheuvel
96cf70951f MdePkg/DynamicStackCookieEntryPointLib: Drop execute-in-place versions
SEC, PEI_CORE and PEIM type modules generally execute in place from
memory that is not writable. This means that it is not generally
possible to use an entrypoint implementation that stores a dynamically
generated stack cookie into a global variable. For PEIMs in particular,
there may be other options, such as a DEPEX on the permanent memory PPI,
but the current dynamic implementations of the stack checking library
entrypoints for PEI_CORE and PEIM modules must not be used as-is.

So remove them, and update the readme accordingly.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
2025-02-11 20:25:08 +00:00
Oliver Smith-Denny
e6b6aa90d4 MdePkg: Add Dynamic Stack Cookie Support
Adds dynamic stack cookies in the form of copies of the entry
point libraries that use shared logic to update stack cookies
at runtime.

This relies on RDRAND on IA32/X64 and RNDR on AARCH64 to get a
random number to apply to the stack cookie on module entry point.

This simplifies the logic a platform must do to include stack
check functionality.

Signed-off-by: Oliver Smith-Denny <osde@microsoft.com>
2025-02-07 02:23:11 +00:00
Oliver Smith-Denny
efbf5ed08c MdePkg: Move StackCheckLibStaticInit to StackCheckLib
This commit oves StackCheckLib from a NULL lib to an instance of
StackCheckLib. This requires every entry point to add a library
dependency on StackCheckLib. It also requires every SEC module
to have a dependency on StackCheckLib because there is no
standard SEC entry point.

It allows for greater flexibility for a platform to apply stack
cookies and simplifies DSC logic.

Continuous-integration-options: PatchCheck.ignore-multi-package

Signed-off-by: Oliver Smith-Denny <osde@microsoft.com>
2025-02-07 02:23:11 +00:00
Oliver Smith-Denny
e63cdeebb8 MdePkg: Add StackCheckLib Library Class
StackCheckLib defines the interface between a compiler
and the stack checking code. It is being converted from
a NULL library class to an actual library class to make
it easier to use for a platform and be easier to define
the expected interface with a compiler, so if there is
a compiler change it can be tracked and caught.

Signed-off-by: Oliver Smith-Denny <osde@microsoft.com>
2025-02-07 02:23:11 +00:00
Oliver Smith-Denny
7123940665 MdePkg: MdeLibs.dsc.inc: Introduce CUSTOM_STACK_CHECK_LIB Macro
In order to support a platform overriding StackCheckLibNull
provided by MdeLibs.dsc.inc, the CUSTOM_STACK_CHECK_LIB macro
is introduced. If this macro is defined, MdeLibs.dsc.inc will
not link StackCheckLibNull and it is expected that the platform
will link the version(s) of StackCheckLib that it requires.

The StackCheckLib README is also updated in this patch to
document the new macro and provide additional information.

Signed-off-by: Oliver Smith-Denny <osde@linux.microsoft.com>
2024-10-04 00:57:12 +00:00
Taylor Beebe
5000568969 MdePkg: Create Stack Check Lib
StackCheckLib contains the required functionality for initializing
the stack cookie value, checking the value, and triggering an interrupt
when a mismatch occurs. The stack cookie is a random value placed on the
stack between the stack variables and the return address so that
continuously writing past the stack variables will cause the stack cookie
to be overwritten. Before the function returns, the stack cookie value
will be checked and if there is a mismatch then StackCheckLib handles the
failure.

Because UEFI doesn't use the C runtime libraries provided by MSVC, the
stack check code is written in assembly within this library. GCC and
Clang compilers have built-in support for stack cookie checking, so this
library only handles failures.

Signed-off-by: Oliver Smith-Denny <osde@linux.microsoft.com>
2024-09-13 03:58:46 +00:00