From nobody Wed Nov 27 14:44:08 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1731155523108541.2287951943176; Sat, 9 Nov 2024 04:32:03 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t9kM6-00085B-Rs; Sat, 09 Nov 2024 07:14:18 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t9kM4-0007yh-1u; Sat, 09 Nov 2024 07:14:16 -0500 Received: from isrv.corpit.ru ([86.62.121.231]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t9kM2-0004iJ-1M; Sat, 09 Nov 2024 07:14:15 -0500 Received: from tsrv.corpit.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id 3D154A161F; Sat, 9 Nov 2024 15:07:10 +0300 (MSK) Received: from tls.msk.ru (mjt.wg.tls.msk.ru [192.168.177.130]) by tsrv.corpit.ru (Postfix) with SMTP id EB6B9167FAD; Sat, 9 Nov 2024 15:08:04 +0300 (MSK) Received: (nullmailer pid 3295423 invoked by uid 1000); Sat, 09 Nov 2024 12:08:01 -0000 From: Michael Tokarev To: qemu-devel@nongnu.org Cc: qemu-stable@nongnu.org, Hanna Czenczek , Peter Xu , Michael Tokarev Subject: [Stable-9.0.4 55/57] migration: Ensure vmstate_save() sets errp Date: Sat, 9 Nov 2024 15:07:57 +0300 Message-Id: <20241109120801.3295120-55-mjt@tls.msk.ru> X-Mailer: git-send-email 2.39.5 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=86.62.121.231; envelope-from=mjt@tls.msk.ru; helo=isrv.corpit.ru X-Spam_score_int: -68 X-Spam_score: -6.9 X-Spam_bar: ------ X-Spam_report: (-6.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_HI=-5, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1731155523668116600 Content-Type: text/plain; charset="utf-8" From: Hanna Czenczek migration/savevm.c contains some calls to vmstate_save() that are followed by migrate_set_error() if the integer return value indicates an error. migrate_set_error() requires that the `Error *` object passed to it is set. Therefore, vmstate_save() is assumed to always set *errp on error. Right now, that assumption is not met: vmstate_save_state_v() (called internally by vmstate_save()) will not set *errp if vmstate_subsection_save() or vmsd->post_save() fail. Fix that by adding an *errp parameter to vmstate_subsection_save(), and by generating a generic error in case post_save() fails (as is already done for pre_save()). Without this patch, qemu will crash after vmstate_subsection_save() or post_save() have failed inside of a vmstate_save() call (unless migrate_set_error() then happen to discard the new error because s->error is already set). This happens e.g. when receiving the state from a virtio-fs back-end (virtiofsd) fails. Signed-off-by: Hanna Czenczek Link: https://lore.kernel.org/r/20241015170437.310358-1-hreitz@redhat.com Signed-off-by: Peter Xu (cherry picked from commit 37dfcba1a04989830c706f9cbc00450e5d3a7447) Signed-off-by: Michael Tokarev diff --git a/migration/vmstate.c b/migration/vmstate.c index ef26f26ccd..d19b42630a 100644 --- a/migration/vmstate.c +++ b/migration/vmstate.c @@ -22,7 +22,8 @@ #include "trace.h" =20 static int vmstate_subsection_save(QEMUFile *f, const VMStateDescription *= vmsd, - void *opaque, JSONWriter *vmdesc); + void *opaque, JSONWriter *vmdesc, + Error **errp); static int vmstate_subsection_load(QEMUFile *f, const VMStateDescription *= vmsd, void *opaque); =20 @@ -440,12 +441,13 @@ int vmstate_save_state_v(QEMUFile *f, const VMStateDe= scription *vmsd, json_writer_end_array(vmdesc); } =20 - ret =3D vmstate_subsection_save(f, vmsd, opaque, vmdesc); + ret =3D vmstate_subsection_save(f, vmsd, opaque, vmdesc, errp); =20 if (vmsd->post_save) { int ps_ret =3D vmsd->post_save(opaque); - if (!ret) { + if (!ret && ps_ret) { ret =3D ps_ret; + error_setg(errp, "post-save failed: %s", vmsd->name); } } return ret; @@ -517,7 +519,8 @@ static int vmstate_subsection_load(QEMUFile *f, const V= MStateDescription *vmsd, } =20 static int vmstate_subsection_save(QEMUFile *f, const VMStateDescription *= vmsd, - void *opaque, JSONWriter *vmdesc) + void *opaque, JSONWriter *vmdesc, + Error **errp) { const VMStateDescription * const *sub =3D vmsd->subsections; bool vmdesc_has_subsections =3D false; @@ -545,7 +548,7 @@ static int vmstate_subsection_save(QEMUFile *f, const V= MStateDescription *vmsd, qemu_put_byte(f, len); qemu_put_buffer(f, (uint8_t *)vmsdsub->name, len); qemu_put_be32(f, vmsdsub->version_id); - ret =3D vmstate_save_state(f, vmsdsub, opaque, vmdesc); + ret =3D vmstate_save_state_with_err(f, vmsdsub, opaque, vmdesc= , errp); if (ret) { return ret; } --=20 2.39.5