From nobody Tue Apr 7 14:39:35 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=1773349742; cv=none; d=zohomail.com; s=zohoarc; b=QVgBOX05FQpqXa36GKLbGgZvQVQHkxjt5LoYicZajb1OKstapXAvzKpane6BBw4CQKdy3fnIYkyAgv0m6iqNWNZbxaxHkONnwjUwBuZPaE3ciju+fbk1MGaXzgqWbQ3HS0YvxGndvtYUL3vRttDMbevlZe6enECTyyOEU9ymdXY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1773349742; 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=dt3hntr+XMknIlkc9WyYiezvJf+IXkmVPBlpDR/PYCE=; b=NPY3mcREp/yMyAgSkVnasBebqodOD9WhUUKBory2rhm62ZpbNPxGg+H7+1pkkoYjrV0MyoeKguTSEVdoz+oZ1BIjK4heurqdiF5iAF8DT7XC1skijXnwj04WzsuGwr9EaGFd+LL6GO3m7GtC+bl7C0Is4bBgBEKVdOK1bJ/vlKU= 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 1773349742564848.5134692163491; Thu, 12 Mar 2026 14:09:02 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1w0nGv-0005tX-5L; Thu, 12 Mar 2026 17:08:45 -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 <3VCuzaQQKCss81z8x55x2v.t537v3B-uvCv2454x4B.58x@flex--rkir.bounces.google.com>) id 1w0nGt-0005tJ-Ba for qemu-devel@nongnu.org; Thu, 12 Mar 2026 17:08:43 -0400 Received: from mail-pl1-x64a.google.com ([2607:f8b0:4864:20::64a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3VCuzaQQKCss81z8x55x2v.t537v3B-uvCv2454x4B.58x@flex--rkir.bounces.google.com>) id 1w0nGr-0004JO-8N for qemu-devel@nongnu.org; Thu, 12 Mar 2026 17:08:42 -0400 Received: by mail-pl1-x64a.google.com with SMTP id d9443c01a7336-2aec6c572fbso44160045ad.1 for ; Thu, 12 Mar 2026 14:08:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1773349716; x=1773954516; darn=nongnu.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=dt3hntr+XMknIlkc9WyYiezvJf+IXkmVPBlpDR/PYCE=; b=xwhgKC98Hv9OSlfC1ZU5W4OO7vNliyX6tOR4VXKTXRj7FQ1f4czAcDV66qCdnocCgS lBN4/ViQ2dFOtU2IFzDGuy90bRBEcAEkYnAowLPDLe+mY53O1C6+xFdIfN+6JIGztTKX +If6US+74HPsyx24R14i+I0/0G/sbjqYo4szfRAhUcGIzjYjvV5ILXKkhdpehXdKjGA1 fuhzEDBL2LqwZY+Fi4AisC4d5/cWwRAirIyw2xLLGSvnWcWP2XU4tFR0AGUQLJ+fbUrb bO8QjCwRK4GKIOhhs7XNdaHCRX6ppKeFI/kHHqB98Ywnq0C2qyj7PjBd3L3yXYylKmvt EdPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1773349716; x=1773954516; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=dt3hntr+XMknIlkc9WyYiezvJf+IXkmVPBlpDR/PYCE=; b=oGf2zWc5/KBnrb9fNCxoVuXNNtnPQeTS/Cnspt6DjndOSKdHrfO9KhASA1398cI+NI gI28lOoc7F8EWN0dg4S+w6LOv649ajy04g42ylG/wNT+5Kyj/B9ylDuhM2g3ZDjA6r0/ 1IC6fgKjd/h8TgxIJYYsj12yUyGusOJKBGixbeUIyWQsXfrBWH2291xl04suZgZ5AvKU V4+b+U+vMFnyDKcpyQ6lt+X/ha+uBeL6/fWsRtCMykj91lG+JE7FTOH3F2j25+yW7dkv zJ2mdzF81Rk3tsjCRxUczfXfkZ+FwbY9T9ql7y5/xN8vICIEZwHSy5casHPtUv+T/rmT cSpA== X-Gm-Message-State: AOJu0YzKW8px/p3aC026P07/KgO6HIkk68SlJ9JRIiM7XdMAt/A2IVVp va3mLp/NnQjD4QSL4DT2U6oVL4XLXhoOYsZqRQi70ssVZqJTjWvY3ajqndCCeAkWpRhSoRBJdw= = X-Received: from plho15.prod.google.com ([2002:a17:903:23cf:b0:2a7:8c71:aa97]) (user=rkir job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:ea06:b0:2ae:4b91:8407 with SMTP id d9443c01a7336-2aecaaa861amr8020345ad.34.1773349716036; Thu, 12 Mar 2026 14:08:36 -0700 (PDT) Date: Thu, 12 Mar 2026 21:08:02 +0000 Mime-Version: 1.0 X-Mailer: git-send-email 2.53.0.851.ga537e3e6e9-goog Message-ID: <20260312210802.899803-1-rkir@google.com> Subject: [PATCH v2] 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::64a; envelope-from=3VCuzaQQKCss81z8x55x2v.t537v3B-uvCv2454x4B.58x@flex--rkir.bounces.google.com; helo=mail-pl1-x64a.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: 1773349743929158500 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 Suggested-by: Peter Xu Signed-off-by: Roman Kiryanov Reviewed-by: Peter Xu --- 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. --- migration/savevm.c | 5 +++++ 1 file changed, 5 insertions(+) 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