From b6eecb182e07a82bae2a5f8c28dadb1bea409090 Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Thu, 9 Jul 2020 14:20:53 +0100 Subject: [efi] Ensure NUL byte is at lowest address within stack cookie The NUL byte included within the stack cookie to act as a string terminator should be placed at the lowest byte address within the stack cookie, in order to avoid potentially including the stack cookie value within an accidentally unterminated string. Suggested-by: Pete Beck Signed-off-by: Michael Brown --- src/interface/efi/efi_init.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/interface/efi/efi_init.c b/src/interface/efi/efi_init.c index 284c39b..e1041a5 100644 --- a/src/interface/efi/efi_init.c +++ b/src/interface/efi/efi_init.c @@ -21,6 +21,7 @@ FILE_LICENCE ( GPL2_OR_LATER ); #include #include +#include #include #include #include @@ -128,6 +129,13 @@ efi_stack_cookie ( EFI_HANDLE handle ) { */ cookie <<= 8; + /* Ensure that the NUL byte is placed at the bottom of the + * stack cookie, to avoid potential disclosure via an + * unterminated string. + */ + if ( __BYTE_ORDER == __BIG_ENDIAN ) + cookie >>= 8; + return cookie; } -- cgit v1.1