Skip to content

Commit

Permalink
launch: libvirt: Fix labelling of overlay files.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
rwmjones committed Dec 11, 2014
1 parent f4b4dcc commit 39f7eae
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/launch-libvirt.c
Expand Up @@ -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);
Expand Down Expand Up @@ -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 =
Expand Down

0 comments on commit 39f7eae

Please sign in to comment.