From patchwork Wed Oct 17 14:18:38 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Barcelo X-Patchwork-Id: 192056 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 8E3F92C008D for ; Thu, 18 Oct 2012 01:19:25 +1100 (EST) Received: from localhost ([::1]:58199 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TOUSx-0000W4-KS for incoming@patchwork.ozlabs.org; Wed, 17 Oct 2012 10:19:23 -0400 Received: from eggs.gnu.org ([208.118.235.92]:45911) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TOUSb-00008M-MX for qemu-devel@nongnu.org; Wed, 17 Oct 2012 10:19:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TOUSV-0006Fi-Pd for qemu-devel@nongnu.org; Wed, 17 Oct 2012 10:19:01 -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 1TOUSV-0006FR-Iw for qemu-devel@nongnu.org; Wed, 17 Oct 2012 10:18:55 -0400 Received: by mail-we0-f173.google.com with SMTP id t11so4442776wey.4 for ; Wed, 17 Oct 2012 07:18:55 -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=QBF/waWKfD+CJDA54eilq9xFIJTLIkKoYoC39+kspTM=; b=0g8PEiaVj7j+CnuOd+fzqTZI0W9HLbuL//cXb1oMQ3g3tCvJ1DbzVA1121RdQvnshU V/K13SkhY+jW0mNOfzPd7ikzgAQZQ7ABoU3PQklzGdNEtbiJ5wKzUGUNiisPUcAIGfc5 MnJZ9wk6Pri2cbxxIUMwPzBA62tWhFIQClaI+PLIBqkACUlRkIl0k6bAQOB6lh8FUif/ R9YH8Jj7upyEIaHQuBcHtjiUjrGU3jch1/hS6S+csIkUl5E051L0LYoT0Pu+yfeRx/Ro 7KA8aZNu4KUsUiCohL88lL0+uSBWNgmKJ9y+BXpGe9heX8P4MsI/J4F6HXqX1VF+FWhn 2G3g== Received: by 10.180.82.34 with SMTP id f2mr4462477wiy.17.1350483535230; Wed, 17 Oct 2012 07:18:55 -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.53 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 17 Oct 2012 07:18:54 -0700 (PDT) From: Alex Barcelo To: Date: Wed, 17 Oct 2012 16:18:38 +0200 Message-Id: <1350483518-5789-3-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 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 3d25b7d..b965d89 100644 --- a/linux-user/signal.c +++ b/linux-user/signal.c @@ -5468,7 +5468,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)