From patchwork Sat Oct 20 14:15:56 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Barcelo X-Patchwork-Id: 192916 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 17E912C008F for ; Sun, 21 Oct 2012 01:16:38 +1100 (EST) Received: from localhost ([::1]:54052 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TPZqu-0000nS-4P for incoming@patchwork.ozlabs.org; Sat, 20 Oct 2012 10:16:36 -0400 Received: from eggs.gnu.org ([208.118.235.92]:44741) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TPZqd-0000Qu-2Z for qemu-devel@nongnu.org; Sat, 20 Oct 2012 10:16:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TPZqb-0006RF-Gl for qemu-devel@nongnu.org; Sat, 20 Oct 2012 10:16:18 -0400 Received: from mail-we0-f173.google.com ([74.125.82.173]:58152) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TPZqb-0006R8-7T for qemu-devel@nongnu.org; Sat, 20 Oct 2012 10:16:17 -0400 Received: by mail-we0-f173.google.com with SMTP id t11so712756wey.4 for ; Sat, 20 Oct 2012 07:16:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; bh=dqSmnLQTLjmO5brFHbBV9ZuWkn2tX7dkqSfZMmoH8O4=; b=OE6Q/IJ1r1CixilibELWUzDlOni5Hpfs8jPJmjZVnEG4PCJm/S/Ci/77Ys0VgCi2fU QUljO0h/Fr44Slc7Nn7JFzcDmuYldy4fcXfeGoOBPk272kz1QHU/rvFugMtWLOsVzTfl /VaIrFib0nQpM8IWEyxyCVzXBTw7o3+rwx23St5cPse2FcvcvsvHIGxZTZ+lA+vm6xjV TWmOtsecPvGicjM02IWjXDoqEKxswH+pnMgb/a6ZpFxoJS4vRyRCwjOeHJkQG582Tqvt KVrzTIM6ujLu0k0OTx2dYRioGxGVKcn15faoFT+N2zQ1r6w6iQRD3Q72m7txOouePQ23 4Nbw== Received: by 10.180.81.37 with SMTP id w5mr9745591wix.10.1350742576466; Sat, 20 Oct 2012 07:16:16 -0700 (PDT) Received: from localhost.localdomain (62.57.4.176.dyn.user.ono.com. [62.57.4.176]) by mx.google.com with ESMTPS id cn6sm9819016wib.9.2012.10.20.07.16.14 (version=TLSv1/SSLv3 cipher=OTHER); Sat, 20 Oct 2012 07:16:15 -0700 (PDT) From: Alex Barcelo To: Date: Sat, 20 Oct 2012 16:15:56 +0200 Message-Id: <1350742557-9717-2-git-send-email-abarcelo@ac.upc.edu> X-Mailer: git-send-email 1.7.5.4 In-Reply-To: <1350742557-9717-1-git-send-email-abarcelo@ac.upc.edu> References: <1350742557-9717-1-git-send-email-abarcelo@ac.upc.edu> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 74.125.82.173 Cc: Riku Voipio , Alex Barcelo Subject: [Qemu-devel] [PATCHv3 1/2] signal: added a wrapper for sigprocmask function X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Create a wrapper for signal mask changes initiated by the guest; (this includes syscalls and also the sigreturns from signal.c) this will give us a place to put code which prevents the guest from changing the handling of signals used by QEMU itself internally. The wrapper is called from all the guest-initiated sigprocmask, but is not called from internal qemu sigprocmask calls. Signed-off-by: Alex Barcelo --- linux-user/qemu.h | 1 + linux-user/signal.c | 10 ++++++++++ linux-user/syscall.c | 14 +++++++------- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/linux-user/qemu.h b/linux-user/qemu.h index 5e53dca..1d59458 100644 --- a/linux-user/qemu.h +++ b/linux-user/qemu.h @@ -240,6 +240,7 @@ int host_to_target_signal(int sig); long do_sigreturn(CPUArchState *env); long do_rt_sigreturn(CPUArchState *env); abi_long do_sigaltstack(abi_ulong uss_addr, abi_ulong uoss_addr, abi_ulong sp); +int do_sigprocmask(int how, const sigset_t *set, sigset_t *oldset); #ifdef TARGET_I386 /* vm86.c */ diff --git a/linux-user/signal.c b/linux-user/signal.c index 95e2ffa..172de9a 100644 --- a/linux-user/signal.c +++ b/linux-user/signal.c @@ -5482,6 +5482,16 @@ long do_rt_sigreturn(CPUArchState *env) #endif +/* Wrapper for sigprocmask function + * Emulates a sigprocmask in a safe way for the guest. Note that set and oldset + * are host signal set, not guest ones. This wraps the sigprocmask host calls + * that should be protected (calls originated from guest) + */ +int do_sigprocmask(int how, const sigset_t *set, sigset_t *oldset) +{ + return sigprocmask(how, set, oldset); +} + void process_pending_signals(CPUArchState *cpu_env) { int sig; diff --git a/linux-user/syscall.c b/linux-user/syscall.c index e4291ed..9b57671 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -5925,7 +5925,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, { sigset_t cur_set; abi_ulong target_set; - sigprocmask(0, NULL, &cur_set); + do_sigprocmask(0, NULL, &cur_set); host_to_target_old_sigset(&target_set, &cur_set); ret = target_set; } @@ -5936,10 +5936,10 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, { sigset_t set, oset, cur_set; abi_ulong target_set = arg1; - sigprocmask(0, NULL, &cur_set); + do_sigprocmask(0, NULL, &cur_set); target_to_host_old_sigset(&set, &target_set); sigorset(&set, &set, &cur_set); - sigprocmask(SIG_SETMASK, &set, &oset); + do_sigprocmask(SIG_SETMASK, &set, &oset); host_to_target_old_sigset(&target_set, &oset); ret = target_set; } @@ -5970,7 +5970,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, mask = arg2; target_to_host_old_sigset(&set, &mask); - ret = get_errno(sigprocmask(how, &set, &oldset)); + ret = get_errno(do_sigprocmask(how, &set, &oldset)); if (!is_error(ret)) { host_to_target_old_sigset(&mask, &oldset); ret = mask; @@ -6004,7 +6004,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, how = 0; set_ptr = NULL; } - ret = get_errno(sigprocmask(how, set_ptr, &oldset)); + ret = get_errno(do_sigprocmask(how, set_ptr, &oldset)); if (!is_error(ret) && arg3) { if (!(p = lock_user(VERIFY_WRITE, arg3, sizeof(target_sigset_t), 0))) goto efault; @@ -6044,7 +6044,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, how = 0; set_ptr = NULL; } - ret = get_errno(sigprocmask(how, set_ptr, &oldset)); + ret = get_errno(do_sigprocmask(how, set_ptr, &oldset)); if (!is_error(ret) && arg3) { if (!(p = lock_user(VERIFY_WRITE, arg3, sizeof(target_sigset_t), 0))) goto efault; @@ -7932,7 +7932,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, } mask = arg2; target_to_host_old_sigset(&set, &mask); - sigprocmask(how, &set, &oldset); + do_sigprocmask(how, &set, &oldset); host_to_target_old_sigset(&mask, &oldset); ret = mask; }