From patchwork Wed Jun 8 13:30:01 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Riku Voipio X-Patchwork-Id: 69637 Delivered-To: patch@linaro.org Received: by 10.140.106.246 with SMTP id e109csp2498473qgf; Wed, 8 Jun 2016 06:33:40 -0700 (PDT) X-Received: by 10.140.43.166 with SMTP id e35mr4599361qga.72.1465392819796; Wed, 08 Jun 2016 06:33:39 -0700 (PDT) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id m2si685434qkc.42.2016.06.08.06.33.39 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 08 Jun 2016 06:33:39 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:57016 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bAdc3-0005g5-5b for patch@linaro.org; Wed, 08 Jun 2016 09:33:39 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37073) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bAdZU-0004Na-Ut for qemu-devel@nongnu.org; Wed, 08 Jun 2016 09:31:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bAdZO-0005mU-Eo for qemu-devel@nongnu.org; Wed, 08 Jun 2016 09:30:59 -0400 Received: from mail-lf0-x22b.google.com ([2a00:1450:4010:c07::22b]:35608) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bAdZO-0005lQ-2v for qemu-devel@nongnu.org; Wed, 08 Jun 2016 09:30:54 -0400 Received: by mail-lf0-x22b.google.com with SMTP id u74so5850868lff.2 for ; Wed, 08 Jun 2016 06:30:51 -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=3SfS5f4rD4ViHMGkZuxbATr8Cd6VNPBLCAyS0bz1eT4=; b=ZyDL+Rm0xwd0FA4B4FfLvCPoDDw/uoZdI9pFoyP7AvU3xdvlMVh5+IDqrfQ3JybYPP w626tCVDk4EjR82K9T9q9yT8XjNGvGFJxnc3+150xQGH1UuXnTN8kmNYGpGOIHdSDoWx aLFMWayWpqjK5clG+ZuDsn9qkruGGLsFPBHMU= 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=3SfS5f4rD4ViHMGkZuxbATr8Cd6VNPBLCAyS0bz1eT4=; b=Kq/6YBGtTN+doNhrGp3JCbMy8Binh7lSR1rvLkOBHO8HrBh8+tY6opHUArypKPN8Z4 9PVwcF0iM9L1bNDv03iQC4W0bm/b6LnS++hkXlWeEj1PFfl3jwgh1MQKko8Vq1WxcWrO yiqFaQ0q5BwLLjYEeBWG0Jv2d3Ho/uLnuiZTsJUODcIi81qP0T97MojQrE9eep6mxJdi Z54JeomefkKdsCySWEqgin16Xeo+oe2AnWznIIp/2jKmn/8J40dpNxByY29U8YwsoFEs iZisJMTIRdPVLrxtuuGdwZepjKbD7A+kg2DvCpFAwujJAg9skxz98LB8zdtD2qsVBVVT j2Cw== X-Gm-Message-State: ALyK8tLqpuOePy1vjBgoIpQkQ502K/rlSjzUPjWy4gEr39bX/nLRWa9XX/xKfIinZc3cURZ+ X-Received: by 10.25.214.231 with SMTP id p100mr4720280lfi.92.1465392651145; Wed, 08 Jun 2016 06:30:51 -0700 (PDT) Received: from beaming.home (91-157-170-157.elisa-laajakaista.fi. [91.157.170.157]) by smtp.gmail.com with ESMTPSA id 2sm139854lja.37.2016.06.08.06.30.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 08 Jun 2016 06:30:50 -0700 (PDT) From: riku.voipio@linaro.org To: qemu-devel@nongnu.org Date: Wed, 8 Jun 2016 16:30:01 +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:c07::22b Subject: [Qemu-devel] [PULL 20/44] linux-user: Use safe_syscall for kill, tkill and tgkill syscalls 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: Peter Maydell Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Peter Maydell Use the safe_syscall wrapper for the kill, tkill and tgkill syscalls. Without this, if a thread sent a SIGKILL to itself it could kill the thread before we had a chance to process a signal that arrived just before the SIGKILL, and that signal would get lost. We drop all the ifdeffery for tkill and tgkill, because every guest architecture we support implements them, and they've been in Linux since 2003 so we can assume the host headers define the __NR_tkill and __NR_tgkill constants. Signed-off-by: Peter Maydell Reviewed-by: Laurent Vivier Signed-off-by: Riku Voipio --- linux-user/syscall.c | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) -- 2.1.4 diff --git a/linux-user/syscall.c b/linux-user/syscall.c index f3061a9..c0d086c 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -191,8 +191,6 @@ static type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5, \ #define __NR_sys_getpriority __NR_getpriority #define __NR_sys_rt_sigqueueinfo __NR_rt_sigqueueinfo #define __NR_sys_syslog __NR_syslog -#define __NR_sys_tgkill __NR_tgkill -#define __NR_sys_tkill __NR_tkill #define __NR_sys_futex __NR_futex #define __NR_sys_inotify_init __NR_inotify_init #define __NR_sys_inotify_add_watch __NR_inotify_add_watch @@ -230,12 +228,6 @@ _syscall5(int, _llseek, uint, fd, ulong, hi, ulong, lo, #endif _syscall3(int,sys_rt_sigqueueinfo,int,pid,int,sig,siginfo_t *,uinfo) _syscall3(int,sys_syslog,int,type,char*,bufp,int,len) -#if defined(TARGET_NR_tgkill) && defined(__NR_tgkill) -_syscall3(int,sys_tgkill,int,tgid,int,pid,int,sig) -#endif -#if defined(TARGET_NR_tkill) && defined(__NR_tkill) -_syscall2(int,sys_tkill,int,tid,int,sig) -#endif #ifdef __NR_exit_group _syscall1(int,exit_group,int,error_code) #endif @@ -717,6 +709,9 @@ safe_syscall6(int, pselect6, int, nfds, fd_set *, readfds, fd_set *, writefds, \ safe_syscall6(int,futex,int *,uaddr,int,op,int,val, \ const struct timespec *,timeout,int *,uaddr2,int,val3) safe_syscall2(int, rt_sigsuspend, sigset_t *, newset, size_t, sigsetsize) +safe_syscall2(int, kill, pid_t, pid, int, sig) +safe_syscall2(int, tkill, int, tid, int, sig) +safe_syscall3(int, tgkill, int, tgid, int, pid, int, sig) static inline int host_to_target_sock_type(int host_type) { @@ -7169,7 +7164,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, ret = 0; break; case TARGET_NR_kill: - ret = get_errno(kill(arg1, target_to_host_signal(arg2))); + ret = get_errno(safe_kill(arg1, target_to_host_signal(arg2))); break; #ifdef TARGET_NR_rename case TARGET_NR_rename: @@ -10405,18 +10400,14 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, break; #endif -#if defined(TARGET_NR_tkill) && defined(__NR_tkill) case TARGET_NR_tkill: - ret = get_errno(sys_tkill((int)arg1, target_to_host_signal(arg2))); + ret = get_errno(safe_tkill((int)arg1, target_to_host_signal(arg2))); break; -#endif -#if defined(TARGET_NR_tgkill) && defined(__NR_tgkill) case TARGET_NR_tgkill: - ret = get_errno(sys_tgkill((int)arg1, (int)arg2, + ret = get_errno(safe_tgkill((int)arg1, (int)arg2, target_to_host_signal(arg3))); - break; -#endif + break; #ifdef TARGET_NR_set_robust_list case TARGET_NR_set_robust_list: