]> xenbits.xensource.com Git - libvirt.git/commitdiff
virDevMapperGetTargetsImpl: quit early if device is not a devmapper target
authorMichal Privoznik <mprivozn@redhat.com>
Fri, 24 Apr 2020 11:17:51 +0000 (13:17 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Mon, 11 May 2020 13:37:27 +0000 (15:37 +0200)
As suggested in the linked bug, libvirt should firstly check
whether the major number of the device is device mapper major.
Because if it isn't subsequent DM_DEVICE_DEPS task may not only
fail, but also yield different results. In the bugzilla this is
demonstrated by creating a devmapper target named 'loop0' and
then creating loop target /dev/loop0. When the latter is then
passed to a domain, our virDevMapperGetTargetsImpl() function
blindly asks devmapper to provide target dependencies for
/dev/loop0 and because of the way devmapper APIs work, it will
'sanitize' the input by using the last component only which is
'loop0' and thus return different results than expected.

Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1823976
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/util/virdevmapper.c

index feb5982315e390c117dbc40ce9968399c39be4ec..79dbc3d02a340906008c9b947c04965885f3cb44 100644 (file)
@@ -64,6 +64,7 @@ virDevMapperGetTargetsImpl(const char *path,
                            char ***devPaths_ret,
                            unsigned int ttl)
 {
+    struct stat sb;
     struct dm_task *dmt = NULL;
     struct dm_deps *deps;
     struct dm_info info;
@@ -82,6 +83,15 @@ virDevMapperGetTargetsImpl(const char *path,
         return ret;
     }
 
+    if (stat(path, &sb) < 0) {
+        if (errno == ENOENT)
+            return 0;
+        return -1;
+    }
+
+    if (!dm_is_dm_major(major(sb.st_dev)))
+        return 0;
+
     if (!(dmt = dm_task_create(DM_DEVICE_DEPS))) {
         if (errno == ENOENT || errno == ENODEV) {
             /* It's okay. Kernel is probably built without