diff mbox series

[1/4] linux-user: Disallow setting newsp for fork

Message ID 20180730201553.32423-2-richard.henderson@linaro.org
State Superseded
Headers show
Series linux-user/sparc: Fixes for clone | expand

Commit Message

Richard Henderson July 30, 2018, 8:15 p.m. UTC
Or really, just clone devolving into fork.  This should not ever happen
in practice.  We do want to reserve calling cpu_clone_regs for the case
in which we are actually performing a clone.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>

---
 linux-user/syscall.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

-- 
2.17.1

Comments

Alex Bennée July 31, 2018, 10:54 a.m. UTC | #1
Richard Henderson <richard.henderson@linaro.org> writes:

> Or really, just clone devolving into fork.  This should not ever happen

> in practice.  We do want to reserve calling cpu_clone_regs for the case

> in which we are actually performing a clone.

>

> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>


Reviewed-by: Alex Bennée <alex.bennee@linaro.org>


> ---

>  linux-user/syscall.c | 7 +++++--

>  1 file changed, 5 insertions(+), 2 deletions(-)

>

> diff --git a/linux-user/syscall.c b/linux-user/syscall.c

> index dfc851cc35..5bf8d13de7 100644

> --- a/linux-user/syscall.c

> +++ b/linux-user/syscall.c

> @@ -6502,10 +6502,14 @@ static int do_fork(CPUArchState *env, unsigned int flags, abi_ulong newsp,

>          pthread_mutex_destroy(&info.mutex);

>          pthread_mutex_unlock(&clone_lock);

>      } else {

> -        /* if no CLONE_VM, we consider it is a fork */

> +        /* If no CLONE_VM, we consider it is a fork.  */

>          if (flags & CLONE_INVALID_FORK_FLAGS) {

>              return -TARGET_EINVAL;

>          }

> +        /* As a fork, setting a new sp does not make sense.  */

> +        if (newsp) {

> +            return -TARGET_EINVAL;

> +        }

>

>          /* We can't support custom termination signals */

>          if ((flags & CSIGNAL) != TARGET_SIGCHLD) {

> @@ -6520,7 +6524,6 @@ static int do_fork(CPUArchState *env, unsigned int flags, abi_ulong newsp,

>          ret = fork();

>          if (ret == 0) {

>              /* Child Process.  */

> -            cpu_clone_regs(env, newsp);

>              fork_end(1);

>              /* There is a race condition here.  The parent process could

>                 theoretically read the TID in the child process before the child



--
Alex Bennée
diff mbox series

Patch

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index dfc851cc35..5bf8d13de7 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -6502,10 +6502,14 @@  static int do_fork(CPUArchState *env, unsigned int flags, abi_ulong newsp,
         pthread_mutex_destroy(&info.mutex);
         pthread_mutex_unlock(&clone_lock);
     } else {
-        /* if no CLONE_VM, we consider it is a fork */
+        /* If no CLONE_VM, we consider it is a fork.  */
         if (flags & CLONE_INVALID_FORK_FLAGS) {
             return -TARGET_EINVAL;
         }
+        /* As a fork, setting a new sp does not make sense.  */
+        if (newsp) {
+            return -TARGET_EINVAL;
+        }
 
         /* We can't support custom termination signals */
         if ((flags & CSIGNAL) != TARGET_SIGCHLD) {
@@ -6520,7 +6524,6 @@  static int do_fork(CPUArchState *env, unsigned int flags, abi_ulong newsp,
         ret = fork();
         if (ret == 0) {
             /* Child Process.  */
-            cpu_clone_regs(env, newsp);
             fork_end(1);
             /* There is a race condition here.  The parent process could
                theoretically read the TID in the child process before the child