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