From patchwork Fri May 27 13:00:17 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Riku Voipio X-Patchwork-Id: 9138361 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id DFD1060467 for ; Fri, 27 May 2016 13:28:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D0A5327CB1 for ; Fri, 27 May 2016 13:28:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C51D628159; Fri, 27 May 2016 13:28:15 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, FSL_HELO_HOME, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 432C827CB1 for ; Fri, 27 May 2016 13:28:15 +0000 (UTC) Received: from localhost ([::1]:45824 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b6HoE-0008Qo-8l for patchwork-qemu-devel@patchwork.kernel.org; Fri, 27 May 2016 09:28:14 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37498) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b6HO4-0007nb-H3 for qemu-devel@nongnu.org; Fri, 27 May 2016 09:01:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b6HNy-0001Hy-Qx for qemu-devel@nongnu.org; Fri, 27 May 2016 09:01:12 -0400 Received: from mail-lb0-x230.google.com ([2a00:1450:4010:c04::230]:36548) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b6HNy-0001HW-JT for qemu-devel@nongnu.org; Fri, 27 May 2016 09:01:06 -0400 Received: by mail-lb0-x230.google.com with SMTP id h1so31609399lbj.3 for ; Fri, 27 May 2016 06:01:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Tbei6IG8h5I924NP3mK+3E9bICEU7FWrBVLc8Y85LqI=; b=NvirBzLEAYBj/KsbXNOd4rCs+FQ9sPuBZ8onS0QeuVPogZ3Dnxz1ytFELpwEOymGE1 Lah5gV+CDWDUxOuU+XX/PlzGKv3US2sTexfEUviKfYC4nlCeaLiVH9P67aQgNUzapTZY 7xa0qtAGAtkCCQkjjxJ65Vrh1UoNsZmyUI3Gg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Tbei6IG8h5I924NP3mK+3E9bICEU7FWrBVLc8Y85LqI=; b=PElZI5iO/7HMp2yH3h7CkkaNYV0CwTUj10X9T/8cfObfjEHn7XQh9qfdYDvRnQHSX1 3VHbWiTAf8+d4Tk/gWOLte6Iz5lHKi5U5M4AfzKCxKCXZLlIqQdjunWg3Nt56GPR1uKo ibTrTyfPIljAxFftn1sux/Dc7IfzOPj4ALzP8ezcUrscygTojH961tGS9tC8aQUkEXCV vVP1rUcjnT7DuRpD9+FBqtSxGdEzW2IuFH0J1eOknI63tvJuqbO2q1LwVP9oELbJB86+ r+7OCjP9Mn/318gJ0EdNkiMIi48+rtWVBg/Poq/+R9K37EPr5EVaPuPr2I/Fq46jOeca TNbQ== X-Gm-Message-State: ALyK8tJjpwT/Tz48RDfbkU4n6a+wxfk18m/mmB9zk7CKNPacIoqMG6wYQ3gGMi3kWCMPs8F2 X-Received: by 10.112.167.9 with SMTP id zk9mr4423844lbb.140.1464354065667; Fri, 27 May 2016 06:01:05 -0700 (PDT) Received: from beaming.home (91-157-168-132.elisa-laajakaista.fi. [91.157.168.132]) by smtp.gmail.com with ESMTPSA id n16sm2281066lfg.31.2016.05.27.06.01.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 27 May 2016 06:01:04 -0700 (PDT) From: riku.voipio@linaro.org To: qemu-devel@nongnu.org Date: Fri, 27 May 2016 16:00:17 +0300 Message-Id: X-Mailer: git-send-email 2.1.4 In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:4010:c04::230 Subject: [Qemu-devel] [PULL v2 26/38] linux-user: Use safe_syscall for execve syscall X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Timothy E Baldwin Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Timothy E Baldwin Wrap execve() in the safe-syscall handling. Although execve() is not an interruptible syscall, it is a special case: if we allow a signal to happen before we make the host$ syscall then we will 'lose' it, because at the point of execve the process leaves QEMU's control. So we use the safe syscall wrapper to ensure that we either take the signal as a guest signal, or else it does not happen before the execve completes and makes it the other program's problem. The practical upshot is that without this SIGTERM could fail to terminate the process. Signed-off-by: Timothy Edward Baldwin Message-id: 1441497448-32489-25-git-send-email-T.E.Baldwin99@members.leeds.ac.uk [PMM: expanded commit message to explain in more detail why this is needed, and add comment about it too] Reviewed-by: Peter Maydell Signed-off-by: Peter Maydell Signed-off-by: Riku Voipio --- linux-user/syscall.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index d9f4695..dea827f 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -703,6 +703,7 @@ safe_syscall4(pid_t, wait4, pid_t, pid, int *, status, int, options, \ struct rusage *, rusage) safe_syscall5(int, waitid, idtype_t, idtype, id_t, id, siginfo_t *, infop, \ int, options, struct rusage *, rusage) +safe_syscall3(int, execve, const char *, filename, char **, argv, char **, envp) static inline int host_to_target_sock_type(int host_type) { @@ -6179,7 +6180,17 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, if (!(p = lock_user_string(arg1))) goto execve_efault; - ret = get_errno(execve(p, argp, envp)); + /* Although execve() is not an interruptible syscall it is + * a special case where we must use the safe_syscall wrapper: + * if we allow a signal to happen before we make the host + * syscall then we will 'lose' it, because at the point of + * execve the process leaves QEMU's control. So we use the + * safe syscall wrapper to ensure that we either take the + * signal as a guest signal, or else it does not happen + * before the execve completes and makes it the other + * program's problem. + */ + ret = get_errno(safe_execve(p, argp, envp)); unlock_user(p, arg1, 0); goto execve_end;