diff --git a/src/security/security_manager.c b/src/security/security_manager.c index 013bbc37ef6126f2a6397f98e60d7fe7cec0d3ba..95b9952308fc46bafde54c1c137b35a56f921c12 100644 --- a/src/security/security_manager.c +++ b/src/security/security_manager.c @@ -650,31 +650,33 @@ virSecurityManagerGenLabel(virSecurityManagerPtr mgr, for (i = 0; sec_managers[i]; i++) { generated = false; seclabel = virDomainDefGetSecurityLabelDef(vm, sec_managers[i]->drv->name); - if (!seclabel) { - if (!(seclabel = virSecurityLabelDefNew(sec_managers[i]->drv->name))) - goto cleanup; - generated = seclabel->implicit = true; - } - - if (seclabel->type == VIR_DOMAIN_SECLABEL_DEFAULT) { - if (virSecurityManagerGetDefaultConfined(sec_managers[i])) { - seclabel->type = VIR_DOMAIN_SECLABEL_DYNAMIC; + if (seclabel == NULL) { + /* Only generate seclabel if confinement is enabled */ + if (!virSecurityManagerGetDefaultConfined(sec_managers[i])) { + VIR_DEBUG("Skipping auto generated seclabel"); + continue; } else { - seclabel->type = VIR_DOMAIN_SECLABEL_NONE; - seclabel->relabel = false; + if (!(seclabel = virSecurityLabelDefNew(sec_managers[i]->drv->name))) + goto cleanup; + generated = seclabel->implicit = true; + seclabel->type = VIR_DOMAIN_SECLABEL_DYNAMIC; + } + } else { + if (seclabel->type == VIR_DOMAIN_SECLABEL_DEFAULT) { + if (virSecurityManagerGetDefaultConfined(sec_managers[i])) { + seclabel->type = VIR_DOMAIN_SECLABEL_DYNAMIC; + } else { + seclabel->type = VIR_DOMAIN_SECLABEL_NONE; + seclabel->relabel = false; + } } - } - if (seclabel->type == VIR_DOMAIN_SECLABEL_NONE) { - if (virSecurityManagerGetRequireConfined(sec_managers[i])) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("Unconfined guests are not allowed on this host")); - goto cleanup; - } else if (vm->nseclabels && generated) { - VIR_DEBUG("Skipping auto generated seclabel of type none"); - virSecurityLabelDefFree(seclabel); - seclabel = NULL; - continue; + if (seclabel->type == VIR_DOMAIN_SECLABEL_NONE) { + if (virSecurityManagerGetRequireConfined(sec_managers[i])) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("Unconfined guests are not allowed on this host")); + goto cleanup; + } } }