Blame SOURCES/libvirt-hostdev-Update-mdev-pointer-reference-after-checking-device-type.patch

ab145e
From bad40f7148a5849e84e9cdc341ff1fa03dc94fc6 Mon Sep 17 00:00:00 2001
ab145e
Message-Id: <bad40f7148a5849e84e9cdc341ff1fa03dc94fc6@dist-git>
ab145e
From: Thomas Huth <thuth@redhat.com>
ab145e
Date: Tue, 11 May 2021 14:10:27 +0200
ab145e
Subject: [PATCH] hostdev: Update mdev pointer reference after checking device
ab145e
 type
ab145e
MIME-Version: 1.0
ab145e
Content-Type: text/plain; charset=UTF-8
ab145e
Content-Transfer-Encoding: 8bit
ab145e
ab145e
We set the pointer to some garbage packed structure data without
ab145e
knowing whether we were actually handling the type of device we
ab145e
expected to be handling. On its own, this was harmless, because we'd
ab145e
never use the pointer as we'd skip the device if it were not the
ab145e
expected type. However, it's better to make the logic even more
ab145e
explicit - we first check the device and only when we're sure we have
ab145e
the expected type we then update the pointer shortcut.
ab145e
ab145e
Signed-off-by: Erik Skultety <eskultet@redhat.com>
ab145e
Reviewed-by: Ján Tomko <jtomko@redhat.com>
ab145e
(cherry picked from commit 964738cff3d949d90fc5c3317a2618fcd8d217b4)
ab145e
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1940449
ab145e
Signed-off-by: Thomas Huth <thuth@redhat.com>
ab145e
Message-Id: <20210511121028.304070-2-thuth@redhat.com>
ab145e
Reviewed-by: Erik Skultety <eskultet@redhat.com>
ab145e
---
ab145e
 src/util/virhostdev.c | 4 ++--
ab145e
 1 file changed, 2 insertions(+), 2 deletions(-)
ab145e
ab145e
diff --git a/src/util/virhostdev.c b/src/util/virhostdev.c
ab145e
index 9596482146..b7050e99e4 100644
ab145e
--- a/src/util/virhostdev.c
ab145e
+++ b/src/util/virhostdev.c
ab145e
@@ -2030,11 +2030,11 @@ virHostdevReAttachMediatedDevices(virHostdevManagerPtr mgr,
ab145e
         virDomainHostdevSubsysMediatedDevPtr mdevsrc;
ab145e
         virDomainHostdevDefPtr hostdev = hostdevs[i];
ab145e
 
ab145e
-        mdevsrc = &hostdev->source.subsys.u.mdev;
ab145e
-
ab145e
         if (!virHostdevIsMdevDevice(hostdev))
ab145e
             continue;
ab145e
 
ab145e
+        mdevsrc = &hostdev->source.subsys.u.mdev;
ab145e
+
ab145e
         if (!(mdev = virMediatedDeviceNew(mdevsrc->uuidstr,
ab145e
                                           mdevsrc->model)))
ab145e
             continue;
ab145e
-- 
ab145e
2.31.1
ab145e