]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/commit
Don't let cpu_set_syscall_retval() clobber exec_setregs().
authored <ed@FreeBSD.org>
Fri, 24 Nov 2017 07:35:08 +0000 (07:35 +0000)
committered <ed@FreeBSD.org>
Fri, 24 Nov 2017 07:35:08 +0000 (07:35 +0000)
commit9b06c6070c5c2a454f1e1ae3a3fedad9f8f1ebc4
tree132c23d4fb0ad6600d9d96a98a811ca45b693eb9
parent291ce17bc80d960492595c2b9c13c287b6353062
Don't let cpu_set_syscall_retval() clobber exec_setregs().

Upon successful completion, the execve() system call invokes
exec_setregs() to initialize the registers of the initial thread of the
newly executed process. What is weird is that when execve() returns, it
still goes through the normal system call return path, clobbering the
registers with the system call's return value (td->td_retval).

Though this doesn't seem to be problematic for x86 most of the times (as
the value of eax/rax doesn't matter upon startup), this can be pretty
frustrating for architectures where function argument and return
registers overlap (e.g., ARM). On these systems, exec_setregs() also
needs to initialize td_retval.

Even worse are architectures where cpu_set_syscall_retval() sets
registers to values not derived from td_retval. On these architectures,
there is no way cpu_set_syscall_retval() can set registers to the way it
wants them to be upon the start of execution.

To get rid of this madness, let sys_execve() return EJUSTRETURN. This
will cause cpu_set_syscall_retval() to leave registers intact. This
makes process execution easier to understand. It also eliminates the
difference between execution of the initial process and successive ones.
The initial call to sys_execve() is not performed through a system call
context.

Reviewed by: kib, jhibbits
Differential Revision: https://reviews.freebsd.org/D13180
13 files changed:
sys/amd64/amd64/machdep.c
sys/amd64/ia32/ia32_signal.c
sys/amd64/linux32/linux32_sysvec.c
sys/arm/cloudabi32/cloudabi32_sysvec.c
sys/arm64/arm64/machdep.c
sys/arm64/cloudabi64/cloudabi64_sysvec.c
sys/compat/linux/linux_emul.c
sys/i386/i386/machdep.c
sys/kern/init_main.c
sys/kern/kern_exec.c
sys/powerpc/powerpc/exec_machdep.c
sys/riscv/riscv/machdep.c
sys/sparc64/sparc64/machdep.c