edecca
From d0f2fffa7c1a86f56f18143a1a14b9a32f8bcf16 Mon Sep 17 00:00:00 2001
edecca
Message-Id: <d0f2fffa7c1a86f56f18143a1a14b9a32f8bcf16@dist-git>
edecca
From: John Ferlan <jferlan@redhat.com>
edecca
Date: Wed, 16 Jan 2019 15:54:31 -0500
edecca
Subject: [PATCH] qemu: Fix logic error in qemuSetUnprivSGIO
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=1666605
edecca
edecca
RHEL-only
edecca
edecca
Commit c0f26a13c6 had a logic error with using both DISK and
edecca
sgio which resulted in a DISK that didn't have sgio set falling
edecca
into the else clause and trying to deref a NULL @hostdev resulting
edecca
in a libvirtd crash:
edecca
edecca
Thread 1 (Thread 0x7ffbc6353700 (LWP 12642)):
edecca
 0  0x00007ffb958e7d7a in qemuSetUnprivSGIO
edecca
 1  0x00007ffb958d9d92 in qemuDomainAttachDeviceDiskLive
edecca
 2  0x00007ffb9594fce8 in qemuDomainAttachDeviceFlags
edecca
 3  0x00007ffbde399d71 in virDomainAttachDevice
edecca
 4  0x0000563b73ded4b2 in remoteDispatchDomainAttachDeviceHelper
edecca
edecca
for hotplug of XML:
edecca
edecca
<disk device="lun" type="block">
edecca
  <source dev="/dev/sdb"/>
edecca
  <driver name="qemu" type="raw"/>
edecca
  <target bus="scsi" dev="sdb"/>
edecca
</disk>
edecca
edecca
Signed-off-by: John Ferlan <jferlan@redhat.com>
edecca
Reviewed-by: Ján Tomko <jtomko@redhat.com>
edecca
---
edecca
 src/qemu/qemu_conf.c | 6 +++---
edecca
 1 file changed, 3 insertions(+), 3 deletions(-)
edecca
edecca
diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
edecca
index 5971f3eb64..768e9d8308 100644
edecca
--- a/src/qemu/qemu_conf.c
edecca
+++ b/src/qemu/qemu_conf.c
edecca
@@ -1679,9 +1679,9 @@ qemuSetUnprivSGIO(virDomainDeviceDefPtr dev)
edecca
         goto cleanup;
edecca
 
edecca
     /* By default, filter the SG_IO commands, i.e. set unpriv_sgio to 0.  */
edecca
-    if (dev->type == VIR_DOMAIN_DEVICE_DISK &&
edecca
-        disk->sgio == VIR_DOMAIN_DEVICE_SGIO_UNFILTERED) {
edecca
-        val = 1;
edecca
+    if (dev->type == VIR_DOMAIN_DEVICE_DISK) {
edecca
+        if (disk->sgio == VIR_DOMAIN_DEVICE_SGIO_UNFILTERED)
edecca
+            val = 1;
edecca
     } else {
edecca
         /* Only settable if <shareable/> was present for hostdev */
edecca
         if (qemuIsSharedHostdev(hostdev) &&
edecca
-- 
edecca
2.20.1
edecca