Blob Blame History Raw
From c2afbedc310ac1a65a5ee96c8fa4103e926483c4 Mon Sep 17 00:00:00 2001
Message-Id: <c2afbedc310ac1a65a5ee96c8fa4103e926483c4@dist-git>
From: Han Han <hhan@redhat.com>
Date: Tue, 28 Aug 2018 10:30:51 +0200
Subject: [PATCH] conf: Add validation of input devices
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

https://bugzilla.redhat.com/show_bug.cgi?id=1591151

Add function virDomainInputDefValidate to validate input devices.
Make sure evdev attribute of source element is not used by mouse,
keyboard, and tablet input device.

Signed-off-by: Han Han <hhan@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
(cherry picked from commit deb057fd364cb57614c6dea7b05c247231f9ae4f)
Signed-off-by: Ján Tomko <jtomko@redhat.com>

https: //bugzilla.redhat.com/show_bug.cgi?id=1591240
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
---
 src/conf/domain_conf.c | 27 ++++++++++++++++++++++++++-
 1 file changed, 26 insertions(+), 1 deletion(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 51a79ad8b1..16e52d149d 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -5760,6 +5760,29 @@ virDomainVsockDefValidate(const virDomainVsockDef *vsock)
     return 0;
 }
 
+static int
+virDomainInputDefValidate(const virDomainInputDef *input)
+{
+    switch ((virDomainInputType) input->type) {
+        case VIR_DOMAIN_INPUT_TYPE_MOUSE:
+        case VIR_DOMAIN_INPUT_TYPE_TABLET:
+        case VIR_DOMAIN_INPUT_TYPE_KBD:
+        case VIR_DOMAIN_INPUT_TYPE_LAST:
+            if (input->source.evdev) {
+                 virReportError(VIR_ERR_XML_ERROR, "%s",
+                                _("setting source evdev path only supported for "
+                                  "passthrough input devices"));
+                 return -1;
+            }
+            break;
+
+        case VIR_DOMAIN_INPUT_TYPE_PASSTHROUGH:
+            break;
+    }
+
+    return 0;
+}
+
 
 static int
 virDomainDeviceDefValidateInternal(const virDomainDeviceDef *dev,
@@ -5799,9 +5822,11 @@ virDomainDeviceDefValidateInternal(const virDomainDeviceDef *dev,
     case VIR_DOMAIN_DEVICE_VSOCK:
         return virDomainVsockDefValidate(dev->data.vsock);
 
+    case VIR_DOMAIN_DEVICE_INPUT:
+        return virDomainInputDefValidate(dev->data.input);
+
     case VIR_DOMAIN_DEVICE_LEASE:
     case VIR_DOMAIN_DEVICE_FS:
-    case VIR_DOMAIN_DEVICE_INPUT:
     case VIR_DOMAIN_DEVICE_SOUND:
     case VIR_DOMAIN_DEVICE_WATCHDOG:
     case VIR_DOMAIN_DEVICE_GRAPHICS:
-- 
2.18.0