From nobody Tue Apr 7 09:22:14 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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; dmarc=pass(p=reject dis=none) header.from=google.com ARC-Seal: i=1; a=rsa-sha256; t=1773444970; cv=none; d=zohomail.com; s=zohoarc; b=T80KdbHHZeD2b9/MDQrbVrHerfOUBjrqn58c95v1+xjhbRjUxRojVDStnh2a3bAdDE8DxXDFxx+OS8EYy65KZ8hCJoSDDrHscS1yRumnKoy7tVU0xytI3Xo0gPIlK4b+IvOKttb8aFHYsGQDWzc7reEPhw7dZqE3AVRkPBzNGFE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1773444970; h=Content-Type:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=SAPEylkIV0nBuTHJQyf+c/OAybfX0uEC9xGFY7/Ve7M=; b=koPz755b6a4s6vcDz5MR5AYQ2cLYdWxy5P/LkeRp1LqLPgF1qX57BNvyna5kCJGc0gCYsDk8GNSYHrCczu0Kk26Ue7k1sEc3yAz1TBqi7NfxeUCYhrsh3MblFuHuESIlwqilVZlRpVQwUgCFw4pRQKJ7G6SKQOa8GR0pLBKBupM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1773444970202936.5095531812536; Fri, 13 Mar 2026 16:36:10 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1w1C2y-0000cX-Ql; Fri, 13 Mar 2026 19:36:00 -0400 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 <3W5-0aQQKCsAxqoxmuumrk.iuswks0-jk1krtutmt0.uxm@flex--rkir.bounces.google.com>) id 1w1C2x-0000cI-Jm for qemu-devel@nongnu.org; Fri, 13 Mar 2026 19:35:59 -0400 Received: from mail-pg1-x54a.google.com ([2607:f8b0:4864:20::54a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3W5-0aQQKCsAxqoxmuumrk.iuswks0-jk1krtutmt0.uxm@flex--rkir.bounces.google.com>) id 1w1C2w-0002sS-5e for qemu-devel@nongnu.org; Fri, 13 Mar 2026 19:35:59 -0400 Received: by mail-pg1-x54a.google.com with SMTP id 41be03b00d2f7-c739120475fso1449286a12.3 for ; Fri, 13 Mar 2026 16:35:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1773444956; x=1774049756; darn=nongnu.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=SAPEylkIV0nBuTHJQyf+c/OAybfX0uEC9xGFY7/Ve7M=; b=wBXZTpIMivpHbPLAc+6Rgk2J1GyM6n5sMPRZ7pUxpLVJFXQWnDmQTw3U+it2+1dyAD 1k3ymn6svkm3qOQCWvNfJz0m0C6xJ5ZDSU3g40z+ViLSS3s3XFluejQCdyS/V4A7zIZ/ Kuw7HlJGbtlmev7Kn5eh9S+FOIfYNwc0BiF135VsLBftf6Nh7VL3nP5xQM6wAl9uBDm5 D/+h8jW4EmEMh9SFV6v7WkkOnBx9qLybSzA6ptYq2sMr9jpny1rUZm9YZf4UmCKsJEFc BbG5NjD7ELtB7UGntjYZNn0iRWf8DvCxMg4JQDeS8o2vxxfn0UBwaPc9k5BVQuYqZzfn 2TfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773444956; x=1774049756; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=SAPEylkIV0nBuTHJQyf+c/OAybfX0uEC9xGFY7/Ve7M=; b=MOcZu0hvBJkO5QmK8aNUzopnn0f9aD11/D54uO/SQt0A+3ByFAP3VqXkHHz0Rj+0wh qKU/VQLlHLV9GaHxPH5WErS3yndjDsxQ+ybdGN56hVsdnhGx9sfcqF+YrOdLQ3x2yTtT I+ojt4QShNNAJPLKl+ELHDCM0ern47FIJEerFKZRIWThjgApUFXEuFR/OUSoMLu5Lv2P VxU/QSHWQoQ+iwf/nKjPkaFEZMXFugBoZLtYsSAs2wcnWeyuJWWqZ2VJr5JtQN/Gzada Xq7FH7O+VuhYheffOt2NRmeMpN1xqZTK00Ic+YQlzUwSaOkXKK5/P0j+hAKf3tH8ZLo7 k0cQ== X-Gm-Message-State: AOJu0YwpSpCfBespipibSEjsgH87asaeHKNlpxQvE9/Qm9hhIGqbZK9V cg0XfT/AwXNV9dZFUJeXC36NYXIGZqAmQgQkrpEfnC0PaejSK4terCunr7zzpbXSWtqfvIHWXA= = X-Received: from pgar3.prod.google.com ([2002:a05:6a02:2e83:b0:c73:cc95:c0be]) (user=rkir job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a21:1805:b0:398:9794:3309 with SMTP id adf61e73a8af0-398eca10f57mr4527080637.10.1773444955733; Fri, 13 Mar 2026 16:35:55 -0700 (PDT) Date: Fri, 13 Mar 2026 23:35:38 +0000 Mime-Version: 1.0 X-Mailer: git-send-email 2.53.0.851.ga537e3e6e9-goog Message-ID: <20260313233538.1519319-1-rkir@google.com> Subject: [PATCH v3] vmstate: validate VMStateDescription::fields upon registration From: Roman Kiryanov To: peterx@redhat.com, farosas@suse.de Cc: qemu-devel@nongnu.org, whollins@google.com, jansene@google.com, jpcottin@google.com, Roman Kiryanov 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=2607:f8b0:4864:20::54a; envelope-from=3W5-0aQQKCsAxqoxmuumrk.iuswks0-jk1krtutmt0.uxm@flex--rkir.bounces.google.com; helo=mail-pg1-x54a.google.com X-Spam_score_int: -95 X-Spam_score: -9.6 X-Spam_bar: --------- X-Spam_report: (-9.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, USER_IN_DEF_DKIM_WL=-7.5 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: qemu development 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-ZohoMail-DKIM: pass (identity @google.com) X-ZM-MESSAGEID: 1773444971659158500 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The vmstate_save_state_v() function does not support NULL in VMStateDescription::fields and will crash if one is provided. This change prevents this situation from happening by explicitly crashing earlier. Suggested-by: Fabiano Rosas Reviewed-by: Peter Xu Signed-off-by: Roman Kiryanov --- v3: - Also added assert to virtio.c to validate VirtioDeviceClass instances which bypass vmstate_register_with_alias_id. - Updated the commit message to "Reviewed-by". v2: - Moved the assert from vmstate_save_state_v to the registration path (vmstate_register_with_alias_id) and the qtest validation path (vmstate_check) to catch missing fields earlier. --- hw/virtio/virtio.c | 6 ++++++ migration/savevm.c | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index 0ba734d0bc..e4543de335 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -4054,6 +4054,12 @@ static void virtio_device_realize(DeviceState *dev, = Error **errp) /* Devices should either use vmsd or the load/save methods */ assert(!vdc->vmsd || !vdc->load); =20 + /* + * If a device has vmsd, it either MUST have valid fields + * or marked unmigratable. + */ + assert(!vdc->vmsd || (vdc->vmsd->unmigratable || vdc->vmsd->fields)); + if (vdc->realize !=3D NULL) { vdc->realize(dev, &err); if (err !=3D NULL) { diff --git a/migration/savevm.c b/migration/savevm.c index 197c89e0e6..20c2b99231 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -861,6 +861,8 @@ static void vmstate_check(const VMStateDescription *vms= d) const VMStateField *field =3D vmsd->fields; const VMStateDescription * const *subsection =3D vmsd->subsections; =20 + assert(field || vmsd->unmigratable); + if (field) { while (field->name) { if (field->flags & (VMS_STRUCT | VMS_VSTRUCT)) { @@ -900,6 +902,9 @@ int vmstate_register_with_alias_id(VMStateIf *obj, uint= 32_t instance_id, /* If this triggers, alias support can be dropped for the vmsd. */ assert(alias_id =3D=3D -1 || required_for_version >=3D vmsd->minimum_v= ersion_id); =20 + /* If vmsd is migratable it MUST have valid fields. */ + assert(vmsd->fields || vmsd->unmigratable); + se =3D g_new0(SaveStateEntry, 1); se->version_id =3D vmsd->version_id; se->section_id =3D savevm_state.global_section_id++; --=20 2.53.0.851.ga537e3e6e9-goog