render / rpms / libvirt

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