[libvirt] [PATCH] Initialization error of qemuCgroupData in Qemu host usb hotplug

Steps to reproduce this bug: # cat usb.xml <hostdev mode='subsystem' type='usb'> <source> <address bus='0x001' device='0x003'/> </source> </hostdev> # virsh attach-device vm1 usb.xml error: Failed to attach device from usb.xml error: server closed connection: The reason of this bug is that we set data.cgroup to NULL, and this will cause libvirtd crashed. Signed-off-by: Wen Congyang <wency@cn.fujitsu.com> --- src/qemu/qemu_hotplug.c | 4 +++- 1 files changed, 3 insertions(+), 1 deletions(-) diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 36b343d..9082515 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -860,7 +860,7 @@ int qemuDomainAttachHostUsbDevice(struct qemud_driver *driver, if (qemuCgroupControllerActive(driver, VIR_CGROUP_CONTROLLER_DEVICES)) { virCgroupPtr cgroup = NULL; usbDevice *usb; - qemuCgroupData data = { vm, cgroup }; + qemuCgroupData data; if (virCgroupForDomain(driver->cgroup, vm->def->name, &cgroup, 0) !=0 ) { qemuReportError(VIR_ERR_INTERNAL_ERROR, @@ -873,6 +873,8 @@ int qemuDomainAttachHostUsbDevice(struct qemud_driver *driver, hostdev->source.subsys.u.usb.device)) == NULL) goto error; + data.vm = vm; + data.cgroup = cgroup; if (usbDeviceFileIterate(usb, qemuSetupHostUsbDeviceCgroup, &data) < 0) goto error; } -- 1.7.1

On 03/22/2011 08:02 PM, Wen Congyang wrote:
Steps to reproduce this bug: # cat usb.xml <hostdev mode='subsystem' type='usb'> <source> <address bus='0x001' device='0x003'/> </source> </hostdev> # virsh attach-device vm1 usb.xml error: Failed to attach device from usb.xml error: server closed connection:
The reason of this bug is that we set data.cgroup to NULL, and this will cause libvirtd crashed.
usbDevice *usb; - qemuCgroupData data = { vm, cgroup }; + qemuCgroupData data;
if (virCgroupForDomain(driver->cgroup, vm->def->name, &cgroup, 0) !=0 ) { qemuReportError(VIR_ERR_INTERNAL_ERROR, @@ -873,6 +873,8 @@ int qemuDomainAttachHostUsbDevice(struct qemud_driver *driver, hostdev->source.subsys.u.usb.device)) == NULL) goto error;
+ data.vm = vm; + data.cgroup = cgroup;
ACK. Latent bug introduced in commit b4d3434f, exposed by commit f2512684. (That explains why I didn't see it - when I tested b4d3434f, nothing dereferenced the NULL, and my testing of f2512684 wasn't as thorough). -- Eric Blake eblake@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org

At 2011-3-23 20:25, Eric Blake Write:
On 03/22/2011 08:02 PM, Wen Congyang wrote:
Steps to reproduce this bug: # cat usb.xml <hostdev mode='subsystem' type='usb'> <source> <address bus='0x001' device='0x003'/> </source> </hostdev> # virsh attach-device vm1 usb.xml error: Failed to attach device from usb.xml error: server closed connection:
The reason of this bug is that we set data.cgroup to NULL, and this will cause libvirtd crashed.
usbDevice *usb; - qemuCgroupData data = { vm, cgroup }; + qemuCgroupData data;
if (virCgroupForDomain(driver->cgroup, vm->def->name,&cgroup, 0) !=0 ) { qemuReportError(VIR_ERR_INTERNAL_ERROR, @@ -873,6 +873,8 @@ int qemuDomainAttachHostUsbDevice(struct qemud_driver *driver, hostdev->source.subsys.u.usb.device)) == NULL) goto error;
+ data.vm = vm; + data.cgroup = cgroup;
ACK. Latent bug introduced in commit b4d3434f, exposed by commit f2512684. (That explains why I didn't see it - when I tested b4d3434f, nothing dereferenced the NULL, and my testing of f2512684 wasn't as thorough).
Thanks. Pushed.
-- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
participants (3)
-
Eric Blake
-
Wen Congyang
-
Wen Congyang