Miscellaneous error handling fixes
cover Miscellaneous error handling fixes
Maintainers decide whether any of these are serious enough to still go into 5.0. I doubt it.
Markus Armbruster (11):
cryptodev: Fix cryptodev_builtin_cleanup() error API violation block/file-posix: Fix check_cache_dropped() error handling
cpus: Fix configure_icount() error API violation
cpus: Proper range-checking for -icount shift=N arm/virt: Fix virt_machine_device_plug_cb() error API violation
fdc: Fix fallback=auto error handling
bochs-display: Fix vgamem=SIZE error handling
virtio-net: Fix duplex=... and speed=... error handling xen/pt: Fix flawed conversion to realize()
io: Fix qio_channel_socket_close() error handling migration/colo: Fix qmp_xen_colo_do_checkpoint() error handling
backends/cryptodev-builtin.c | 10 ++----- block/file-posix.c | 5 +++- cpus.c | 52 +++++++++++++++++++++--------------- hw/arm/virt.c | 4 +-- hw/block/fdc.c | 1 + hw/display/bochs-display.c | 6 +++-- hw/net/virtio-net.c | 5 +++- hw/xen/xen_pt.c | 12 ++++----- io/channel-socket.c | 5 ++-- migration/colo.c | 8 +++++- 10 files changed, 63 insertions(+), 45 deletions(-)
Signature · 1 line
2.21.1
PATCH 1/11 cryptodev: Fix cryptodev_builtin_cleanup() error API violation
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.
cryptodev_builtin_cleanup() passes @errp to cryptodev_builtin_sym_close_session() in a loop. Harmless, because cryptodev_builtin_sym_close_session() can't actually fail. Fix it anyway.
--- backends/cryptodev-builtin.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-)
backends/cryptodev-builtin.c +2 -8
@@ -282,12 +282,7 @@ static int cryptodev_builtin_sym_close_session(CryptoDevBackendBuiltin *builtin =CRYPTODEV_BACKEND_BUILTIN (backend); -if (session_id >=MAX_NUM_SESSIONS || - builtin->sessions[session_id] ==NULL ) { -error_setg (errp,"Cannot find a valid session id: %" PRIu64"" , - session_id); -return -1 ; - } +assert (session_id <MAX_NUM_SESSIONS && builtin->sessions[session_id]);qcrypto_cipher_free (builtin->sessions[session_id]->cipher);g_free (builtin->sessions[session_id]);
@@ -356,8 +351,7 @@ static void cryptodev_builtin_cleanup(for (i =0 ; i <MAX_NUM_SESSIONS ; i++) {if (builtin->sessions[i] !=NULL ) { -cryptodev_builtin_sym_close_session ( - backend, i,0 , errp); +cryptodev_builtin_sym_close_session (backend, i,0 , &error_abort); } }
Signature · 1 line
2.21.1
PATCH 2/11 block/file-posix: Fix check_cache_dropped() error handling
In reply to Markus ArmbrusterThe 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.
check_cache_dropped() calls error_setg() in a loop. It fails to break the loop in one instance. If a subsequent iteration error_setg()s again, it trips error_setv()'s assertion.
Fix it to break the loop.
--- block/file-posix.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
block/file-posix.c +4 -1
@@ -2691,10 +2691,13 @@ static void check_cache_dropped(BlockDriverState *bs, Error **errp) vec_end =DIV_ROUND_UP (length, page_size);for (i =0 ; i < vec_end; i++) {if (vec[i] &0x1 ) { -error_setg (errp,"page cache still in use!" );break ; } } +if (i < vec_end) { +error_setg (errp,"page cache still in use!" ); +break ; + } }if (window) {
Signature · 1 line
2.21.1
Re: [PATCH 02/11] block/file-posix: Fix check_cache_dropped() error handling
Quoted 10 lines · Markus Armbruster
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.
check_cache_dropped()callserror_setg()in a loop. It fails to break the loop in one instance. If a subsequent iteration error_setg()s again, it trips error_setv()'s assertion.
Quoted 8 lines
Fix it to break the loop.
Fixes 31be8a2a97ecba7d31a82932286489cac318e9e9Cc Stefan Hajnoczi <[email protected]>Signed-off-by Markus Armbruster <[email protected]>--- block/file-posix.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
Doesn't seem to be a fresh regression in 5.0 (present since 3.0), so no need to rush it in before 5.1.
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
PATCH 3/11 cpus: Fix configure_icount() error API violation
In reply to Markus ArmbrusterThe 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.
configure_icount() is wrong that way. Harmless, because its @errp is always &error_abort or &error_fatal.
Just as wrong (and just as harmless): when it fails, it can still update global state.
Fix all that.
--- cpus.c | 51 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 30 insertions(+), 21 deletions(-)
cpus.c +30 -21
@@ -797,40 +797,49 @@ void cpu_ticks_init(void)void configure_icount (QemuOpts *opts,Error **errp) { -const char *option; +const char *option =qemu_opt_get (opts,"shift" ); +bool sleep =qemu_opt_get_bool (opts,"sleep" , true); +bool align =qemu_opt_get_bool (opts,"align" , false); +long time_shift =-1 ;char *rem_str =NULL ; - option =qemu_opt_get (opts,"shift" ); -if (!option) { -if (qemu_opt_get (opts,"align" ) !=NULL ) { -error_setg (errp,"Please specify shift option when using align" ); - } +if (!option &&qemu_opt_get (opts,"align" )) { +error_setg (errp,"Please specify shift option when using align" );return ; } - icount_sleep =qemu_opt_get_bool (opts,"sleep" , true); +if (align && !sleep) { +error_setg (errp,"align=on and sleep=off are incompatible" ); +return ; + } + +if (strcmp (option,"auto" ) !=0 ) { + errno =0 ; + time_shift =strtol (option, &rem_str,0 ); +if (errno !=0 || *rem_str !='\0' || !strlen (option)) { +error_setg (errp,"icount: Invalid shift value" ); +return ; + } + }else if (icount_align_option) { +error_setg (errp,"shift=auto and align=on are incompatible" ); +return ; + }else if (!icount_sleep) { +error_setg (errp,"shift=auto and sleep=off are incompatible" ); +return ; + } + + icount_sleep = sleep;if (icount_sleep) { timers_state.icount_warp_timer =timer_new_ns (QEMU_CLOCK_VIRTUAL_RT , icount_timer_cb,NULL ); } - icount_align_option =qemu_opt_get_bool (opts,"align" , false); + icount_align_option = align; -if (icount_align_option && !icount_sleep) { -error_setg (errp,"align=on and sleep=off are incompatible" ); - } -if (strcmp (option,"auto" ) !=0 ) { - errno =0 ; - timers_state.icount_time_shift =strtol (option, &rem_str,0 ); -if (errno !=0 || *rem_str !='\0' || !strlen (option)) { -error_setg (errp,"icount: Invalid shift value" ); - } +if (time_shift >=0 ) { + timers_state.icount_time_shift = time_shift; use_icount =1 ;return ; - }else if (icount_align_option) { -error_setg (errp,"shift=auto and align=on are incompatible" ); - }else if (!icount_sleep) { -error_setg (errp,"shift=auto and sleep=off are incompatible" ); } use_icount =2 ;
Signature · 1 line
2.21.1
PATCH 4/11 cpus: Proper range-checking for -icount shift=N
In reply to Markus Armbrustertimers_state.icount_time_shift must be in [0,63] to avoid undefined behavior when shifting by it, e.g. in cpu_icount_to_ns(). icount_adjust() clamps it to [0,MAX_ICOUNT_SHIFT], with MAX_ICOUNT_SHIFT = 10. configure_icount() doesn't. Fix that.
--- cpus.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
cpus.c +3 -4
@@ -25,6 +25,7 @@#include "qemu/osdep.h" #include "qemu-common.h" #include "qemu/config-file.h" +#include "qemu/cutils.h" #include "migration/vmstate.h" #include "monitor/monitor.h" #include "qapi/error.h"
@@ -801,7 +802,6 @@ void configure_icount(QemuOpts *opts, Error **errp)bool sleep =qemu_opt_get_bool (opts,"sleep" , true);bool align =qemu_opt_get_bool (opts,"align" , false);long time_shift =-1 ; -char *rem_str =NULL ;if (!option &&qemu_opt_get (opts,"align" )) {error_setg (errp,"Please specify shift option when using align" );
@@ -814,9 +814,8 @@ void configure_icount(QemuOpts *opts, Error **errp) }if (strcmp (option,"auto" ) !=0 ) { - errno =0 ; - time_shift =strtol (option, &rem_str,0 ); -if (errno !=0 || *rem_str !='\0' || !strlen (option)) { +if (qemu_strtol (option,NULL ,0 , &time_shift) <0 + || time_shift <0 || time_shift >MAX_ICOUNT_SHIFT ) {error_setg (errp,"icount: Invalid shift value" );return ; }
Signature · 1 line
2.21.1
PATCH 5/11 arm/virt: Fix virt_machine_device_plug_cb() error API violation
In reply to Markus ArmbrusterThe 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.
virt_machine_device_plug_cb() passes @errp to cryptodev_builtin_sym_close_session() in a loop. Harmless, because cryptodev_builtin_sym_close_session() can't actually fail. Fix by dropping its Error ** parameter.
--- hw/arm/virt.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
hw/arm/virt.c +2 -2
@@ -1186,7 +1186,7 @@ static void create_smmu(const VirtMachineState *vms,g_free (node); } -static void create_virtio_iommu_dt_bindings (VirtMachineState *vms,Error **errp) +static void create_virtio_iommu_dt_bindings (VirtMachineState *vms) {const char compat[] ="virtio,pci-iommu" ;uint16_t bdf = vms->virtio_iommu_bdf;
@@ -2118,7 +2118,7 @@ static void virt_machine_device_plug_cb(HotplugHandler *hotplug_dev, vms->iommu =VIRT_IOMMU_VIRTIO ; vms->virtio_iommu_bdf =pci_get_bdf (pdev); -create_virtio_iommu_dt_bindings (vms, errp); +create_virtio_iommu_dt_bindings (vms); } }
Signature · 1 line
2.21.1
Re: [PATCH 05/11] arm/virt: Fix virt_machine_device_plug_cb() error API violation
Quoted 6 lines · Markus Armbruster
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.
Quoted 8 lines
virt_machine_device_plug_cb()passes @errp tocryptodev_builtin_sym_close_session()in a loop. Harmless, becausecryptodev_builtin_sym_close_session()can't actually fail. Fix by dropping its Error ** parameter.Cc Peter Maydell <[email protected]>Signed-off-by Markus Armbruster <[email protected]>
Quoted 27 lines
--- hw/arm/virt.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)hw/arm/virt.c +2
-2@@ -1186,7 +1186,7 @@ static void create_smmu(const VirtMachineState *vms,g_free (node); } -static void create_virtio_iommu_dt_bindings (VirtMachineState *vms,Error **errp) +static void create_virtio_iommu_dt_bindings (VirtMachineState *vms) {const char compat[] ="virtio,pci-iommu" ;uint16_t bdf = vms->virtio_iommu_bdf;@@ -2118,7 +2118,7 @@ static void virt_machine_device_plug_cb(HotplugHandler *hotplug_dev, vms->iommu =VIRT_IOMMU_VIRTIO ; vms->virtio_iommu_bdf =pci_get_bdf (pdev); -create_virtio_iommu_dt_bindings (vms, errp); +create_virtio_iommu_dt_bindings (vms); } }
PATCH 6/11 fdc: Fix fallback=auto error handling
In reply to Markus Armbrusterfdctrl_realize_common() rejects fallback=auto. Used by devices "isa-fdc", "sysbus-fdc", "SUNW,fdtwo". The error handling is broken:
$ qemu-system-x86_64 -nodefaults -device isa-fdc,fallback=auto,driveA=fd0 -drive if=none,id=fd0
**
ERROR:/work/armbru/qemu/hw/block/fdc.c:434:pick_drive_type: assertion failed: (drv->drive != FLOPPY_DRIVE_TYPE_AUTO)
Aborted (core dumped)Cause: fdctrl_realize_common() neglects to bail out after setting the error. Fix that.
--- hw/block/fdc.c | 1 + 1 file changed, 1 insertion(+)
hw/block/fdc.c +1 -0
@@ -2615,6 +2615,7 @@ static void fdctrl_realize_common(DeviceState *dev, FDCtrl *fdctrl,if (fdctrl->fallback ==FLOPPY_DRIVE_TYPE_AUTO ) {error_setg (errp,"Cannot choose a fallback FDrive type of 'auto'" ); +return ; }/* Fill 'command_to_handler' lookup table */
Signature · 1 line
2.21.1
Re: [PATCH 06/11] fdc: Fix fallback=auto error handling
Quoted 24 lines · Markus Armbruster
fdctrl_realize_common()rejects fallback=auto. Used by devices "isa-fdc", "sysbus-fdc", "SUNW,fdtwo". The error handling is broken:$ qemu-system-x86_64 -nodefaults -device isa-fdc,fallback=auto,driveA=fd0 -drive if=none,id=fd0 ** ERROR:/work/armbru/qemu/hw/block/fdc.c:434:pick_drive_type: assertion failed: (drv->drive != FLOPPY_DRIVE_TYPE_AUTO) Aborted (core dumped)Cause:
fdctrl_realize_common()neglects to bail out after setting the error. Fix that.Fixes a73275dd6fc3bfda33165bebc28e0c33c20cb0a0Cc John Snow <[email protected]>Signed-off-by Markus Armbruster <[email protected]>--- hw/block/fdc.c | 1 + 1 file changed, 1 insertion(+)hw/block/fdc.c +0
-0
hw/block/fdc.c static void fdctrl_realize_common(DeviceState *dev, FDCtrl *fdctrl, · line 2621
Quoted 7 lines
hw/block/fdc.c +1
-0@@ -2615,6 +2615,7 @@ static void fdctrl_realize_common(DeviceState *dev, FDCtrl *fdctrl,if (fdctrl->fallback ==FLOPPY_DRIVE_TYPE_AUTO ) {error_setg (errp,"Cannot choose a fallback FDrive type of 'auto'" ); +return ; }/* Fill 'command_to_handler' lookup table */
PATCH 7/11 bochs-display: Fix vgamem=SIZE error handling
In reply to Markus Armbrusterbochs_display_realize() rejects out-of-range vgamem. The error handling is broken:
$ qemu-system-x86_64 -S -display none -monitor stdio
QEMU 4.2.93 monitor - type 'help' for more information
(qemu) device_add bochs-display,vgamem=1
Error: bochs-display: video memory too small
(qemu) device_add bochs-display,vgamem=1
RAMBlock "0000:00:04.0/bochs-display-vram" already registered, abort!
Aborted (core dumped)Cause: bochs_display_realize() neglects to bail out after setting the error. Fix that.
--- hw/display/bochs-display.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
hw/display/bochs-display.c +4 -2
@@ -267,16 +267,18 @@ static void bochs_display_realize(PCIDevice *dev, Error **errp)Object *obj =OBJECT (dev);int ret; - s->con =graphic_console_init (DEVICE (dev),0 , &bochs_display_gfx_ops, s); -if (s->vgamem <4 * MiB) {error_setg (errp,"bochs-display: video memory too small" ); +return ; }if (s->vgamem >256 * MiB) {error_setg (errp,"bochs-display: video memory too big" ); +return ; } s->vgamem =pow2ceil (s->vgamem); + s->con =graphic_console_init (DEVICE (dev),0 , &bochs_display_gfx_ops, s); +memory_region_init_ram (&s->vram, obj,"bochs-display-vram" , s->vgamem, &error_fatal); memory_region_init_io(&s->vbe, obj, &bochs_display_vbe_ops, s,
Signature · 1 line
2.21.1
Re: [PATCH 07/11] bochs-display: Fix vgamem=SIZE error handling
Quoted 37 lines · Markus Armbruster
bochs_display_realize()rejects out-of-range vgamem. The error handling is broken:$ qemu-system-x86_64 -S -display none -monitor stdio QEMU 4.2.93 monitor - type 'help' for more information (qemu) device_add bochs-display,vgamem=1 Error: bochs-display: video memory too small (qemu) device_add bochs-display,vgamem=1 RAMBlock "0000:00:04.0/bochs-display-vram" already registered, abort! Aborted (core dumped)Cause:
bochs_display_realize()neglects to bail out after setting the error. Fix that.Fixes 765c94290863eef1fc4a67819d452cc13b7854a1Cc Gerd Hoffmann <[email protected]>Signed-off-by Markus Armbruster <[email protected]>--- hw/display/bochs-display.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)hw/display/bochs-display.c +1
-2@@ -267,16 +267,18 @@ static void bochs_display_realize(PCIDevice *dev, Error **errp)Object *obj =OBJECT (dev);int ret; - s->con =graphic_console_init (DEVICE (dev),0 , &bochs_display_gfx_ops, s); -if (s->vgamem <4 * MiB) {error_setg (errp,"bochs-display: video memory too small" ); +return ; }if (s->vgamem >256 * MiB) {
hw/display/bochs-display.c static void bochs_display_realize(PCIDevice *dev, Error **errp) · line 284
Quoted 10 lines
hw/display/bochs-display.c +3
-0error_setg (errp,"bochs-display: video memory too big" ); +return ; } s->vgamem =pow2ceil (s->vgamem); + s->con =graphic_console_init (DEVICE (dev),0 , &bochs_display_gfx_ops, s); +memory_region_init_ram (&s->vram, obj,"bochs-display-vram" , s->vgamem, &error_fatal); memory_region_init_io(&s->vbe, obj, &bochs_display_vbe_ops, s,
PATCH 8/11 virtio-net: Fix duplex=... and speed=... error handling
In reply to Markus Armbrustervirtio_net_device_realize() rejects invalid duplex and speed values. The error handling is broken:
$ ../qemu/bld-sani/x86_64-softmmu/qemu-system-x86_64 -S -display none -monitor stdio
QEMU 4.2.93 monitor - type 'help' for more information
(qemu) device_add virtio-net,duplex=x
Error: 'duplex' must be 'half' or 'full'
(qemu) c
=================================================================
==15654==ERROR: AddressSanitizer: heap-use-after-free on address 0x62e000014590 at pc 0x560b75c8dc13 bp 0x7fffdf1a6950 sp 0x7fffdf1a6940
READ of size 8 at 0x62e000014590 thread T0
#0 0x560b75c8dc12 in object_dynamic_cast_assert /work/armbru/qemu/qom/object.c:826
#1 0x560b74c38ac0 in virtio_vmstate_change /work/armbru/qemu/hw/virtio/virtio.c:3210
#2 0x560b74d9765e in vm_state_notify /work/armbru/qemu/softmmu/vl.c:1271
#3 0x560b7494ba72 in vm_prepare_start /work/armbru/qemu/cpus.c:2156
#4 0x560b7494bacd in vm_start /work/armbru/qemu/cpus.c:2162
#5 0x560b75a7d890 in qmp_cont /work/armbru/qemu/monitor/qmp-cmds.c:160
#6 0x560b75a8d70a in hmp_cont /work/armbru/qemu/monitor/hmp-cmds.c:1043
#7 0x560b75a799f2 in handle_hmp_command /work/armbru/qemu/monitor/hmp.c:1082
[...] 0x62e000014590 is located 33168 bytes inside of 42288-byte region [0x62e00000c400,0x62e000016930)
freed by thread T1 here:
#0 0x7feadd39491f in __interceptor_free (/lib64/libasan.so.5+0x10d91f)
#1 0x7feadcebcd7c in g_free (/lib64/libglib-2.0.so.0+0x55d7c)
#2 0x560b75c8fd40 in object_unref /work/armbru/qemu/qom/object.c:1128
#3 0x560b7498a625 in memory_region_unref /work/armbru/qemu/memory.c:1762
#4 0x560b74999fa4 in do_address_space_destroy /work/armbru/qemu/memory.c:2788
#5 0x560b762362fc in call_rcu_thread /work/armbru/qemu/util/rcu.c:283
#6 0x560b761c8884 in qemu_thread_start /work/armbru/qemu/util/qemu-thread-posix.c:519
#7 0x7fead9be34bf in start_thread (/lib64/libpthread.so.0+0x84bf)
previously allocated by thread T0 here:
#0 0x7feadd394d18 in __interceptor_malloc (/lib64/libasan.so.5+0x10dd18)
#1 0x7feadcebcc88 in g_malloc (/lib64/libglib-2.0.so.0+0x55c88)
#2 0x560b75c8cf8a in object_new /work/armbru/qemu/qom/object.c:699
#3 0x560b75010ad9 in qdev_device_add /work/armbru/qemu/qdev-monitor.c:654
#4 0x560b750120c2 in qmp_device_add /work/armbru/qemu/qdev-monitor.c:805
#5 0x560b75012c1b in hmp_device_add /work/armbru/qemu/qdev-monitor.c:905
[...]
==15654==ABORTINGCause: virtio_net_device_realize() neglects to bail out after setting the error. Fix that.
--- hw/net/virtio-net.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
hw/net/virtio-net.c +4 -1
@@ -2947,6 +2947,7 @@ static void virtio_net_device_realize(DeviceState *dev, Error **errp) n->net_conf.duplex =DUPLEX_FULL ; }else {error_setg (errp,"'duplex' must be 'half' or 'full'" ); +return ; } n->host_features |= (1ULL <<VIRTIO_NET_F_SPEED_DUPLEX ); }else {
@@ -2955,7 +2956,9 @@ static void virtio_net_device_realize(DeviceState *dev, Error **errp)if (n->net_conf.speed <SPEED_UNKNOWN ) {error_setg (errp,"'speed' must be between 0 and INT_MAX" ); - }else if (n->net_conf.speed >=0 ) { +return ; + } +if (n->net_conf.speed >=0 ) { n->host_features |= (1ULL <<VIRTIO_NET_F_SPEED_DUPLEX ); }
Signature · 1 line
2.21.1
Re: [PATCH 08/11] virtio-net: Fix duplex=... and speed=... error handling
Quoted 67 lines · Markus Armbruster
virtio_net_device_realize()rejects invalid duplex and speed values. The error handling is broken:$ ../qemu/bld-sani/x86_64-softmmu/qemu-system-x86_64 -S -display none -monitor stdio QEMU 4.2.93 monitor - type 'help' for more information (qemu) device_add virtio-net,duplex=x Error: 'duplex' must be 'half' or 'full' (qemu) c ================================================================= ==15654==ERROR: AddressSanitizer: heap-use-after-free on address 0x62e000014590 at pc 0x560b75c8dc13 bp 0x7fffdf1a6950 sp 0x7fffdf1a6940 READ of size 8 at 0x62e000014590 thread T0 #0 0x560b75c8dc12 in object_dynamic_cast_assert /work/armbru/qemu/qom/object.c:826 #1 0x560b74c38ac0 in virtio_vmstate_change /work/armbru/qemu/hw/virtio/virtio.c:3210 #2 0x560b74d9765e in vm_state_notify /work/armbru/qemu/softmmu/vl.c:1271 #3 0x560b7494ba72 in vm_prepare_start /work/armbru/qemu/cpus.c:2156 #4 0x560b7494bacd in vm_start /work/armbru/qemu/cpus.c:2162 #5 0x560b75a7d890 in qmp_cont /work/armbru/qemu/monitor/qmp-cmds.c:160 #6 0x560b75a8d70a in hmp_cont /work/armbru/qemu/monitor/hmp-cmds.c:1043 #7 0x560b75a799f2 in handle_hmp_command /work/armbru/qemu/monitor/hmp.c:1082 [...]0x62e000014590 is located 33168 bytes inside of 42288-byte region [0x62e00000c400,0x62e000016930) freed by thread T1 here: #0 0x7feadd39491f in __interceptor_free (/lib64/libasan.so.5+0x10d91f) #1 0x7feadcebcd7c in g_free (/lib64/libglib-2.0.so.0+0x55d7c) #2 0x560b75c8fd40 in object_unref /work/armbru/qemu/qom/object.c:1128 #3 0x560b7498a625 in memory_region_unref /work/armbru/qemu/memory.c:1762 #4 0x560b74999fa4 in do_address_space_destroy /work/armbru/qemu/memory.c:2788 #5 0x560b762362fc in call_rcu_thread /work/armbru/qemu/util/rcu.c:283 #6 0x560b761c8884 in qemu_thread_start /work/armbru/qemu/util/qemu-thread-posix.c:519 #7 0x7fead9be34bf in start_thread (/lib64/libpthread.so.0+0x84bf) previously allocated by thread T0 here: #0 0x7feadd394d18 in __interceptor_malloc (/lib64/libasan.so.5+0x10dd18) #1 0x7feadcebcc88 in g_malloc (/lib64/libglib-2.0.so.0+0x55c88) #2 0x560b75c8cf8a in object_new /work/armbru/qemu/qom/object.c:699 #3 0x560b75010ad9 in qdev_device_add /work/armbru/qemu/qdev-monitor.c:654 #4 0x560b750120c2 in qmp_device_add /work/armbru/qemu/qdev-monitor.c:805 #5 0x560b75012c1b in hmp_device_add /work/armbru/qemu/qdev-monitor.c:905 [...] ==15654==ABORTINGCause:
virtio_net_device_realize()neglects to bail out after setting the error. Fix that.Fixes 9473939ed7addcaaeb8fde5c093918fb7fa0919cCc "Michael S. Tsirkin" <[email protected]>Cc Jason Wang <[email protected]>Signed-off-by Markus Armbruster <[email protected]>--- hw/net/virtio-net.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)hw/net/virtio-net.c +1
-0@@ -2947,6 +2947,7 @@ static void virtio_net_device_realize(DeviceState *dev, Error **errp) n->net_conf.duplex =DUPLEX_FULL ; }else {error_setg (errp,"'duplex' must be 'half' or 'full'" ); +return ; } n->host_features |= (1ULL <<VIRTIO_NET_F_SPEED_DUPLEX ); }else {
hw/net/virtio-net.c static void virtio_net_device_realize(DeviceState *dev, Error **errp) · line 2964
Quoted 10 lines
hw/net/virtio-net.c +3
-1@@ -2955,7 +2956,9 @@ static void virtio_net_device_realize(DeviceState *dev, Error **errp)if (n->net_conf.speed <SPEED_UNKNOWN ) {error_setg (errp,"'speed' must be between 0 and INT_MAX" ); - }else if (n->net_conf.speed >=0 ) { +return ; + } +if (n->net_conf.speed >=0 ) { n->host_features |= (1ULL <<VIRTIO_NET_F_SPEED_DUPLEX ); }
PATCH 9/11 xen/pt: Fix flawed conversion to realize()
In reply to Markus ArmbrusterThe conversion of xen_pt_initfn() to xen_pt_realize() blindly replaced XEN_PT_ERR() by error_setg(). Several error conditions that did not fail xen_pt_initfn() now fail xen_pt_realize(). Unsurprisingly, the cleanup on these errors looks highly suspicious.
Revert the inappropriate replacements.
--- hw/xen/xen_pt.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
hw/xen/xen_pt.c +6 -6
@@ -858,8 +858,8 @@ static void xen_pt_realize(PCIDevice *d, Error **errp) rc =xc_physdev_map_pirq (xen_xc, xen_domid, machine_irq, &pirq);if (rc <0 ) { -error_setg_errno (errp, errno,"Mapping machine irq %u to" -" pirq %i failed" , machine_irq, pirq); +XEN_PT_ERR (d,"Mapping machine irq %u to pirq %i failed, (err: %d)\n" , + machine_irq, pirq, errno);/* Disable PCI intx assertion (turn on bit10 of devctl) */ cmd |=PCI_COMMAND_INTX_DISABLE ;
@@ -880,8 +880,8 @@ static void xen_pt_realize(PCIDevice *d, Error **errp)PCI_SLOT (d->devfn), e_intx);if (rc <0 ) { -error_setg_errno (errp, errno,"Binding of interrupt %u failed" , - e_intx); +XEN_PT_ERR (d,"Binding of interrupt %i failed! (err: %d)\n" , + e_intx, errno);/* Disable PCI intx assertion (turn on bit10 of devctl) */ cmd |=PCI_COMMAND_INTX_DISABLE ;
@@ -889,8 +889,8 @@ static void xen_pt_realize(PCIDevice *d, Error **errp)if (xen_pt_mapped_machine_irq[machine_irq] ==0 ) {if (xc_physdev_unmap_pirq (xen_xc, xen_domid, machine_irq)) { -error_setg_errno (errp, errno,"Unmapping of machine" -" interrupt %u failed" , machine_irq); +XEN_PT_ERR (d,"Unmapping of machine interrupt %i failed!" +" (err: %d)\n" , machine_irq, errno); } } s->machine_irq =0 ;
Signature · 1 line
2.21.1
RE: [PATCH 09/11] xen/pt: Fix flawed conversion to realize()
Quoted 13 lines
-----Original Message-----
From: Markus Armbruster <[email protected]>
Sent: 20 April 2020 09:33
To: [email protected]
Cc: Stefano Stabellini <[email protected]>; Anthony Perard <[email protected]>; Paul Durrant <[email protected]>; [email protected]
Subject: [PATCH 09/11] xen/pt: Fix flawed conversion torealize()The conversion of
xen_pt_initfn()toxen_pt_realize()blindly replacedXEN_PT_ERR()byerror_setg(). Several error conditions that did not failxen_pt_initfn()now failxen_pt_realize(). Unsurprisingly, the cleanup on these errors looks highly suspicious.
Quoted 8 lines
Revert the inappropriate replacements.
Fixes 5a11d0f7549e24a10e178a9dc8ff5e698031d9a6Cc Stefano Stabellini <[email protected]>Cc Anthony Perard <[email protected]>Cc Paul Durrant <[email protected]>Signed-off-by Markus Armbruster <[email protected]>
PATCH 10/11 io: Fix qio_channel_socket_close() error handling
In reply to Markus ArmbrusterThe 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.
qio_channel_socket_close() passes @errp first to socket_listen_cleanup(), and then, if closesocket() fails, to error_setg_errno(). If socket_listen_cleanup() failed, this will trip the assertion in error_setv().
Fix by ignoring a second error.
--- io/channel-socket.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
io/channel-socket.c +3 -2
@@ -704,6 +704,7 @@ qio_channel_socket_close(QIOChannel *ioc, {QIOChannelSocket *sioc =QIO_CHANNEL_SOCKET (ioc);int rc =0 ; +Error *err =NULL ;if (sioc->fd !=-1 ) {#ifdef WIN32
@@ -715,8 +716,8 @@ qio_channel_socket_close(QIOChannel *ioc,if (closesocket (sioc->fd) <0 ) { sioc->fd =-1 ; -error_setg_errno (errp, errno, -"Unable to close socket" ); +error_setg_errno (&err, errno,"Unable to close socket" ); +error_propagate (errp, err);return -1 ; } sioc->fd =-1 ;
Signature · 1 line
2.21.1
Re: [PATCH 10/11] io: Fix qio_channel_socket_close() error handling
Quoted 11 lines · Markus Armbruster
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.
qio_channel_socket_close()passes @errp first tosocket_listen_cleanup(), and then, ifclosesocket()fails, toerror_setg_errno(). Ifsocket_listen_cleanup()failed, this will trip the assertion inerror_setv().
Quoted 8 lines
Fix by ignoring a second error.
Fixes 73564c407caedf992a1c688b5fea776a8b56ba2aCc Daniel P. Berrangé <[email protected]>Signed-off-by Markus Armbruster <[email protected]>--- io/channel-socket.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
Regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
PATCH 11/11 migration/colo: Fix qmp_xen_colo_do_checkpoint() error handling
In reply to Markus ArmbrusterThe 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.
qmp_xen_colo_do_checkpoint() passes @errp first to replication_do_checkpoint_all(), and then to colo_notify_filters_event(). If both fail, this will trip the assertion in error_setv().
Similar code in secondary_vm_do_failover() calls colo_notify_filters_event() only after replication_do_checkpoint_all() succeeded. Do the same here.
--- migration/colo.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
migration/colo.c +7 -1
@@ -263,7 +263,13 @@ ReplicationStatus *qmp_query_xen_replication_status(Error **errp)void qmp_xen_colo_do_checkpoint (Error **errp) { -replication_do_checkpoint_all (errp); +Error *err =NULL ; + +replication_do_checkpoint_all (&err); +if (err) { +error_propagate (errp, err); +return ; + }/* Notify all filters of all NIC to do checkpoint */ colo_notify_filters_event (COLO_EVENT_CHECKPOINT , errp); }
Signature · 1 line
2.21.1
RE: [PATCH 11/11] migration/colo: Fix qmp_xen_colo_do_checkpoint() error handling
Quoted 54 lines
-----Original Message-----
From: Markus Armbruster [mailto:[email protected]]
Sent: Monday, April 20, 2020 4:33 PM
To: [email protected]
Cc: Zhang Chen <[email protected]>; Zhanghailiang <[email protected]>
Subject: [PATCH 11/11] migration/colo: Fixqmp_xen_colo_do_checkpoint()error handlingThe 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.
qmp_xen_colo_do_checkpoint()passes @errp first toreplication_do_checkpoint_all(), and then tocolo_notify_filters_event(). If both fail, this will trip the assertion inerror_setv().Similar code in
secondary_vm_do_failover()callscolo_notify_filters_event()only afterreplication_do_checkpoint_all()succeeded. Do the same here.Fixes 0e8818f023616677416840d6ddc880db8de3c967Cc Zhang Chen <[email protected]>Cc zhanghailiang <[email protected]>Signed-off-by Markus Armbruster <[email protected]>--- migration/colo.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)migration/colo.c +7
-1@@ -263,7 +263,13 @@ ReplicationStatus *qmp_query_xen_replication_status(Error **errp)void qmp_xen_colo_do_checkpoint (Error **errp) { -replication_do_checkpoint_all (errp); +Error *err =NULL ; + +replication_do_checkpoint_all (&err); +if (err) { +error_propagate (errp, err); +return ; + }/* Notify all filters of all NIC to do checkpoint */ colo_notify_filters_event (COLO_EVENT_CHECKPOINT , errp);}
--
2.21.1
Re: [PATCH 11/11] migration/colo: Fix qmp_xen_colo_do_checkpoint() error handling
In reply to Markus ArmbrusterQuoted 33 lines · Markus Armbruster
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.
qmp_xen_colo_do_checkpoint()passes @errp first toreplication_do_checkpoint_all(), and then tocolo_notify_filters_event(). If both fail, this will trip the assertion inerror_setv().Similar code in
secondary_vm_do_failover()callscolo_notify_filters_event()only afterreplication_do_checkpoint_all()succeeded. Do the same here.Fixes 0e8818f023616677416840d6ddc880db8de3c967Cc Zhang Chen <[email protected]>Cc zhanghailiang <[email protected]>Signed-off-by Markus Armbruster <[email protected]>--- migration/colo.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)migration/colo.c +0
-1@@ -263,7 +263,13 @@ ReplicationStatus *qmp_query_xen_replication_status(Error **errp)void qmp_xen_colo_do_checkpoint (Error **errp) { -replication_do_checkpoint_all (errp);
migration/colo.c ReplicationStatus *qmp_query_xen_replication_status(Error **errp) · line 275
Quoted 10 lines
migration/colo.c +7
-0+Error *err =NULL ; + +replication_do_checkpoint_all (&err); +if (err) { +error_propagate (errp, err); +return ; + }/* Notify all filters of all NIC to do checkpoint */ colo_notify_filters_event (COLO_EVENT_CHECKPOINT , errp); }
RE: [PATCH 11/11] migration/colo: Fix qmp_xen_colo_do_checkpoint() error handling
In reply to Markus ArmbrusterQuoted 20 lines
-----Original Message-----
From: Markus Armbruster <[email protected]>
Sent: Monday, April 20, 2020 4:33 PM
To: [email protected]
Cc: Zhang, Chen <[email protected]>; zhanghailiang <[email protected]>
Subject: [PATCH 11/11] migration/colo: Fixqmp_xen_colo_do_checkpoint()error handlingThe 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.
qmp_xen_colo_do_checkpoint()passes @errp first toreplication_do_checkpoint_all(), and then tocolo_notify_filters_event(). If both fail, this will trip the assertion inerror_setv().
Quoted 8 lines
Similar code in
secondary_vm_do_failover()callscolo_notify_filters_event()only afterreplication_do_checkpoint_all()succeeded. Do the same here.Fixes 0e8818f023616677416840d6ddc880db8de3c967Cc Zhang Chen <[email protected]>Cc zhanghailiang <[email protected]>Signed-off-by Markus Armbruster <[email protected]>
Looks good for me.
Thanks
Zhang Chen
Quoted 24 lines
--- migration/colo.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)migration/colo.c index a54ac84f41..1b3493729b renamed from migration/colo.c +0
-0100644
migration/colo.c +7
-2@@ -263,7 +263,13 @@ ReplicationStatus *qmp_query_xen_replication_status(Error **errp)void qmp_xen_colo_do_checkpoint (Error **errp) { -replication_do_checkpoint_all (errp); +Error *err =NULL ; + +replication_do_checkpoint_all (&err); +if (err) { +error_propagate (errp, err); +return ; + }/* Notify all filters of all NIC to do checkpoint */ colo_notify_filters_event (COLO_EVENT_CHECKPOINT , errp); } --2.21.1
Patchew URL: https://patchew.org/QEMU/[email protected]/
Patchew URL: https://patchew.org/QEMU/[email protected]/
Hi,
This series seems to have some coding style problems. See output below for more information:
Subject: [PATCH 00/11] Miscellaneous error handling fixes
Message-id: [email protected]
Type: series
=== TEST SCRIPT BEGIN ===
#!/bin/bash
git rev-parse base > /dev/null || exit 0
git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram./scripts/checkpatch.pl --mailback base..
=== TEST SCRIPT END ===
Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
Switched to a new branch 'test'
942181b migration/colo: Fix qmp_xen_colo_do_checkpoint() error handling a8c2f29 io: Fix qio_channel_socket_close() error handling cedb56e xen/pt: Fix flawed conversion to realize()
7173a0e virtio-net: Fix duplex=... and speed=... error handling 9c7afc3 bochs-display: Fix vgamem=SIZE error handling f3ad7d4 fdc: Fix fallback=auto error handling
e484e15 arm/virt: Fix virt_machine_device_plug_cb() error API violation 1c54f10 cpus: Proper range-checking for -icount shift=N 0a69dc4 cpus: Fix configure_icount() error API violation bafe5f5 block/file-posix: Fix check_cache_dropped() error handling a690fa1 cryptodev: Fix cryptodev_builtin_cleanup() error API violation
=== OUTPUT BEGIN ===
1/11 Checking commit a690fa1dc425 (cryptodev: Fix cryptodev_builtin_cleanup() error API violation) 2/11 Checking commit bafe5f5e9888 (block/file-posix: Fix check_cache_dropped() error handling) 3/11 Checking commit 0a69dc45007c (cpus: Fix configure_icount() error API violation)
ERROR: consider using qemu_strtol in preference to strtol
#58: FILE: cpus.c:818:
+ time_shift = strtol(option, &rem_str, 0);
total: 1 errors, 0 warnings, 70 lines checked
Patch 3/11 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
4/11 Checking commit 1c54f102aed3 (cpus: Proper range-checking for -icount shift=N) 5/11 Checking commit e484e1536ed7 (arm/virt: Fix virt_machine_device_plug_cb() error API violation) 6/11 Checking commit f3ad7d444a66 (fdc: Fix fallback=auto error handling)
7/11 Checking commit 9c7afc3c57a4 (bochs-display: Fix vgamem=SIZE error handling) 8/11 Checking commit 7173a0e399fd (virtio-net: Fix duplex=... and speed=... error handling) 9/11 Checking commit cedb56ec3da3 (xen/pt: Fix flawed conversion to realize())
10/11 Checking commit a8c2f294abb2 (io: Fix qio_channel_socket_close() error handling) 11/11 Checking commit 942181b72505 (migration/colo: Fix qmp_xen_colo_do_checkpoint() error handling) === OUTPUT END ===
Test command exited with code: 1
The full log is available at
http://patchew.org/logs/[email protected]/testing.checkpatch/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to [email protected]