Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 24 Jul 2023 22:50:11 GMT
From:      Mark Johnston <markj@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: 789df254cc9e - main - amd64: Use a larger boot stack
Message-ID:  <202307242250.36OMoBKk081290@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by markj:

URL: https://cgit.FreeBSD.org/src/commit/?id=789df254cc9e20c860ccc149b94dd1f92843ec9a

commit 789df254cc9e20c860ccc149b94dd1f92843ec9a
Author:     Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2023-07-24 22:47:42 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2023-07-24 22:49:36 +0000

    amd64: Use a larger boot stack
    
    With sanitizers enabled, it becomes possible to overflow the stack when
    only a single page is used.  Follow arm64's example and use the default
    kernel stack size instead.  This is a bit wasteful, but without a guard
    page, overflow merely corrupts adjacent .bss entries and is thus
    difficult to debug.
    
    Note, with a GENERIC kernel we already consume over half of the
    available boot stack space, see the review for an example.
    
    Reviewed by:    kib
    Reported by:    Jenkins
    MFC after:      2 weeks
    Sponsored by:   The FreeBSD Foundation
    Differential Revision:  https://reviews.freebsd.org/D41166
---
 sys/amd64/amd64/genassym.c | 1 +
 sys/amd64/amd64/locore.S   | 4 ++--
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/sys/amd64/amd64/genassym.c b/sys/amd64/amd64/genassym.c
index feb3c7f503ce..4c17561b6e39 100644
--- a/sys/amd64/amd64/genassym.c
+++ b/sys/amd64/amd64/genassym.c
@@ -116,6 +116,7 @@ ASSYM(KERNBASE, KERNBASE);
 ASSYM(KERNLOAD, KERNLOAD);
 ASSYM(DMAP_MIN_ADDRESS, DMAP_MIN_ADDRESS);
 ASSYM(DMAP_MAX_ADDRESS, DMAP_MAX_ADDRESS);
+ASSYM(KSTACK_PAGES, KSTACK_PAGES);
 
 ASSYM(PCB_R15, offsetof(struct pcb, pcb_r15));
 ASSYM(PCB_R14, offsetof(struct pcb, pcb_r14));
diff --git a/sys/amd64/amd64/locore.S b/sys/amd64/amd64/locore.S
index f034a25c9b1b..41386756021e 100644
--- a/sys/amd64/amd64/locore.S
+++ b/sys/amd64/amd64/locore.S
@@ -48,7 +48,7 @@
 	.set	dmapbase,DMAP_MIN_ADDRESS
 	.set	dmapend,DMAP_MAX_ADDRESS
 
-#define	BOOTSTACK_SIZE	4096
+#define	BOOTSTACK_SIZE	(PAGE_SIZE * KSTACK_PAGES)
 
 	.text
 /**********************************************************************
@@ -148,7 +148,7 @@ ENTRY(la57_trampoline_gdt)
 ENTRY(la57_trampoline_end)
 
 	.bss
-	ALIGN_DATA			/* just to be sure */
+	.p2align PAGE_SHIFT
 	.globl	bootstack
 	.space	BOOTSTACK_SIZE		/* space for bootstack - temporary stack */
 bootstack:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202307242250.36OMoBKk081290>