From patchwork Tue Apr 5 09:50:06 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 8749131 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 112E79F336 for ; Tue, 5 Apr 2016 09:50:50 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 67E6920374 for ; Tue, 5 Apr 2016 09:50:49 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C41B720373 for ; Tue, 5 Apr 2016 09:50:48 +0000 (UTC) Received: from localhost ([::1]:35624 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1anNdG-0003VL-TG for patchwork-qemu-devel@patchwork.kernel.org; Tue, 05 Apr 2016 05:50:46 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54783) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1anNcy-0003V8-HY for qemu-devel@nongnu.org; Tue, 05 Apr 2016 05:50:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1anNcx-00017Q-HY for qemu-devel@nongnu.org; Tue, 05 Apr 2016 05:50:28 -0400 Received: from mail-wm0-x22d.google.com ([2a00:1450:400c:c09::22d]:35227) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1anNcx-00016g-7u for qemu-devel@nongnu.org; Tue, 05 Apr 2016 05:50:27 -0400 Received: by mail-wm0-x22d.google.com with SMTP id 191so18373805wmq.0 for ; Tue, 05 Apr 2016 02:50:27 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=TZDmtHktHi824Hn6Wvb35LvVCaqHtkLogQYXRv1FPX8=; b=vsYGUi5xH2Hsi6Mf8bL0fopILCgxHK4HwUs6d6cqB3YLYlchmCLo72WY6LJ2p7E1Tb 5SPPQj6R2hfdpTytaZ0SHJRCXdYxz/sifm/Xd4dZUKevvWQQbDXu+1DYqoYy6BMpjcJS SEmX9oiA9ylolzxmlHX4MMB1RlHht/UjerHh/zcB3TZpQaZDGyWmxqmtBzjRyq2szTAU SGXrbEgFlQwH3JqNAxe0u1rwKov1EoYMwDGUM9n9Q4m3HqJh0RsChg9jZjmWj1jYZb7o ptvF8TRcy8ILFdQULZ0dGeeaINSGtdVlYrw7XNQV6Zas310vYkpo2cTNSm9tszA/oWJG ut2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=TZDmtHktHi824Hn6Wvb35LvVCaqHtkLogQYXRv1FPX8=; b=k3LjOrivIRynfu4zU/QD6eVUiB9k1kqziZQO+rL3Nzk9Fdg+FK2SWG0Q3+ME1rI5oz QOoZcg2racELe5D4PYhoR4WfgI8EeTNAFH+WlHyb6YiLSIHzsnsb75XboN5E0mF9FNhu X5MIwHfb1kfoigWzxj1I1ivhPtY82h1wpxvJCXhpCUtCKzJHw02cW/GhJ5x0P5Gajmnj KrU5vUf9QzORQq4dtZ4S+YaoVJMGmu5Zu4kZl1ByLYGpPssuypILde5R4dFhTtizqsV4 dacAoLXqQeDeZI9CuCIYnYkV3lwHqajT/VRv0IgVZ+vpwQ/Us8fzKRd6wtUxs/r+5J9G BRkg== X-Gm-Message-State: AD7BkJKcsVheo97uUcdL+ZEQsNKFfFpnUa9eL9LRp3CXeTWnnXTMcuriJjLFp5RSFtyQJQ== X-Received: by 10.194.236.198 with SMTP id uw6mr12069303wjc.42.1459849826528; Tue, 05 Apr 2016 02:50:26 -0700 (PDT) Received: from donizetti.lan (94-39-141-76.adsl-ull.clienti.tiscali.it. [94.39.141.76]) by smtp.gmail.com with ESMTPSA id ka4sm33721377wjc.47.2016.04.05.02.50.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 05 Apr 2016 02:50:25 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Tue, 5 Apr 2016 11:50:06 +0200 Message-Id: <1459849818-26649-4-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1459849818-26649-1-git-send-email-pbonzini@redhat.com> References: <1459849818-26649-1-git-send-email-pbonzini@redhat.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::22d Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini Subject: [Qemu-devel] [PULL 03/15] memory: fix segv on qemu_ram_free(block=0x0) 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Marc-André Lureau Since f1060c55bf1377b4, the pointer is directly passed to qemu_ram_free(). However, on initialization failure, it may be called with a NULL pointer. Return immediately in this case. This fixes a SEGV when memory initialization failed, for example permission denied on open backing store /dev/hugepages, with -object memory-backend-file,mem-path=/dev/hugepages. Program received signal SIGSEGV, Segmentation fault. 0x00005555556e67e7 in qemu_ram_free (block=0x0) at /home/elmarco/src/qemu/exec.c:1775 Signed-off-by: Marc-André Lureau Message-Id: <1459250451-29984-1-git-send-email-marcandre.lureau@redhat.com> Signed-off-by: Paolo Bonzini --- exec.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/exec.c b/exec.c index f46e596..c4f9036 100644 --- a/exec.c +++ b/exec.c @@ -1773,6 +1773,10 @@ static void reclaim_ramblock(RAMBlock *block) void qemu_ram_free(RAMBlock *block) { + if (!block) { + return; + } + qemu_mutex_lock_ramlist(); QLIST_REMOVE_RCU(block, next); ram_list.mru_block = NULL;