Skip to content

Commit 8de17cd

Browse files
riastradhriastradh
authored andcommitted
mips: Make sure stack is aligned on exec.
The only caller of setregs, sys/kern/kern_exec.c execve_runproc, already guarantees STACK_ALIGNBYTES alignment, so let's assert it but out of paranoia also clear the bits anyway just in case for non- DIAGNOSTIC builds. Based on a patch by rin@. PR kern/59327: user stack pointer is not aligned properly
1 parent d9cfd12 commit 8de17cd

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

sys/arch/mips/mips/mips_machdep.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $NetBSD: mips_machdep.c,v 1.307 2025/03/16 15:34:59 riastradh Exp $ */
1+
/* $NetBSD: mips_machdep.c,v 1.308 2025/04/24 23:55:18 riastradh Exp $ */
22

33
/*
44
* Copyright 2002 Wasabi Systems, Inc.
@@ -111,7 +111,7 @@
111111
*/
112112

113113
#include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
114-
__KERNEL_RCSID(0, "$NetBSD: mips_machdep.c,v 1.307 2025/03/16 15:34:59 riastradh Exp $");
114+
__KERNEL_RCSID(0, "$NetBSD: mips_machdep.c,v 1.308 2025/04/24 23:55:18 riastradh Exp $");
115115

116116
#define __INTR_PRIVATE
117117
#include "opt_cputype.h"
@@ -1697,8 +1697,10 @@ setregs(struct lwp *l, struct exec_package *pack, vaddr_t stack)
16971697
struct trapframe * const tf = l->l_md.md_utf;
16981698
struct proc * const p = l->l_proc;
16991699

1700+
KASSERTMSG((stack & STACK_ALIGNBYTES) == 0, "stack=%"PRIxVADDR, stack);
1701+
17001702
memset(tf, 0, sizeof(*tf));
1701-
tf->tf_regs[_R_SP] = (intptr_t)stack;
1703+
tf->tf_regs[_R_SP] = (intptr_t)stack & ~STACK_ALIGNBYTES;
17021704
tf->tf_regs[_R_PC] = (intptr_t)pack->ep_entry & ~3;
17031705
tf->tf_regs[_R_T9] = (intptr_t)pack->ep_entry & ~3; /* abicall requirement */
17041706
tf->tf_regs[_R_SR] = PSL_USERSET;

0 commit comments

Comments
 (0)