mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-22 11:22:23 +00:00
node_device_udev: Set @def to NULL
@def is owned by @obj after adding it the node device object list. As soon as the @obj lock has been released, another thread could free @obj and therefore @def. If now someone accesses @def this would lead to a heap-use-after-free and therefore most likely to a segmentation fault, therefore set @def to NULL after the ownership has moved. While at it, add comments to other code places why @def is set to NULL. Reviewed-by: Boris Fiuczynski <fiuczy@linux.ibm.com> Reviewed-by: Jonathon Jongsma <jjongsma@redhat.com> Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
This commit is contained in:
parent
7ccf76ea34
commit
30354f5b1f
@ -1588,6 +1588,8 @@ udevAddOneDevice(struct udev_device *device)
|
|||||||
* and the current definition will take its place. */
|
* and the current definition will take its place. */
|
||||||
if (!(obj = virNodeDeviceObjListAssignDef(driver->devs, def)))
|
if (!(obj = virNodeDeviceObjListAssignDef(driver->devs, def)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
/* @def is now owned by @obj */
|
||||||
|
def = NULL;
|
||||||
virNodeDeviceObjSetPersistent(obj, persistent);
|
virNodeDeviceObjSetPersistent(obj, persistent);
|
||||||
virNodeDeviceObjSetAutostart(obj, autostart);
|
virNodeDeviceObjSetAutostart(obj, autostart);
|
||||||
objdef = virNodeDeviceObjGetDef(obj);
|
objdef = virNodeDeviceObjGetDef(obj);
|
||||||
@ -1983,6 +1985,8 @@ udevSetupSystemDev(void)
|
|||||||
if (!(obj = virNodeDeviceObjListAssignDef(driver->devs, def)))
|
if (!(obj = virNodeDeviceObjListAssignDef(driver->devs, def)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
|
/* @def is now owned by @obj */
|
||||||
|
def = NULL;
|
||||||
virNodeDeviceObjSetActive(obj, true);
|
virNodeDeviceObjSetActive(obj, true);
|
||||||
virNodeDeviceObjSetAutostart(obj, true);
|
virNodeDeviceObjSetAutostart(obj, true);
|
||||||
virNodeDeviceObjSetPersistent(obj, true);
|
virNodeDeviceObjSetPersistent(obj, true);
|
||||||
|
@ -7674,8 +7674,9 @@ testNodeDeviceMockCreateVport(testDriver *driver,
|
|||||||
|
|
||||||
if (!(obj = virNodeDeviceObjListAssignDef(driver->devs, def)))
|
if (!(obj = virNodeDeviceObjListAssignDef(driver->devs, def)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
virNodeDeviceObjSetSkipUpdateCaps(obj, true);
|
/* @def is now owned by @obj */
|
||||||
def = NULL;
|
def = NULL;
|
||||||
|
virNodeDeviceObjSetSkipUpdateCaps(obj, true);
|
||||||
objdef = virNodeDeviceObjGetDef(obj);
|
objdef = virNodeDeviceObjGetDef(obj);
|
||||||
|
|
||||||
event = virNodeDeviceEventLifecycleNew(objdef->name,
|
event = virNodeDeviceEventLifecycleNew(objdef->name,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user