51d9a2
From 0d80657c5002e3914f28dce9bf46c2a6577e817b Mon Sep 17 00:00:00 2001
51d9a2
Message-Id: <0d80657c5002e3914f28dce9bf46c2a6577e817b@dist-git>
51d9a2
From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= <berrange@redhat.com>
51d9a2
Date: Fri, 6 Jul 2018 15:47:02 +0100
51d9a2
Subject: [PATCH] qemu: fix UNIX socket chardevs operating in client mode
51d9a2
MIME-Version: 1.0
51d9a2
Content-Type: text/plain; charset=UTF-8
51d9a2
Content-Transfer-Encoding: 8bit
51d9a2
51d9a2
https://bugzilla.redhat.com/show_bug.cgi?id=1598440
51d9a2
51d9a2
When support was adding for passing a pre-opened listener socket to UNIX
51d9a2
chardevs, it accidentally passed the listener socket for client mode
51d9a2
chardevs too with predictable amounts of fail resulting. This affects
51d9a2
libvirt when using QEMU >= 2.12
51d9a2
51d9a2
Expand the unit test coverage to validate that we are only doing FD
51d9a2
passing when operating in server mode.
51d9a2
51d9a2
  https://bugzilla.redhat.com/show_bug.cgi?id=1598440
51d9a2
51d9a2
Tested-by: Richard W.M. Jones <rjones@redhat.com>
51d9a2
Reported-by: Richard W.M. Jones <rjones@redhat.com>
51d9a2
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
51d9a2
(cherry picked from commit 1bc1a7e3205f7ef75ebd8fd1ef7653f8e181e3d2)
51d9a2
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
51d9a2
---
51d9a2
 src/qemu/qemu_command.c                       |  3 +-
51d9a2
 .../qemuxml2argvdata/serial-unix-chardev.args |  2 ++
51d9a2
 .../serial-unix-chardev.x86_64-latest.args    | 36 +++++++++++++++++++
51d9a2
 .../qemuxml2argvdata/serial-unix-chardev.xml  |  4 +++
51d9a2
 tests/qemuxml2argvtest.c                      |  1 +
51d9a2
 5 files changed, 45 insertions(+), 1 deletion(-)
51d9a2
 create mode 100644 tests/qemuxml2argvdata/serial-unix-chardev.x86_64-latest.args
51d9a2
51d9a2
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
51d9a2
index 637e787d25..f38ae668a7 100644
51d9a2
--- a/src/qemu/qemu_command.c
51d9a2
+++ b/src/qemu/qemu_command.c
51d9a2
@@ -5082,7 +5082,8 @@ qemuBuildChrChardevStr(virLogManagerPtr logManager,
51d9a2
         break;
51d9a2
 
51d9a2
     case VIR_DOMAIN_CHR_TYPE_UNIX:
51d9a2
-        if ((flags & QEMU_BUILD_CHARDEV_UNIX_FD_PASS) &&
51d9a2
+        if (dev->data.nix.listen &&
51d9a2
+            (flags & QEMU_BUILD_CHARDEV_UNIX_FD_PASS) &&
51d9a2
             virQEMUCapsGet(qemuCaps, QEMU_CAPS_CHARDEV_FD_PASS)) {
51d9a2
             if (qemuSecuritySetSocketLabel(secManager, (virDomainDefPtr)def) < 0)
51d9a2
                 goto cleanup;
51d9a2
diff --git a/tests/qemuxml2argvdata/serial-unix-chardev.args b/tests/qemuxml2argvdata/serial-unix-chardev.args
51d9a2
index 584f4a1dd1..873d3263c6 100644
51d9a2
--- a/tests/qemuxml2argvdata/serial-unix-chardev.args
51d9a2
+++ b/tests/qemuxml2argvdata/serial-unix-chardev.args
51d9a2
@@ -26,4 +26,6 @@ server,nowait \
51d9a2
 -device ide-drive,bus=ide.0,unit=0,drive=drive-ide0-0-0,id=ide0-0-0 \
51d9a2
 -chardev socket,id=charserial0,path=/tmp/serial.sock \
51d9a2
 -device isa-serial,chardev=charserial0,id=serial0 \
51d9a2
+-chardev socket,id=charserial1,path=/tmp/serial-server.sock,server,nowait \
51d9a2
+-device isa-serial,chardev=charserial1,id=serial1 \
51d9a2
 -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3
51d9a2
diff --git a/tests/qemuxml2argvdata/serial-unix-chardev.x86_64-latest.args b/tests/qemuxml2argvdata/serial-unix-chardev.x86_64-latest.args
51d9a2
new file mode 100644
51d9a2
index 0000000000..ce7a7f80d7
51d9a2
--- /dev/null
51d9a2
+++ b/tests/qemuxml2argvdata/serial-unix-chardev.x86_64-latest.args
51d9a2
@@ -0,0 +1,36 @@
51d9a2
+LC_ALL=C \
51d9a2
+PATH=/bin \
51d9a2
+HOME=/home/test \
51d9a2
+USER=test \
51d9a2
+LOGNAME=test \
51d9a2
+QEMU_AUDIO_DRV=none \
51d9a2
+/usr/bin/qemu-system-i686 \
51d9a2
+-name guest=QEMUGuest1,debug-threads=on \
51d9a2
+-S \
51d9a2
+-object secret,id=masterKey0,format=raw,\
51d9a2
+file=/tmp/lib/domain--1-QEMUGuest1/master-key.aes \
51d9a2
+-machine pc,accel=tcg,usb=off,dump-guest-core=off \
51d9a2
+-m 214 \
51d9a2
+-realtime mlock=off \
51d9a2
+-smp 1,sockets=1,cores=1,threads=1 \
51d9a2
+-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \
51d9a2
+-display none \
51d9a2
+-no-user-config \
51d9a2
+-nodefaults \
51d9a2
+-chardev socket,id=charmonitor,fd=1729,server,nowait \
51d9a2
+-mon chardev=charmonitor,id=monitor,mode=control \
51d9a2
+-rtc base=utc \
51d9a2
+-no-shutdown \
51d9a2
+-no-acpi \
51d9a2
+-boot strict=on \
51d9a2
+-device piix3-usb-uhci,id=usb,bus=pci.0,addr=0x1.0x2 \
51d9a2
+-drive file=/dev/HostVG/QEMUGuest1,format=raw,if=none,id=drive-ide0-0-0 \
51d9a2
+-device ide-hd,bus=ide.0,unit=0,drive=drive-ide0-0-0,id=ide0-0-0,bootindex=1 \
51d9a2
+-chardev socket,id=charserial0,path=/tmp/serial.sock \
51d9a2
+-device isa-serial,chardev=charserial0,id=serial0 \
51d9a2
+-chardev socket,id=charserial1,fd=1729,server,nowait \
51d9a2
+-device isa-serial,chardev=charserial1,id=serial1 \
51d9a2
+-device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x2 \
51d9a2
+-sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,\
51d9a2
+resourcecontrol=deny \
51d9a2
+-msg timestamp=on
51d9a2
diff --git a/tests/qemuxml2argvdata/serial-unix-chardev.xml b/tests/qemuxml2argvdata/serial-unix-chardev.xml
51d9a2
index 04f83779ce..af513d6445 100644
51d9a2
--- a/tests/qemuxml2argvdata/serial-unix-chardev.xml
51d9a2
+++ b/tests/qemuxml2argvdata/serial-unix-chardev.xml
51d9a2
@@ -25,6 +25,10 @@
51d9a2
       <source mode='connect' path='/tmp/serial.sock'/>
51d9a2
       <target port='0'/>
51d9a2
     </serial>
51d9a2
+    <serial type='unix'>
51d9a2
+      <source mode='bind' path='/tmp/serial-server.sock'/>
51d9a2
+      <target port='1'/>
51d9a2
+    </serial>
51d9a2
     <console type='unix'>
51d9a2
       <source mode='connect' path='/tmp/serial.sock'/>
51d9a2
       <target port='0'/>
51d9a2
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
51d9a2
index 2d52f352b0..3be5af03aa 100644
51d9a2
--- a/tests/qemuxml2argvtest.c
51d9a2
+++ b/tests/qemuxml2argvtest.c
51d9a2
@@ -1335,6 +1335,7 @@ mymain(void)
51d9a2
             QEMU_CAPS_CHARDEV_FILE_APPEND);
51d9a2
     DO_TEST("serial-unix-chardev",
51d9a2
             QEMU_CAPS_DEVICE_ISA_SERIAL);
51d9a2
+    DO_TEST_CAPS_LATEST("serial-unix-chardev");
51d9a2
     DO_TEST("serial-tcp-chardev",
51d9a2
             QEMU_CAPS_DEVICE_ISA_SERIAL);
51d9a2
     DO_TEST("serial-udp-chardev",
51d9a2
-- 
51d9a2
2.18.0
51d9a2