From nobody Sat May 4 13:37:32 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 14860404946531005.7574464768967; Thu, 2 Feb 2017 05:01:34 -0800 (PST) Received: from localhost ([::1]:56275 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cZH11-0001uA-08 for importer@patchew.org; Thu, 02 Feb 2017 08:01:31 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41607) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cZGzb-00013s-Ba for qemu-devel@nongnu.org; Thu, 02 Feb 2017 08:00:04 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cZGzZ-0008Ul-7u for qemu-devel@nongnu.org; Thu, 02 Feb 2017 08:00:03 -0500 Received: from mx1.redhat.com ([209.132.183.28]:47676) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cZGzY-0008Te-Va for qemu-devel@nongnu.org; Thu, 02 Feb 2017 08:00:01 -0500 Received: from smtp.corp.redhat.com (int-mx16.intmail.prod.int.phx2.redhat.com [10.5.11.28]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0FF7FC04D2F2 for ; Thu, 2 Feb 2017 13:00:01 +0000 (UTC) Received: from dgilbert-t530.redhat.com (ovpn-117-124.ams2.redhat.com [10.36.117.124]) by smtp.corp.redhat.com (Postfix) with ESMTP id 313FE6D9B6; Thu, 2 Feb 2017 13:00:00 +0000 (UTC) From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, quintela@redhat.com, amit.shah@redhat.com Date: Thu, 2 Feb 2017 12:59:54 +0000 Message-Id: <20170202125956.21942-2-dgilbert@redhat.com> In-Reply-To: <20170202125956.21942-1-dgilbert@redhat.com> References: <20170202125956.21942-1-dgilbert@redhat.com> X-Scanned-By: MIMEDefang 2.74 on 10.5.11.28 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Thu, 02 Feb 2017 13:00:01 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 1/3] vmstate_register_with_alias_id: Take an Error ** X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: "Dr. David Alan Gilbert" I'll be adding an error to it in a subsequent patch. Signed-off-by: Dr. David Alan Gilbert Reviewed-by: Juan Quintela --- hw/core/qdev.c | 3 ++- hw/intc/apic_common.c | 2 +- include/migration/vmstate.h | 5 +++-- migration/savevm.c | 3 ++- stubs/vmstate.c | 3 ++- 5 files changed, 10 insertions(+), 6 deletions(-) diff --git a/hw/core/qdev.c b/hw/core/qdev.c index 5783442..ea97b15 100644 --- a/hw/core/qdev.c +++ b/hw/core/qdev.c @@ -935,7 +935,8 @@ static void device_set_realized(Object *obj, bool value= , Error **errp) if (qdev_get_vmsd(dev)) { vmstate_register_with_alias_id(dev, -1, qdev_get_vmsd(dev), de= v, dev->instance_id_alias, - dev->alias_required_for_version= ); + dev->alias_required_for_version, + NULL); } =20 QLIST_FOREACH(bus, &dev->child_bus, sibling) { diff --git a/hw/intc/apic_common.c b/hw/intc/apic_common.c index 17df24c..6ce8ef7 100644 --- a/hw/intc/apic_common.c +++ b/hw/intc/apic_common.c @@ -329,7 +329,7 @@ static void apic_common_realize(DeviceState *dev, Error= **errp) instance_id =3D -1; } vmstate_register_with_alias_id(NULL, instance_id, &vmstate_apic_common, - s, -1, 0); + s, -1, 0, NULL); } =20 static void apic_common_unrealize(DeviceState *dev, Error **errp) diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h index 3bbe3ed..c38b00a 100644 --- a/include/migration/vmstate.h +++ b/include/migration/vmstate.h @@ -988,14 +988,15 @@ bool vmstate_save_needed(const VMStateDescription *vm= sd, void *opaque); int vmstate_register_with_alias_id(DeviceState *dev, int instance_id, const VMStateDescription *vmsd, void *base, int alias_id, - int required_for_version); + int required_for_version, + Error **errp); =20 static inline int vmstate_register(DeviceState *dev, int instance_id, const VMStateDescription *vmsd, void *opaque) { return vmstate_register_with_alias_id(dev, instance_id, vmsd, - opaque, -1, 0); + opaque, -1, 0, NULL); } =20 void vmstate_unregister(DeviceState *dev, const VMStateDescription *vmsd, diff --git a/migration/savevm.c b/migration/savevm.c index 204012e..59928d6 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -656,7 +656,8 @@ void unregister_savevm(DeviceState *dev, const char *id= str, void *opaque) int vmstate_register_with_alias_id(DeviceState *dev, int instance_id, const VMStateDescription *vmsd, void *opaque, int alias_id, - int required_for_version) + int required_for_version, + Error **errp) { SaveStateEntry *se; =20 diff --git a/stubs/vmstate.c b/stubs/vmstate.c index 6590627..bbe158f 100644 --- a/stubs/vmstate.c +++ b/stubs/vmstate.c @@ -8,7 +8,8 @@ int vmstate_register_with_alias_id(DeviceState *dev, int instance_id, const VMStateDescription *vmsd, void *base, int alias_id, - int required_for_version) + int required_for_version, + Error **errp) { return 0; } --=20 2.9.3 From nobody Sat May 4 13:37:32 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 148604049355982.3698845852258; Thu, 2 Feb 2017 05:01:33 -0800 (PST) Received: from localhost ([::1]:56277 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cZH11-0001uo-Lc for importer@patchew.org; Thu, 02 Feb 2017 08:01:31 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41609) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cZGzb-00013t-Bs for qemu-devel@nongnu.org; Thu, 02 Feb 2017 08:00:04 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cZGza-00005k-By for qemu-devel@nongnu.org; Thu, 02 Feb 2017 08:00:03 -0500 Received: from mx1.redhat.com ([209.132.183.28]:51774) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cZGza-0008W0-4G for qemu-devel@nongnu.org; Thu, 02 Feb 2017 08:00:02 -0500 Received: from smtp.corp.redhat.com (int-mx16.intmail.prod.int.phx2.redhat.com [10.5.11.28]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3C79481222 for ; Thu, 2 Feb 2017 13:00:02 +0000 (UTC) Received: from dgilbert-t530.redhat.com (ovpn-117-124.ams2.redhat.com [10.36.117.124]) by smtp.corp.redhat.com (Postfix) with ESMTP id 575B46D9B6; Thu, 2 Feb 2017 13:00:01 +0000 (UTC) From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, quintela@redhat.com, amit.shah@redhat.com Date: Thu, 2 Feb 2017 12:59:55 +0000 Message-Id: <20170202125956.21942-3-dgilbert@redhat.com> In-Reply-To: <20170202125956.21942-1-dgilbert@redhat.com> References: <20170202125956.21942-1-dgilbert@redhat.com> X-Scanned-By: MIMEDefang 2.74 on 10.5.11.28 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Thu, 02 Feb 2017 13:00:02 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 2/3] migration: Check for ID length X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: "Dr. David Alan Gilbert" The qdev id of a device can be huge if it's on the end of a chain of bridges; in reality such chains shouldn't occur but they can be made to by chaining PCIe bridges together. The migration format has a number of 256 character long format limits; check we don't hit them (we already use pstrcat/cpy but that just protects us from buffer overruns, we fairly quickly hit an assert). Signed-off-by: Dr. David Alan Gilbert Reviewed-by: Juan Quintela --- include/migration/vmstate.h | 2 ++ migration/savevm.c | 21 ++++++++++++++++----- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h index c38b00a..6233fe2 100644 --- a/include/migration/vmstate.h +++ b/include/migration/vmstate.h @@ -985,12 +985,14 @@ void vmstate_save_state(QEMUFile *f, const VMStateDes= cription *vmsd, =20 bool vmstate_save_needed(const VMStateDescription *vmsd, void *opaque); =20 +/* Returns: 0 on success, -1 on failure */ int vmstate_register_with_alias_id(DeviceState *dev, int instance_id, const VMStateDescription *vmsd, void *base, int alias_id, int required_for_version, Error **errp); =20 +/* Returns: 0 on success, -1 on failure */ static inline int vmstate_register(DeviceState *dev, int instance_id, const VMStateDescription *vmsd, void *opaque) diff --git a/migration/savevm.c b/migration/savevm.c index 59928d6..e8e5ff5 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -590,8 +590,14 @@ int register_savevm_live(DeviceState *dev, if (dev) { char *id =3D qdev_get_dev_path(dev); if (id) { - pstrcpy(se->idstr, sizeof(se->idstr), id); - pstrcat(se->idstr, sizeof(se->idstr), "/"); + if (snprintf(se->idstr, sizeof(se->idstr), "%s/", id) >=3D + sizeof(se->idstr)) { + error_report("Path too long for VMState (%s)", id); + g_free(id); + g_free(se); + + return -1; + } g_free(id); =20 se->compat =3D g_new0(CompatEntry, 1); @@ -674,9 +680,14 @@ int vmstate_register_with_alias_id(DeviceState *dev, i= nt instance_id, if (dev) { char *id =3D qdev_get_dev_path(dev); if (id) { - pstrcpy(se->idstr, sizeof(se->idstr), id); - pstrcat(se->idstr, sizeof(se->idstr), "/"); - g_free(id); + if (snprintf(se->idstr, sizeof(se->idstr), "%s/", id) >=3D + sizeof(se->idstr)) { + error_setg(errp, "Path too long for VMState (%s)", id); + g_free(id); + g_free(se); + + return -1; + } =20 se->compat =3D g_new0(CompatEntry, 1); pstrcpy(se->compat->idstr, sizeof(se->compat->idstr), vmsd->na= me); --=20 2.9.3 From nobody Sat May 4 13:37:32 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1486040793020807.3057048418176; Thu, 2 Feb 2017 05:06:33 -0800 (PST) Received: from localhost ([::1]:56384 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cZH5q-0005ju-IA for importer@patchew.org; Thu, 02 Feb 2017 08:06:30 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41730) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cZGzo-0001G2-IX for qemu-devel@nongnu.org; Thu, 02 Feb 2017 08:00:19 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cZGzb-000088-FX for qemu-devel@nongnu.org; Thu, 02 Feb 2017 08:00:12 -0500 Received: from mx1.redhat.com ([209.132.183.28]:21623) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cZGzb-00006P-A6 for qemu-devel@nongnu.org; Thu, 02 Feb 2017 08:00:03 -0500 Received: from smtp.corp.redhat.com (int-mx16.intmail.prod.int.phx2.redhat.com [10.5.11.28]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 633F6C05092E for ; Thu, 2 Feb 2017 13:00:03 +0000 (UTC) Received: from dgilbert-t530.redhat.com (ovpn-117-124.ams2.redhat.com [10.36.117.124]) by smtp.corp.redhat.com (Postfix) with ESMTP id 80C30B2375; Thu, 2 Feb 2017 13:00:02 +0000 (UTC) From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, quintela@redhat.com, amit.shah@redhat.com Date: Thu, 2 Feb 2017 12:59:56 +0000 Message-Id: <20170202125956.21942-4-dgilbert@redhat.com> In-Reply-To: <20170202125956.21942-1-dgilbert@redhat.com> References: <20170202125956.21942-1-dgilbert@redhat.com> X-Scanned-By: MIMEDefang 2.74 on 10.5.11.28 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Thu, 02 Feb 2017 13:00:03 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 3/3] vmstate registration: check return values X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: "Dr. David Alan Gilbert" Check qdev's call to vmstate_register_with_alias_id; that gets most of the common uses; there's hundreds of calls via vmstate_register which could get fixed over time. Signed-off-by: Dr. David Alan Gilbert Reviewed-by: Juan Quintela --- hw/core/qdev.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/hw/core/qdev.c b/hw/core/qdev.c index ea97b15..06ba02e 100644 --- a/hw/core/qdev.c +++ b/hw/core/qdev.c @@ -933,10 +933,12 @@ static void device_set_realized(Object *obj, bool val= ue, Error **errp) } =20 if (qdev_get_vmsd(dev)) { - vmstate_register_with_alias_id(dev, -1, qdev_get_vmsd(dev), de= v, - dev->instance_id_alias, - dev->alias_required_for_version, - NULL); + if (vmstate_register_with_alias_id(dev, -1, qdev_get_vmsd(dev)= , dev, + dev->instance_id_alias, + dev->alias_required_for_ver= sion, + &local_err) < 0) { + goto post_realize_fail; + } } =20 QLIST_FOREACH(bus, &dev->child_bus, sibling) { --=20 2.9.3