]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[efi] Ensure NUL byte is at lowest address within stack cookie 119/head
authorMichael Brown <mcb30@ipxe.org>
Thu, 9 Jul 2020 13:20:53 +0000 (14:20 +0100)
committerMichael Brown <mcb30@ipxe.org>
Thu, 9 Jul 2020 13:20:53 +0000 (14:20 +0100)
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 <pete.beck@ioactive.com>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/interface/efi/efi_init.c

index 284c39b358f5da47b45b542bae9695a2a3b1d5df..e1041a5ec52ca049f66dbe5a3a6cb07175a42a83 100644 (file)
@@ -21,6 +21,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
 
 #include <string.h>
 #include <errno.h>
+#include <endian.h>
 #include <ipxe/init.h>
 #include <ipxe/rotate.h>
 #include <ipxe/efi/efi.h>
@@ -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;
 }