Blame SOURCES/libvirt-virDevMapperGetTargetsImpl-quit-early-if-device-is-not-a-devmapper-target.patch

fbe740
From 7ea7ef99b8d3f9a7d83ea12a843d786b182f24e3 Mon Sep 17 00:00:00 2001
fbe740
Message-Id: <7ea7ef99b8d3f9a7d83ea12a843d786b182f24e3@dist-git>
fbe740
From: Michal Privoznik <mprivozn@redhat.com>
fbe740
Date: Mon, 11 May 2020 16:56:48 +0200
fbe740
Subject: [PATCH] virDevMapperGetTargetsImpl: quit early if device is not a
fbe740
 devmapper target
fbe740
MIME-Version: 1.0
fbe740
Content-Type: text/plain; charset=UTF-8
fbe740
Content-Transfer-Encoding: 8bit
fbe740
fbe740
As suggested in the linked bug, libvirt should firstly check
fbe740
whether the major number of the device is device mapper major.
fbe740
Because if it isn't subsequent DM_DEVICE_DEPS task may not only
fbe740
fail, but also yield different results. In the bugzilla this is
fbe740
demonstrated by creating a devmapper target named 'loop0' and
fbe740
then creating loop target /dev/loop0. When the latter is then
fbe740
passed to a domain, our virDevMapperGetTargetsImpl() function
fbe740
blindly asks devmapper to provide target dependencies for
fbe740
/dev/loop0 and because of the way devmapper APIs work, it will
fbe740
'sanitize' the input by using the last component only which is
fbe740
'loop0' and thus return different results than expected.
fbe740
fbe740
Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1823976
fbe740
fbe740
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
fbe740
Reviewed-by: Ján Tomko <jtomko@redhat.com>
fbe740
(cherry picked from commit 01626c668ecfbe465d18799ac4628e6127ea1d47)
fbe740
fbe740
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1834353
fbe740
fbe740
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
fbe740
Message-Id: <bd8ec0d0b833b22d1117cdbdc3d39b7c3ba99fe6.1589208990.git.mprivozn@redhat.com>
fbe740
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
fbe740
---
fbe740
 src/util/virdevmapper.c | 10 ++++++++++
fbe740
 1 file changed, 10 insertions(+)
fbe740
fbe740
diff --git a/src/util/virdevmapper.c b/src/util/virdevmapper.c
fbe740
index cc6a099faa..f000979ce0 100644
fbe740
--- a/src/util/virdevmapper.c
fbe740
+++ b/src/util/virdevmapper.c
fbe740
@@ -66,6 +66,7 @@ virDevMapperGetTargetsImpl(const char *path,
fbe740
                            char ***devPaths_ret,
fbe740
                            unsigned int ttl)
fbe740
 {
fbe740
+    struct stat sb;
fbe740
     struct dm_task *dmt = NULL;
fbe740
     struct dm_deps *deps;
fbe740
     struct dm_info info;
fbe740
@@ -84,6 +85,15 @@ virDevMapperGetTargetsImpl(const char *path,
fbe740
         return ret;
fbe740
     }
fbe740
 
fbe740
+    if (stat(path, &sb) < 0) {
fbe740
+        if (errno == ENOENT)
fbe740
+            return 0;
fbe740
+        return -1;
fbe740
+    }
fbe740
+
fbe740
+    if (!dm_is_dm_major(major(sb.st_dev)))
fbe740
+        return 0;
fbe740
+
fbe740
     if (!(dmt = dm_task_create(DM_DEVICE_DEPS))) {
fbe740
         if (errno == ENOENT || errno == ENODEV) {
fbe740
             /* It's okay. Kernel is probably built without
fbe740
-- 
fbe740
2.26.2
fbe740