CVS commit: src
"Taylor R Campbell" <[email protected]>
| Newsgroups | gmane.os.netbsd.devel.cvs |
|---|---|
| Message-ID | <[email protected]> |
Module Name: src
Committed By: riastradh
Date: Fri Aug 28 12:02:16 UTC 2026
Modified Files:
src/sys/compat/linux32/arch/aarch64: linux32_exec_machdep.c
src/sys/kern: exec_subr.c kern_exec.c
src/tests/kernel: t_signal_and_sp.c
Log Message:
execve(2): Set p_stackbase in execve_runproc, not execve_loadvm.
execve_loadvm must not have side effects on the running process for
two reasons:
1. If execve(2) fails, it has to be able to back out and return to
the calling process. For example, the shell will execute the
first of a series of candidate paths that works when it searches
$PATH, and if one fails, it has to be able to move on to try the
next.
2. The caller may be the _parent_ process -- this is the case when
we're in posix_spawn.
Instead, it must be set in execve_runproc, after we're committed to
the exec and can't back out -- and we're definitely operating on the
process that is executing a new image, not on its parent!
p_stackbase and its assignment in exec_setup_stack, a subroutine of
execve_loadvm, were introduced with the PaX ASLR changes back in 2007
in order to pass the true stack base via AT_STACKBASE in the ELF
auxv, and in order to have getcontext() return the true stack base,
in the face of address space layout randomization.
This change, however, broke the stack base returned by getcontext()
in programs that have tried to exec other programs and failed in
various ways. And made the later introduction of posix_spawn break
the stack base in the _parent_.
To fix this, we set p_stackbase -- under p_lock, to avoid racing with
sysctl_doeproc in another thread -- only in execve_runproc once we're
committed to the exec, but before copyoutargs -> es_copyargs =
elf_copyargs -> elf_populate_auxv needs to read it. (That said,
elf_populate_auxv(..., pack, ...) could just use pack->es_minsaddr
directly anyway, and then we wouldn't have that ordering constraint.)
PR kern/60653: posix_spawn(3) causes incorrect stack base information
To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 \
src/sys/compat/linux32/arch/aarch64/linux32_exec_machdep.c
cvs rdiff -u -r1.92 -r1.93 src/sys/kern/exec_subr.c
cvs rdiff -u -r1.534 -r1.535 src/sys/kern/kern_exec.c
cvs rdiff -u -r1.22 -r1.23 src/tests/kernel/t_signal_and_sp.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.