[PATCH v2] lxc: fix lxcContainerMountAllFS() DEREF_BEFORE_CHECK

Dmitry Frolov posted 1 patch 7 months, 3 weeks ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/20230907090456.563322-1-frolov@swemel.ru
src/lxc/lxc_container.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
[PATCH v2] lxc: fix lxcContainerMountAllFS() DEREF_BEFORE_CHECK
Posted by Dmitry Frolov 7 months, 3 weeks ago
vmDef->fss[i]->src->path may be NULL,
so check is needed before passing it to VIR_DEBUG.
Also removed checking vmDef->fss[i]->src for NULL, since it may not be NULL.

Fixes: 57487085dc ("lxc: don't try to reference NULL when mounting filesystems")

Signed-off-by: Dmitry Frolov <frolov@swemel.ru>
---
 src/lxc/lxc_container.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/lxc/lxc_container.c b/src/lxc/lxc_container.c
index 21220661f7..9601061b23 100644
--- a/src/lxc/lxc_container.c
+++ b/src/lxc/lxc_container.c
@@ -1467,12 +1467,12 @@ static int lxcContainerMountAllFS(virDomainDef *vmDef,
         if (STREQ(vmDef->fss[i]->dst, "/"))
             continue;
 
-        VIR_DEBUG("Mounting '%s' -> '%s'", vmDef->fss[i]->src->path, vmDef->fss[i]->dst);
+        VIR_DEBUG("Mounting '%s' -> '%s'", NULLSTR(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 &&
+        if (!(vmDef->fss[i]->src->path &&
               STRPREFIX(vmDef->fss[i]->src->path, vmDef->fss[i]->dst)) &&
             lxcContainerUnmountSubtree(vmDef->fss[i]->dst, false) < 0)
             return -1;
-- 
2.34.1
Re: [PATCH v2] lxc: fix lxcContainerMountAllFS() DEREF_BEFORE_CHECK
Posted by Michal Prívozník 6 months, 1 week ago
On 9/7/23 11:04, Dmitry Frolov wrote:
> vmDef->fss[i]->src->path may be NULL,
> so check is needed before passing it to VIR_DEBUG.
> Also removed checking vmDef->fss[i]->src for NULL, since it may not be NULL.
> 
> Fixes: 57487085dc ("lxc: don't try to reference NULL when mounting filesystems")
> 
> Signed-off-by: Dmitry Frolov <frolov@swemel.ru>
> ---
>  src/lxc/lxc_container.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/src/lxc/lxc_container.c b/src/lxc/lxc_container.c
> index 21220661f7..9601061b23 100644
> --- a/src/lxc/lxc_container.c
> +++ b/src/lxc/lxc_container.c
> @@ -1467,12 +1467,12 @@ static int lxcContainerMountAllFS(virDomainDef *vmDef,
>          if (STREQ(vmDef->fss[i]->dst, "/"))
>              continue;
>  
> -        VIR_DEBUG("Mounting '%s' -> '%s'", vmDef->fss[i]->src->path, vmDef->fss[i]->dst);
> +        VIR_DEBUG("Mounting '%s' -> '%s'", NULLSTR(vmDef->fss[i]->src->path), vmDef->fss[i]->dst);

Nitpick, this is long enough line that can be easily broken into two.

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

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>

and pushed.

Michal
Fwd: [PATCH v2] lxc: fix lxcContainerMountAllFS() DEREF_BEFORE_CHECK
Posted by Дмитрий Фролов 6 months, 3 weeks ago
ping.

-------- Перенаправленное сообщение --------
Тема: 	[PATCH v2] lxc: fix lxcContainerMountAllFS() DEREF_BEFORE_CHECK
Дата: 	Thu, 7 Sep 2023 12:04:57 +0300
От: 	Dmitry Frolov <frolov@swemel.ru>
Кому: 	libvir-list@redhat.com
Копия: 	Dmitry Frolov <frolov@swemel.ru>



vmDef->fss[i]->src->path may be NULL,
so check is needed before passing it to VIR_DEBUG.
Also removed checking vmDef->fss[i]->src for NULL, since it may not be NULL.

Fixes: 57487085dc ("lxc: don't try to reference NULL when mounting 
filesystems")

Signed-off-by: Dmitry Frolov <frolov@swemel.ru>
---
src/lxc/lxc_container.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/lxc/lxc_container.c b/src/lxc/lxc_container.c
index 21220661f7..9601061b23 100644
--- a/src/lxc/lxc_container.c
+++ b/src/lxc/lxc_container.c
@@ -1467,12 +1467,12 @@ static int lxcContainerMountAllFS(virDomainDef 
*vmDef,
if (STREQ(vmDef->fss[i]->dst, "/"))
continue;
- VIR_DEBUG("Mounting '%s' -> '%s'", vmDef->fss[i]->src->path, 
vmDef->fss[i]->dst);
+ VIR_DEBUG("Mounting '%s' -> '%s'", NULLSTR(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 &&
+ if (!(vmDef->fss[i]->src->path &&
STRPREFIX(vmDef->fss[i]->src->path, vmDef->fss[i]->dst)) &&
lxcContainerUnmountSubtree(vmDef->fss[i]->dst, false) < 0)
return -1;

-- 
2.34.1