From patchwork Tue Mar 15 15:00:43 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 8589201 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id DCEFBC0553 for ; Tue, 15 Mar 2016 15:07:01 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 4AD26202E5 for ; Tue, 15 Mar 2016 15:07:00 +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 971B6202AE for ; Tue, 15 Mar 2016 15:06:59 +0000 (UTC) Received: from localhost ([::1]:48899 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1afqYk-0000uV-UG for patchwork-qemu-devel@patchwork.kernel.org; Tue, 15 Mar 2016 11:06:58 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57626) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1afqSq-0006sZ-61 for qemu-devel@nongnu.org; Tue, 15 Mar 2016 11:00:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1afqSl-0006Mz-1w for qemu-devel@nongnu.org; Tue, 15 Mar 2016 11:00:52 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46926) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1afqSk-0006Mq-Sx for qemu-devel@nongnu.org; Tue, 15 Mar 2016 11:00:46 -0400 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (Postfix) with ESMTPS id 6C0D17F0AD; Tue, 15 Mar 2016 15:00:46 +0000 (UTC) Received: from redhat.com (vpn1-6-68.ams2.redhat.com [10.36.6.68]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with SMTP id u2FF0i5O004653; Tue, 15 Mar 2016 11:00:44 -0400 Date: Tue, 15 Mar 2016 17:00:43 +0200 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Message-ID: <1458053975-2410-11-git-send-email-mst@redhat.com> References: <1458053975-2410-1-git-send-email-mst@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1458053975-2410-1-git-send-email-mst@redhat.com> X-Mutt-Fcc: =sent X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Peter Maydell , Eduardo Habkost , Markus Armbruster , Igor Mammedov Subject: [Qemu-devel] [PULL v2 10/51] pc-dimm: fix error handling in pc_dimm_check_memdev_is_busy() 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.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable 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: Igor Mammedov If host_memory_backend_get_memory() were to return error and NULL MemoryRegion, pc_dimm_check_memdev_is_busy() would crash dereferencing NULL pointer in memory_region_is_mapped(). But if error is set and non NULL MemoryRegion is returned then error_setg() will fail with "error already set" assertion in error_setv() To avoid above issues use typical error handling pattern for property setters: Error *local_error = NULL; ... error_propagate(errp, local_err); Reported-by: Markus Armbruster Signed-off-by: Igor Mammedov Reviewed-by: Markus Armbruster Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/mem/pc-dimm.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c index 650f0f8..973bf20 100644 --- a/hw/mem/pc-dimm.c +++ b/hw/mem/pc-dimm.c @@ -364,15 +364,22 @@ static void pc_dimm_check_memdev_is_busy(Object *obj, const char *name, Object *val, Error **errp) { MemoryRegion *mr; + Error *local_err = NULL; - mr = host_memory_backend_get_memory(MEMORY_BACKEND(val), errp); + mr = host_memory_backend_get_memory(MEMORY_BACKEND(val), &local_err); + if (local_err) { + goto out; + } if (memory_region_is_mapped(mr)) { char *path = object_get_canonical_path_component(val); - error_setg(errp, "can't use already busy memdev: %s", path); + error_setg(&local_err, "can't use already busy memdev: %s", path); g_free(path); } else { - qdev_prop_allow_set_link_before_realize(obj, name, val, errp); + qdev_prop_allow_set_link_before_realize(obj, name, val, &local_err); } + +out: + error_propagate(errp, local_err); } static void pc_dimm_init(Object *obj)