Skip to contentSkip to conversation

vmstate: assert that VMStateDescription::fields is not NULL

PATCH In review Roman Kiryanov 3 participants 4 messages Mar 9 – Mar 12

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 vmstate: assert that VMStateDescription::fields is not NULL

The vmstate_save_state_v() function does not
support NULL in VMStateDescription::fields
and will crash if one is provided.

---
 migration/vmstate.c | 1 +
 1 file changed, 1 insertion(+)
migration/vmstate.c +1 -0
index 4d28364f7b..5cb173ea25 100644
@@ -433,6 +433,7 @@ int vmstate_save_state_v(QEMUFile *f, const VMStateDescription *vmsd,
     ERRP_GUARD();
     int ret = 0;
     const VMStateField *field = vmsd->fields;
+    assert(field);
 
     trace_vmstate_save_state_top(vmsd->name);
 
Signature · 1 line
2.53.0.851.ga537e3e6e9-goog
#1 lore raw
Quoted 5 lines · Roman Kiryanov

The vmstate_save_state_v() function does not
support NULL in VMStateDescription::fields
and will crash if one is provided.

Thanks for the patch.

Yeah I think assert it is fine, but maybe unnecessary, because we have a lot of such in QEMU (and IIUC in most userspace apps, likely even kernel is the same..) where we assert by directly reference it as a pointer..

Here, the assert() only helps to crash slightly earlier, rather than the field->name reference later.. While in both cases it'll be crystal clear on what has happened when a QEMU coredump is generated, either at assert(), or a few instructions later.

PS: please always copy Fabiano when sending migration patches.

Thanks,

Quoted 19 lines
---
 migration/vmstate.c | 1 +
 1 file changed, 1 insertion(+)
migration/vmstate.c +1 -0
index 4d28364f7b..5cb173ea25 100644
@@ -433,6 +433,7 @@ int vmstate_save_state_v(QEMUFile *f, const VMStateDescription *vmsd,
     ERRP_GUARD();
     int ret = 0;
     const VMStateField *field = vmsd->fields;
+    assert(field);
 
     trace_vmstate_save_state_top(vmsd->name);
 
Signature · 1 line
2.53.0.851.ga537e3e6e9-goog
Signature · 1 line
Peter Xu
#2 lore raw
Quoted 13 lines · Peter Xu
Quoted 5 lines · Roman Kiryanov

The vmstate_save_state_v() function does not
support NULL in VMStateDescription::fields
and will crash if one is provided.

Thanks for the patch.

Yeah I think assert it is fine, but maybe unnecessary, because we have a lot of such in QEMU (and IIUC in most userspace apps, likely even kernel is the same..) where we assert by directly reference it as a pointer..

Quoted 7 lines

Here, the assert() only helps to crash slightly earlier, rather than the field->name reference later.. While in both cases it'll be crystal clear on what has happened when a QEMU coredump is generated, either at assert(), or a few instructions later.

PS: please always copy Fabiano when sending migration patches.

I'd rather have a (vmsd->fields || vmsd->unmigratable) check when registering.

#3 lore raw
Quoted 6 lines · Fabiano Rosas
Quoted 2 lines · Peter Xu

Here, the assert() only helps to crash slightly earlier, rather than the field->name reference later..

I'd rather have a (vmsd->fields || vmsd->unmigratable) check when registering.

Hi Peter and Fabiano, thank you for looking into this.

Yes, I agree that validating VMStateDescription upon registration is a much better idea. I will send an updated patch.