From patchwork Wed Oct 17 14:18:37 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Barcelo X-Patchwork-Id: 192055 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 EEBE52C009F for ; Thu, 18 Oct 2012 01:19:18 +1100 (EST) Received: from localhost ([::1]:57562 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TOUSr-00009z-0f for incoming@patchwork.ozlabs.org; Wed, 17 Oct 2012 10:19:17 -0400 Received: from eggs.gnu.org ([208.118.235.92]:45895) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TOUSY-00007o-8q for qemu-devel@nongnu.org; Wed, 17 Oct 2012 10:19:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TOUST-0006FY-Th for qemu-devel@nongnu.org; Wed, 17 Oct 2012 10:18:58 -0400 Received: from mail-we0-f173.google.com ([74.125.82.173]:61800) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TOUST-0006FR-Ju for qemu-devel@nongnu.org; Wed, 17 Oct 2012 10:18:53 -0400 Received: by mail-we0-f173.google.com with SMTP id t11so4442776wey.4 for ; Wed, 17 Oct 2012 07:18:52 -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=MYp/ECKSsjQY2I57H5hHfGeuaazyV6oTRpl5wLYt9qk=; b=KWTsnFfrEsMc8qPl1yf4TvpqkouYR4hLNaqpYETiZ+4jDVxO8kROs0f6M+99ZDIEQo gjZNvLKPK3posYfvX583rLkm4aonaZgU9RmVs9PbZC52//PkRvfdzSwOrG1aOUWPgofz udM1mMhheMUZAiGRS5lDKTCgciiLt9FoURrA6X60bptP4D3KLAB1d2Io1fHDbWaoZHCo jZvVMWV/us+vAFldGSMJxQv2CxA7c18/pmj+Aqfidyd0PZWtdaWAHgZaplG9F1hxjvWX J/9aFKcxqe5CqOrVPcuLsIo967QuNnIaYRgOSd63vBIjUy7blKDO8xjo42peqdnjc38i lTXQ== Received: by 10.216.71.202 with SMTP id r52mr7487327wed.108.1350483532550; Wed, 17 Oct 2012 07:18:52 -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 m14sm24518080wie.8.2012.10.17.07.18.48 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 17 Oct 2012 07:18:49 -0700 (PDT) From: Alex Barcelo To: Date: Wed, 17 Oct 2012 16:18:37 +0200 Message-Id: <1350483518-5789-2-git-send-email-abarcelo@ac.upc.edu> X-Mailer: git-send-email 1.7.5.4 In-Reply-To: <1350483518-5789-1-git-send-email-abarcelo@ac.upc.edu> References: <1350483518-5789-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] [PATCHv2 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 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 fc4cc00..e2dd6a6 100644 --- a/linux-user/qemu.h +++ b/linux-user/qemu.h @@ -237,6 +237,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 15bc4e8..3d25b7d 100644 --- a/linux-user/signal.c +++ b/linux-user/signal.c @@ -5461,6 +5461,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 471d060..49c0beb 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -5875,7 +5875,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; } @@ -5886,10 +5886,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; } @@ -5920,7 +5920,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; @@ -5954,7 +5954,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; @@ -5994,7 +5994,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; @@ -7870,7 +7870,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; }