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

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