From patchwork Sat Oct 20 14:15:57 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Barcelo X-Patchwork-Id: 192917 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 2FDE22C008D for ; Sun, 21 Oct 2012 01:16:57 +1100 (EST) Received: from localhost ([::1]:55982 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TPZrD-0001wG-7R for incoming@patchwork.ozlabs.org; Sat, 20 Oct 2012 10:16:55 -0400 Received: from eggs.gnu.org ([208.118.235.92]:44750) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TPZqd-0000Rw-RP 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 1TPZqc-0006RW-MZ for qemu-devel@nongnu.org; Sat, 20 Oct 2012 10:16:19 -0400 Received: from mail-wi0-f175.google.com ([209.85.212.175]:44017) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TPZqc-0006RN-G2 for qemu-devel@nongnu.org; Sat, 20 Oct 2012 10:16:18 -0400 Received: by mail-wi0-f175.google.com with SMTP id hq4so869175wib.10 for ; Sat, 20 Oct 2012 07:16:17 -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=5Mynd5KAJtij2olPqrkm3M9ozDqWKKuvtz232evPQOc=; b=aK45BkH4ZK2vj/q7Sh8yfofSmki1L1zRrjKG/jelTFDP36vykcE4wZ20lKSw1AN7A6 F1Q1DezQVhvWt2nxlHSvpuyITW5CQAsuAIcxKHMUN5529f7bWcZ4UlgBS5J4tnNkbdgI 6AcQoyh+gnNt//QisMpTKTxdnxKAlDTiQrcaZX9bxihdrvpZNs32e0wjIgNEQSr47YUp swRmsJznNZHq3IvBg74caZqxWNhXKZeIkYT0ISEgHMIKmeEQXe2Fv8iNy4VtXzAUu1Kx PLmSpvZoiXTeug64b3LlH+MoMWM3EzPW1ArLl/MU1SQTVFYSjtnlslekM7muZwHpNIaz 9/fg== Received: by 10.216.209.40 with SMTP id r40mr2568081weo.144.1350742577563; Sat, 20 Oct 2012 07:16:17 -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.16 (version=TLSv1/SSLv3 cipher=OTHER); Sat, 20 Oct 2012 07:16:17 -0700 (PDT) From: Alex Barcelo To: Date: Sat, 20 Oct 2012 16:15:57 +0200 Message-Id: <1350742557-9717-3-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: 209.85.212.175 Cc: Riku Voipio , Alex Barcelo Subject: [Qemu-devel] [PATCHv3 2/2] signal: sigsegv protection on do_sigprocmask 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 safe wrapper by protecting the signal mask. Instead of doing a simple passthrough of the sigprocmask, the wrapper manipulates the signal mask in a safe way for the qemu internal. This is done by avoiding SIGSEGV bit mask manipulation from the guest. We also return the same bit on the SIGSEGV. This is not required for most applications, but if the application checks it, then it will see that somethings fishy about it (and, in fact, maybe it should). If we do not want the guest to be aware of those manipulations, then it should be implemented in another way, but this seems quite clean and consistent. The wrapper can be improved to add more features for better signal managing, but this seems enough for "simple" self-modifying code. Signed-off-by: Alex Barcelo --- linux-user/signal.c | 19 ++++++++++++++++++- 1 files changed, 18 insertions(+), 1 deletions(-) diff --git a/linux-user/signal.c b/linux-user/signal.c index 172de9a..b430ab0 100644 --- a/linux-user/signal.c +++ b/linux-user/signal.c @@ -5489,7 +5489,24 @@ long do_rt_sigreturn(CPUArchState *env) */ int do_sigprocmask(int how, const sigset_t *set, sigset_t *oldset) { - return sigprocmask(how, set, oldset); + int ret; + sigset_t val; + sigset_t *temp; + if (set) { + val = *set; + temp = &val; + sigdelset(temp, SIGSEGV); + } else { + temp = NULL; + } + ret = sigprocmask(how, temp, oldset); + + /* Force set state of SIGSEGV, may be best for some apps, maybe not so good + * This is not required for qemu to work */ + if (oldset) { + sigaddset(oldset, SIGSEGV); + } + return ret; } void process_pending_signals(CPUArchState *cpu_env)