render / rpms / libvirt

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