[PATCH] virDevMapperGetTargetsImpl: quit early if device is not a devmapper target

Ján Tomko jtomko at redhat.com
Mon May 11 12:28:59 UTC 2020


On a Monday in 2020, Michal Privoznik wrote:
>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 at redhat.com>
>---
> src/util/virdevmapper.c | 10 ++++++++++
> 1 file changed, 10 insertions(+)
>
>diff --git a/src/util/virdevmapper.c b/src/util/virdevmapper.c
>index feb5982315..ee026d502e 100644
>--- a/src/util/virdevmapper.c
>+++ b/src/util/virdevmapper.c
>@@ -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)
>+            ret = 0;
>+        return ret;

Why not 'return 0' and 'return -1' directly?

>+    }
>+
>+    if (!dm_is_dm_major(major(sb.st_dev)))
>+        return 0;
>+

Either way
Reviewed-by: Ján Tomko <jtomko at redhat.com>

Jano
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20200511/908dcead/attachment-0001.sig>


More information about the libvir-list mailing list