Re: [PATCH] lxc: fix lxcContainerMountAllFS() DEREF_BEFORE_CHECK

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Sep 06, 2023 at 06:34:42PM +0300, Dmitry Frolov wrote:
Reviewing the sources, I found, that
in function lxcContainerMountAllFS() pointers
vmDef->fss[i]->src and vmDef->fss[i]->src->path
are checked for NULL after dereferencing in
VIR_DEBUG() macro.

Fixes: 57487085dc ("lxc: don't try to reference NULL when mounting filesystems")
---
src/lxc/lxc_container.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/lxc/lxc_container.c b/src/lxc/lxc_container.c
index 21220661f7..58a6695458 100644
--- a/src/lxc/lxc_container.c
+++ b/src/lxc/lxc_container.c
@@ -1467,13 +1467,15 @@ static int lxcContainerMountAllFS(virDomainDef *vmDef,
        if (STREQ(vmDef->fss[i]->dst, "/"))
            continue;

+        if (!(vmDef->fss[i]->src && vmDef->fss[i]->src->path))
+            return -1;
+

This unfortunately changes the semantics.  This fails whenever there is
src or src->path missing, but ...

        VIR_DEBUG("Mounting '%s' -> '%s'", vmDef->fss[i]->src->path, vmDef->fss[i]->dst);

        if (lxcContainerResolveSymlinks(vmDef->fss[i], false) < 0)
            return -1;

-        if (!(vmDef->fss[i]->src && vmDef->fss[i]->src->path &&
-              STRPREFIX(vmDef->fss[i]->src->path, vmDef->fss[i]->dst)) &&
+        if (!STRPREFIX(vmDef->fss[i]->src->path, vmDef->fss[i]->dst) &&
            lxcContainerUnmountSubtree(vmDef->fss[i]->dst, false) < 0)

... here it only skips the unmount in such case.  That makes sense
because for example tmpfs does not have a source path, only the
destination and the mount that is not visible in the context here would
not only be skipped as well, but the whole starting of a domain would
fail.

Instead of this patch, you could just conditionally change the
VIR_DEBUG() to report what's actually happening.

            return -1;

--
2.34.1

Attachment: signature.asc
Description: PGP signature


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux