qemu with hax to log dma reads & writes jcs.org/2018/11/12/vfio

x86: Fix x86_cpu_new() error handling

The Error ** argument must be NULL, &error_abort, &error_fatal, or a
pointer to a variable containing NULL. Passing an argument of the
latter kind twice without clearing it in between is wrong: if the
first call sets an error, it no longer points to NULL for the second
call.

x86_cpu_new() is wrong that way: it passes &local_err to
object_property_set_uint() without checking it, and then to
qdev_realize(). If both fail, we'll trip error_setv()'s assertion.
To assess the bug's impact, we'd need to figure out how to make both
calls fail. Too much work for ignorant me, sorry.

Fix by checking for failure right away.

Cc: Igor Mammedov <imammedo@redhat.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Richard Henderson <rth@twiddle.net>
Cc: Eduardo Habkost <ehabkost@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <20200630090351.1247703-21-armbru@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>

+5 -3
+5 -3
hw/i386/x86.c
··· 118 118 119 119 void x86_cpu_new(X86MachineState *x86ms, int64_t apic_id, Error **errp) 120 120 { 121 - Object *cpu = NULL; 122 121 Error *local_err = NULL; 123 - 124 - cpu = object_new(MACHINE(x86ms)->cpu_type); 122 + Object *cpu = object_new(MACHINE(x86ms)->cpu_type); 125 123 126 124 object_property_set_uint(cpu, apic_id, "apic-id", &local_err); 125 + if (local_err) { 126 + goto out; 127 + } 127 128 qdev_realize(DEVICE(cpu), NULL, &local_err); 128 129 130 + out: 129 131 object_unref(cpu); 130 132 error_propagate(errp, local_err); 131 133 }