From 39f7eaea80c103d9b1cdf1826c4bc70c304c860e Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Thu, 11 Dec 2014 14:05:47 +0000 Subject: [PATCH] launch: libvirt: Fix labelling of overlay files. We had code (added for RHBZ#912499) which labels overlay files correctly so that libvirt can read them. Unfortunately this code was broken by subsequent commits: the new backend setting for the imagelabel is only copied to the 'data' struct during launch, but the create_cow_overlay callback is called before launch (when adding drives). The fix is easy: ensure create_cow_overlay_libvirt checks for the backend setting and initializes the 'data' struct. This change also means we need to free (data->selinux_imagelabel) before setting it in launch (and we do the same for data->selinux_label, although that's not strictly necessary). For background on this, see: https://bugzilla.redhat.com/show_bug.cgi?id=912499#c10 --- src/launch-libvirt.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/launch-libvirt.c b/src/launch-libvirt.c index 1f3c4518a9..ea0502f72c 100644 --- a/src/launch-libvirt.c +++ b/src/launch-libvirt.c @@ -217,6 +217,15 @@ create_cow_overlay_libvirt (guestfs_h *g, void *datav, struct drive *drv) return NULL; #if HAVE_LIBSELINUX + /* Since this function is called before launch, the field won't be + * initialized correctly, so we have to initialize it here. + */ + guestfs_push_error_handler (g, NULL, NULL); + free (data->selinux_imagelabel); + data->selinux_imagelabel = + guestfs_get_backend_setting (g, "internal_libvirt_imagelabel"); + guestfs_pop_error_handler (g); + if (data->selinux_imagelabel) { debug (g, "setting SELinux label on %s to %s", overlay, data->selinux_imagelabel); @@ -350,8 +359,10 @@ launch_libvirt (guestfs_h *g, void *datav, const char *libvirt_uri) /* Misc backend settings. */ guestfs_push_error_handler (g, NULL, NULL); + free (data->selinux_label); data->selinux_label = guestfs_get_backend_setting (g, "internal_libvirt_label"); + free (data->selinux_imagelabel); data->selinux_imagelabel = guestfs_get_backend_setting (g, "internal_libvirt_imagelabel"); data->selinux_norelabel_disks =