From patchwork Wed Apr 18 19:30:48 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 153579 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 83303B6F62 for ; Thu, 19 Apr 2012 06:11:31 +1000 (EST) Received: from localhost ([::1]:43875 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SKbDt-0003xF-8o for incoming@patchwork.ozlabs.org; Wed, 18 Apr 2012 16:11:29 -0400 Received: from eggs.gnu.org ([208.118.235.92]:46839) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SKbDm-0003wx-Ff for qemu-devel@nongnu.org; Wed, 18 Apr 2012 16:11:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SKbDk-0000PK-Kt for qemu-devel@nongnu.org; Wed, 18 Apr 2012 16:11:22 -0400 Received: from mx1.redhat.com ([209.132.183.28]:59175) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SKbDk-0000P6-Cz for qemu-devel@nongnu.org; Wed, 18 Apr 2012 16:11:20 -0400 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q3IKBG8I001309 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 18 Apr 2012 16:11:17 -0400 Received: from localhost (ovpn-113-24.phx2.redhat.com [10.3.113.24]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id q3IJUjgH018859; Wed, 18 Apr 2012 15:30:46 -0400 From: Luiz Capitulino To: qemu-devel@nongnu.org Date: Wed, 18 Apr 2012 16:30:48 -0300 Message-Id: <1334777449-18542-2-git-send-email-lcapitulino@redhat.com> In-Reply-To: <1334777449-18542-1-git-send-email-lcapitulino@redhat.com> References: <1334777449-18542-1-git-send-email-lcapitulino@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Cc: lersek@redhat.com, mdroth@linux.vnet.ibm.com Subject: [Qemu-devel] [PATCH 1/2] qemu-ga: suspend: fix possible SIGCHLD during close() and g_free() 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 A child created by bios_supports_mode() could terminate during the call to close() or g_free(). This could cause the SIGCHLD signal to be deliveried in the midle of their execution. Possible problems range from resource leak to segfault. Fix that by blocking SIGCHLD during those calls. Also, tries to explain why bios_supports_mode() got so complex... Signed-off-by: Luiz Capitulino --- qga/commands-posix.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/qga/commands-posix.c b/qga/commands-posix.c index faf970d..41ba0c5 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -521,14 +521,18 @@ static void guest_fsfreeze_cleanup(void) * This function forks twice and the information about the mode support * status is passed to the qemu-ga process via a pipe. * - * This approach allows us to keep the way we reap terminated children - * in qemu-ga quite simple. + * XXX: This approach is a bit complex, it's implemented this way to avoid + * calling waitpid() from the main qemu-ga process, as this could cause + * interference with other commands that create new processes. The + * solution to this problem is to introduce an internal API to safely + * create & wait for children processes. */ static void bios_supports_mode(const char *pmutils_bin, const char *pmutils_arg, const char *sysfile_str, Error **err) { pid_t pid; ssize_t ret; + sigset_t sigset; char *pmutils_path; int status, pipefds[2]; @@ -603,9 +607,15 @@ static void bios_supports_mode(const char *pmutils_bin, const char *pmutils_arg, _exit(EXIT_SUCCESS); } + sigemptyset(&sigset); + sigaddset(&sigset, SIGCHLD); + pthread_sigmask(SIG_BLOCK, &sigset, NULL); + close(pipefds[1]); g_free(pmutils_path); + pthread_sigmask(SIG_UNBLOCK, &sigset, NULL); + if (pid < 0) { error_set(err, QERR_UNDEFINED_ERROR); goto out;