提交 606afafb 编写于 作者: E Erik Skultety

security: Enable labeling of vfio mediated devices

This patch updates all of our security driver to start labeling the
VFIO IOMMU devices under /dev/vfio/ as well.
Signed-off-by: NErik Skultety <eskultet@redhat.com>
上级 ec783d7c
...@@ -51,6 +51,7 @@ ...@@ -51,6 +51,7 @@
#include "virlog.h" #include "virlog.h"
#include "virstring.h" #include "virstring.h"
#include "virscsi.h" #include "virscsi.h"
#include "virmdev.h"
#define VIR_FROM_THIS VIR_FROM_SECURITY #define VIR_FROM_THIS VIR_FROM_SECURITY
...@@ -813,6 +814,7 @@ AppArmorSetSecurityHostdevLabel(virSecurityManagerPtr mgr, ...@@ -813,6 +814,7 @@ AppArmorSetSecurityHostdevLabel(virSecurityManagerPtr mgr,
virDomainHostdevSubsysPCIPtr pcisrc = &dev->source.subsys.u.pci; virDomainHostdevSubsysPCIPtr pcisrc = &dev->source.subsys.u.pci;
virDomainHostdevSubsysSCSIPtr scsisrc = &dev->source.subsys.u.scsi; virDomainHostdevSubsysSCSIPtr scsisrc = &dev->source.subsys.u.scsi;
virDomainHostdevSubsysSCSIVHostPtr hostsrc = &dev->source.subsys.u.scsi_host; virDomainHostdevSubsysSCSIVHostPtr hostsrc = &dev->source.subsys.u.scsi_host;
virDomainHostdevSubsysMediatedDevPtr mdevsrc = &dev->source.subsys.u.mdev;
if (!secdef || !secdef->relabel) if (!secdef || !secdef->relabel)
return 0; return 0;
...@@ -901,8 +903,25 @@ AppArmorSetSecurityHostdevLabel(virSecurityManagerPtr mgr, ...@@ -901,8 +903,25 @@ AppArmorSetSecurityHostdevLabel(virSecurityManagerPtr mgr,
break; break;
} }
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV: case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV: {
char *vfiodev = NULL;
virMediatedDevicePtr mdev = virMediatedDeviceNew(mdevsrc->uuidstr,
mdevsrc->model);
if (!mdev)
goto done;
if (!(vfiodev = virMediatedDeviceGetIOMMUGroupDev(mdev))) {
virMediatedDeviceFree(mdev);
goto done;
}
ret = AppArmorSetSecurityHostdevLabelHelper(vfiodev, ptr);
VIR_FREE(vfiodev);
virMediatedDeviceFree(mdev);
break; break;
}
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_LAST: case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_LAST:
ret = 0; ret = 0;
......
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#include "virfile.h" #include "virfile.h"
#include "viralloc.h" #include "viralloc.h"
#include "virlog.h" #include "virlog.h"
#include "virmdev.h"
#include "virpci.h" #include "virpci.h"
#include "virusb.h" #include "virusb.h"
#include "virscsi.h" #include "virscsi.h"
...@@ -867,6 +868,7 @@ virSecurityDACSetHostdevLabel(virSecurityManagerPtr mgr, ...@@ -867,6 +868,7 @@ virSecurityDACSetHostdevLabel(virSecurityManagerPtr mgr,
virDomainHostdevSubsysPCIPtr pcisrc = &dev->source.subsys.u.pci; virDomainHostdevSubsysPCIPtr pcisrc = &dev->source.subsys.u.pci;
virDomainHostdevSubsysSCSIPtr scsisrc = &dev->source.subsys.u.scsi; virDomainHostdevSubsysSCSIPtr scsisrc = &dev->source.subsys.u.scsi;
virDomainHostdevSubsysSCSIVHostPtr hostsrc = &dev->source.subsys.u.scsi_host; virDomainHostdevSubsysSCSIVHostPtr hostsrc = &dev->source.subsys.u.scsi_host;
virDomainHostdevSubsysMediatedDevPtr mdevsrc = &dev->source.subsys.u.mdev;
int ret = -1; int ret = -1;
if (!priv->dynamicOwnership) if (!priv->dynamicOwnership)
...@@ -964,7 +966,26 @@ virSecurityDACSetHostdevLabel(virSecurityManagerPtr mgr, ...@@ -964,7 +966,26 @@ virSecurityDACSetHostdevLabel(virSecurityManagerPtr mgr,
break; break;
} }
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV: case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV: {
char *vfiodev = NULL;
virMediatedDevicePtr mdev = virMediatedDeviceNew(mdevsrc->uuidstr,
mdevsrc->model);
if (!mdev)
goto done;
if (!(vfiodev = virMediatedDeviceGetIOMMUGroupDev(mdev))) {
virMediatedDeviceFree(mdev);
goto done;
}
ret = virSecurityDACSetHostdevLabelHelper(vfiodev, &cbdata);
VIR_FREE(vfiodev);
virMediatedDeviceFree(mdev);
break;
}
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_LAST: case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_LAST:
ret = 0; ret = 0;
break; break;
...@@ -1032,6 +1053,7 @@ virSecurityDACRestoreHostdevLabel(virSecurityManagerPtr mgr, ...@@ -1032,6 +1053,7 @@ virSecurityDACRestoreHostdevLabel(virSecurityManagerPtr mgr,
virDomainHostdevSubsysPCIPtr pcisrc = &dev->source.subsys.u.pci; virDomainHostdevSubsysPCIPtr pcisrc = &dev->source.subsys.u.pci;
virDomainHostdevSubsysSCSIPtr scsisrc = &dev->source.subsys.u.scsi; virDomainHostdevSubsysSCSIPtr scsisrc = &dev->source.subsys.u.scsi;
virDomainHostdevSubsysSCSIVHostPtr hostsrc = &dev->source.subsys.u.scsi_host; virDomainHostdevSubsysSCSIVHostPtr hostsrc = &dev->source.subsys.u.scsi_host;
virDomainHostdevSubsysMediatedDevPtr mdevsrc = &dev->source.subsys.u.mdev;
int ret = -1; int ret = -1;
secdef = virDomainDefGetSecurityLabelDef(def, SECURITY_DAC_NAME); secdef = virDomainDefGetSecurityLabelDef(def, SECURITY_DAC_NAME);
...@@ -1120,7 +1142,26 @@ virSecurityDACRestoreHostdevLabel(virSecurityManagerPtr mgr, ...@@ -1120,7 +1142,26 @@ virSecurityDACRestoreHostdevLabel(virSecurityManagerPtr mgr,
break; break;
} }
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV: case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV: {
char *vfiodev = NULL;
virMediatedDevicePtr mdev = virMediatedDeviceNew(mdevsrc->uuidstr,
mdevsrc->model);
if (!mdev)
goto done;
if (!(vfiodev = virMediatedDeviceGetIOMMUGroupDev(mdev))) {
virMediatedDeviceFree(mdev);
goto done;
}
ret = virSecurityDACRestoreFileLabel(virSecurityManagerGetPrivateData(mgr),
vfiodev);
VIR_FREE(vfiodev);
virMediatedDeviceFree(mdev);
break;
}
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_LAST: case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_LAST:
ret = 0; ret = 0;
break; break;
......
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
#include "virerror.h" #include "virerror.h"
#include "viralloc.h" #include "viralloc.h"
#include "virlog.h" #include "virlog.h"
#include "virmdev.h"
#include "virpci.h" #include "virpci.h"
#include "virusb.h" #include "virusb.h"
#include "virscsi.h" #include "virscsi.h"
...@@ -1741,6 +1742,7 @@ virSecuritySELinuxSetHostLabel(virSCSIVHostDevicePtr dev ATTRIBUTE_UNUSED, ...@@ -1741,6 +1742,7 @@ virSecuritySELinuxSetHostLabel(virSCSIVHostDevicePtr dev ATTRIBUTE_UNUSED,
return virSecuritySELinuxSetHostdevLabelHelper(file, opaque); return virSecuritySELinuxSetHostdevLabelHelper(file, opaque);
} }
static int static int
virSecuritySELinuxSetHostdevSubsysLabel(virSecurityManagerPtr mgr, virSecuritySELinuxSetHostdevSubsysLabel(virSecurityManagerPtr mgr,
virDomainDefPtr def, virDomainDefPtr def,
...@@ -1752,6 +1754,7 @@ virSecuritySELinuxSetHostdevSubsysLabel(virSecurityManagerPtr mgr, ...@@ -1752,6 +1754,7 @@ virSecuritySELinuxSetHostdevSubsysLabel(virSecurityManagerPtr mgr,
virDomainHostdevSubsysPCIPtr pcisrc = &dev->source.subsys.u.pci; virDomainHostdevSubsysPCIPtr pcisrc = &dev->source.subsys.u.pci;
virDomainHostdevSubsysSCSIPtr scsisrc = &dev->source.subsys.u.scsi; virDomainHostdevSubsysSCSIPtr scsisrc = &dev->source.subsys.u.scsi;
virDomainHostdevSubsysSCSIVHostPtr hostsrc = &dev->source.subsys.u.scsi_host; virDomainHostdevSubsysSCSIVHostPtr hostsrc = &dev->source.subsys.u.scsi_host;
virDomainHostdevSubsysMediatedDevPtr mdevsrc = &dev->source.subsys.u.mdev;
virSecuritySELinuxCallbackData data = {.mgr = mgr, .def = def}; virSecuritySELinuxCallbackData data = {.mgr = mgr, .def = def};
int ret = -1; int ret = -1;
...@@ -1838,7 +1841,26 @@ virSecuritySELinuxSetHostdevSubsysLabel(virSecurityManagerPtr mgr, ...@@ -1838,7 +1841,26 @@ virSecuritySELinuxSetHostdevSubsysLabel(virSecurityManagerPtr mgr,
break; break;
} }
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV: case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV: {
char *vfiodev = NULL;
virMediatedDevicePtr mdev = virMediatedDeviceNew(mdevsrc->uuidstr,
mdevsrc->model);
if (!mdev)
goto done;
if (!(vfiodev = virMediatedDeviceGetIOMMUGroupDev(mdev))) {
virMediatedDeviceFree(mdev);
goto done;
}
ret = virSecuritySELinuxSetHostdevLabelHelper(vfiodev, &data);
VIR_FREE(vfiodev);
virMediatedDeviceFree(mdev);
break;
}
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_LAST: case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_LAST:
ret = 0; ret = 0;
break; break;
...@@ -1973,6 +1995,7 @@ virSecuritySELinuxRestoreHostLabel(virSCSIVHostDevicePtr dev ATTRIBUTE_UNUSED, ...@@ -1973,6 +1995,7 @@ virSecuritySELinuxRestoreHostLabel(virSCSIVHostDevicePtr dev ATTRIBUTE_UNUSED,
return virSecuritySELinuxRestoreFileLabel(mgr, file); return virSecuritySELinuxRestoreFileLabel(mgr, file);
} }
static int static int
virSecuritySELinuxRestoreHostdevSubsysLabel(virSecurityManagerPtr mgr, virSecuritySELinuxRestoreHostdevSubsysLabel(virSecurityManagerPtr mgr,
virDomainHostdevDefPtr dev, virDomainHostdevDefPtr dev,
...@@ -1983,6 +2006,7 @@ virSecuritySELinuxRestoreHostdevSubsysLabel(virSecurityManagerPtr mgr, ...@@ -1983,6 +2006,7 @@ virSecuritySELinuxRestoreHostdevSubsysLabel(virSecurityManagerPtr mgr,
virDomainHostdevSubsysPCIPtr pcisrc = &dev->source.subsys.u.pci; virDomainHostdevSubsysPCIPtr pcisrc = &dev->source.subsys.u.pci;
virDomainHostdevSubsysSCSIPtr scsisrc = &dev->source.subsys.u.scsi; virDomainHostdevSubsysSCSIPtr scsisrc = &dev->source.subsys.u.scsi;
virDomainHostdevSubsysSCSIVHostPtr hostsrc = &dev->source.subsys.u.scsi_host; virDomainHostdevSubsysSCSIVHostPtr hostsrc = &dev->source.subsys.u.scsi_host;
virDomainHostdevSubsysMediatedDevPtr mdevsrc = &dev->source.subsys.u.mdev;
int ret = -1; int ret = -1;
/* Like virSecuritySELinuxRestoreImageLabelInt() for a networked /* Like virSecuritySELinuxRestoreImageLabelInt() for a networked
...@@ -2066,7 +2090,26 @@ virSecuritySELinuxRestoreHostdevSubsysLabel(virSecurityManagerPtr mgr, ...@@ -2066,7 +2090,26 @@ virSecuritySELinuxRestoreHostdevSubsysLabel(virSecurityManagerPtr mgr,
break; break;
} }
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV: case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV: {
char *vfiodev = NULL;
virMediatedDevicePtr mdev = virMediatedDeviceNew(mdevsrc->uuidstr,
mdevsrc->model);
if (!mdev)
goto done;
if (!(vfiodev = virMediatedDeviceGetIOMMUGroupDev(mdev))) {
virMediatedDeviceFree(mdev);
goto done;
}
ret = virSecuritySELinuxRestoreFileLabel(mgr, vfiodev);
VIR_FREE(vfiodev);
virMediatedDeviceFree(mdev);
break;
}
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_LAST: case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_LAST:
ret = 0; ret = 0;
break; break;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册