[libvirt] [PATCH] nodedev_hal: fix segfault when virDBusGetSystemBus fails

Ryota Ozaki ozaki.ryota at gmail.com
Thu Oct 31 15:45:12 UTC 2013


Thie patch fixes the segfault:
    error : nodeStateInitialize:658 : DBus not available,
      disabling HAL driver: internal error: Unable to get DBus
      system bus connection: Failed to connect to socket
      /var/run/dbus/system_bus_socket: No such file or directory
    error : nodeStateInitialize:719 :  ?:
    Caught Segmentation violation dumping internal log buffer:

This segfault occurs at the below VIR_ERROR:
  failure:
      if (dbus_error_is_set(&err)) {
          VIR_ERROR(_("%s: %s"), err.name, err.message);

When virDBusGetSystemBus fails, the code jumps to the above failure
path. However, the err variable is not correctly initialized
before calling virDBusGetSystemBus. As a result, dbus_error_is_set
may pass over the uninitialized err variable whose name or
message may point to somewhere unknown memory region, which
causes a segfault on VIR_ERROR.

The new code initializes the err variable before calling
virDBusGetSystemBus.

Signed-off-by: Ryota Ozaki <ozaki.ryota at gmail.com>
---
 src/node_device/node_device_hal.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/node_device/node_device_hal.c b/src/node_device/node_device_hal.c
index d94767c..a019a07 100644
--- a/src/node_device/node_device_hal.c
+++ b/src/node_device/node_device_hal.c
@@ -652,6 +652,7 @@ nodeStateInitialize(bool privileged ATTRIBUTE_UNUSED,
     }
     nodeDeviceLock(driverState);
 
+    dbus_error_init(&err);
     if (!(sysbus = virDBusGetSystemBus())) {
         virErrorPtr verr = virGetLastError();
         VIR_ERROR(_("DBus not available, disabling HAL driver: %s"),
@@ -660,7 +661,6 @@ nodeStateInitialize(bool privileged ATTRIBUTE_UNUSED,
         goto failure;
     }
 
-    dbus_error_init(&err);
     hal_ctx = libhal_ctx_new();
     if (hal_ctx == NULL) {
         VIR_ERROR(_("libhal_ctx_new returned NULL"));
-- 
1.8.4




More information about the libvir-list mailing list