svn commit: r338337 - in head/stand/efi: boot1 loader/arch/arm64

Andrew Turner andrew at FreeBSD.org
Mon Aug 27 11:14:50 UTC 2018


Author: andrew
Date: Mon Aug 27 11:14:49 2018
New Revision: 338337
URL: https://svnweb.freebsd.org/changeset/base/338337

Log:
  Ensure we have a large enough stack for the lua loader
  
  Lua has a few places where it allocates a large buffer on the stack. This
  is normally fine, except there are a few places where there can be multiple
  frames with this buffer. This can cause a stack overflow on some arm64 SoCs.
  
  Fix this by allocating our own stack in loader.efi large enough for these
  objects. The required size has been found by tracing how the stack pointer
  changes in a virtual machine and found to be no larger than 50kB. A
  larger stack is allocated to reduce the likelihood of overflow from future
  changes.
  
  Reviewed by:	kevans
  Approved by:	re (kib)
  Differential Revision:	https://reviews.freebsd.org/D16886

Modified:
  head/stand/efi/boot1/Makefile
  head/stand/efi/loader/arch/arm64/start.S

Modified: head/stand/efi/boot1/Makefile
==============================================================================
--- head/stand/efi/boot1/Makefile	Mon Aug 27 10:08:27 2018	(r338336)
+++ head/stand/efi/boot1/Makefile	Mon Aug 27 11:14:49 2018	(r338337)
@@ -6,6 +6,7 @@ PROG=		boot1.sym
 INTERNALPROG=
 WARNS?=		6
 
+CFLAGS+=	-DEFI_BOOT1
 # We implement a slightly non-standard %S in that it always takes a
 # CHAR16 that's common in UEFI-land instead of a wchar_t. This only
 # seems to matter on arm64 where wchar_t defaults to an int instead

Modified: head/stand/efi/loader/arch/arm64/start.S
==============================================================================
--- head/stand/efi/loader/arch/arm64/start.S	Mon Aug 27 10:08:27 2018	(r338336)
+++ head/stand/efi/loader/arch/arm64/start.S	Mon Aug 27 11:14:49 2018	(r338337)
@@ -160,6 +160,23 @@ _start:
 
 	ldp	x0, x1, [sp], #16
 
+#ifndef EFI_BOOT1
+	/*
+	 * Load the stack to use. The default stack may be too small for
+	 * the lua loader.
+	 */
+	adr	x2, initstack_end
+	mov	sp, x2
+#endif
+
 	bl	efi_main
 
 1:	b	1b
+
+#ifndef EFI_BOOT1
+.bss
+	.align	4
+initstack:
+	.space	(64 * 1024)
+initstack_end:
+#endif


More information about the svn-src-head mailing list