render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
edecca
From 03cf4bcbcfa55297b2359875640819a755b7860c Mon Sep 17 00:00:00 2001
edecca
Message-Id: <03cf4bcbcfa55297b2359875640819a755b7860c@dist-git>
edecca
From: Erik Skultety <eskultet@redhat.com>
edecca
Date: Fri, 1 Feb 2019 17:21:55 +0100
edecca
Subject: [PATCH] qemu: cgroup: Expose /dev/sev/ only to domains that require
edecca
 SEV
edecca
MIME-Version: 1.0
edecca
Content-Type: text/plain; charset=UTF-8
edecca
Content-Transfer-Encoding: 8bit
edecca
edecca
SEV has a limit on number of concurrent guests. From security POV we
edecca
should only expose resources (any resources for that matter) to domains
edecca
that truly need them.
edecca
edecca
Signed-off-by: Erik Skultety <eskultet@redhat.com>
edecca
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
edecca
(cherry picked from commit a404ac34768e975bd420d1eeac3811563da67e3f)
edecca
edecca
https: //bugzilla.redhat.com/show_bug.cgi?id=1665400
edecca
Signed-off-by: Erik Skultety <eskultet@redhat.com>
edecca
Reviewed-by: Ján Tomko <jtomko@redhat.com>
edecca
---
edecca
 src/qemu/qemu_cgroup.c | 19 +++++++++++++++++++
edecca
 1 file changed, 19 insertions(+)
edecca
edecca
diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c
edecca
index fd54333fb9..9f2fc1b062 100644
edecca
--- a/src/qemu/qemu_cgroup.c
edecca
+++ b/src/qemu/qemu_cgroup.c
edecca
@@ -695,6 +695,22 @@ qemuTeardownChardevCgroup(virDomainObjPtr vm,
edecca
 }
edecca
 
edecca
 
edecca
+static int
edecca
+qemuSetupSEVCgroup(virDomainObjPtr vm)
edecca
+{
edecca
+    qemuDomainObjPrivatePtr priv = vm->privateData;
edecca
+    int ret;
edecca
+
edecca
+    if (!virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_DEVICES))
edecca
+        return 0;
edecca
+
edecca
+    ret = virCgroupAllowDevicePath(priv->cgroup, "/dev/sev",
edecca
+                                   VIR_CGROUP_DEVICE_RW, false);
edecca
+    virDomainAuditCgroupPath(vm, priv->cgroup, "allow", "/dev/sev",
edecca
+                             "rw", ret);
edecca
+    return ret;
edecca
+}
edecca
+
edecca
 static int
edecca
 qemuSetupDevicesCgroup(virDomainObjPtr vm)
edecca
 {
edecca
@@ -802,6 +818,9 @@ qemuSetupDevicesCgroup(virDomainObjPtr vm)
edecca
             goto cleanup;
edecca
     }
edecca
 
edecca
+    if (vm->def->sev && qemuSetupSEVCgroup(vm) < 0)
edecca
+        goto cleanup;
edecca
+
edecca
     ret = 0;
edecca
  cleanup:
edecca
     virObjectUnref(cfg);
edecca
-- 
edecca
2.20.1
edecca