[libvirt] [PATCH] storage: Fix daemon crash on lookup storagepool by targetpath

Yi Li posted 1 patch 6 years, 1 month ago
Test syntax-check failed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/1576849054-17764-1-git-send-email-yili@winhong.com
There is a newer version of this series
src/storage/storage_driver.c | 6 ++++++
1 file changed, 6 insertions(+)
[libvirt] [PATCH] storage: Fix daemon crash on lookup storagepool by targetpath
Posted by Yi Li 6 years, 1 month ago
Causing a crash when storagePoolLookupByTargetPath because of
Some types of storage pool have no target elements.

Core was generated by `/usr/sbin/libvirtd'.
Program terminated with signal 11, Segmentation fault.
(gdb) bt
0  0x0000ffff9e951388 in strcmp () from /lib64/libc.so.6
1  0x0000ffff92103e9c in storagePoolLookupByTargetPathCallback (
    obj=0xffff7009aab0, opaque=0xffff801058b0) at storage/storage_driver.c:1649
2  0x0000ffff9f2c52a4 in virStoragePoolObjListSearchCb (
    payload=0xffff801058b0, name=<optimized out>, opaque=<optimized out>)
    at conf/virstorageobj.c:476
3  0x0000ffff9f1f2f7c in virHashSearch (ctable=0xffff800f4f60,
    iter=iter@entry=0xffff9f2c5278 <virStoragePoolObjListSearchCb>,
    data=data@entry=0xffff95af7488, name=name@entry=0x0) at util/virhash.c:696
4  0x0000ffff9f2c64f0 in virStoragePoolObjListSearch (pools=0xffff800f2ce0,
    searcher=searcher@entry=0xffff92103e68 <storagePoolLookupByTargetPathCallback>,
     opaque=<optimized out>) at conf/virstorageobj.c:505
5  0x0000ffff92101f54 in storagePoolLookupByTargetPath (conn=0xffff5c0009f0,
path=0xffff7009a850 "/vms/images") at storage/storage_driver.c:1672

Signed-off-by: Yi Li <yili@winhong.com>
---
 src/storage/storage_driver.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c
index a33328d..5863e1f 100644
--- a/src/storage/storage_driver.c
+++ b/src/storage/storage_driver.c
@@ -1713,6 +1713,12 @@ storagePoolLookupByTargetPathCallback(virStoragePoolObjPtr obj,
         return false;
 
     def = virStoragePoolObjGetDef(obj);
+
+    /* Some Storage pool types have no Target elements,
+     * so we should check it. */
+    if (def->target.path == NULL)
+        return false;
+
     return STREQ(path, def->target.path);
 }
 
-- 
2.7.5




--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Re: [libvirt] [PATCH] storage: Fix daemon crash on lookup storagepool by targetpath
Posted by Cole Robinson 6 years, 1 month ago
On 12/20/19 8:37 AM, Yi Li wrote:
> Causing a crash when storagePoolLookupByTargetPath because of
> Some types of storage pool have no target elements.
> 
> Core was generated by `/usr/sbin/libvirtd'.
> Program terminated with signal 11, Segmentation fault.
> (gdb) bt
> 0  0x0000ffff9e951388 in strcmp () from /lib64/libc.so.6
> 1  0x0000ffff92103e9c in storagePoolLookupByTargetPathCallback (
>     obj=0xffff7009aab0, opaque=0xffff801058b0) at storage/storage_driver.c:1649
> 2  0x0000ffff9f2c52a4 in virStoragePoolObjListSearchCb (
>     payload=0xffff801058b0, name=<optimized out>, opaque=<optimized out>)
>     at conf/virstorageobj.c:476
> 3  0x0000ffff9f1f2f7c in virHashSearch (ctable=0xffff800f4f60,
>     iter=iter@entry=0xffff9f2c5278 <virStoragePoolObjListSearchCb>,
>     data=data@entry=0xffff95af7488, name=name@entry=0x0) at util/virhash.c:696
> 4  0x0000ffff9f2c64f0 in virStoragePoolObjListSearch (pools=0xffff800f2ce0,
>     searcher=searcher@entry=0xffff92103e68 <storagePoolLookupByTargetPathCallback>,
>      opaque=<optimized out>) at conf/virstorageobj.c:505
> 5  0x0000ffff92101f54 in storagePoolLookupByTargetPath (conn=0xffff5c0009f0,
> path=0xffff7009a850 "/vms/images") at storage/storage_driver.c:1672
> 
> Signed-off-by: Yi Li <yili@winhong.com>
> ---
>  src/storage/storage_driver.c | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c
> index a33328d..5863e1f 100644
> --- a/src/storage/storage_driver.c
> +++ b/src/storage/storage_driver.c
> @@ -1713,6 +1713,12 @@ storagePoolLookupByTargetPathCallback(virStoragePoolObjPtr obj,
>          return false;
>  
>      def = virStoragePoolObjGetDef(obj);
> +
> +    /* Some Storage pool types have no Target elements,
> +     * so we should check it. */
> +    if (def->target.path == NULL)
> +        return false;
> +
>      return STREQ(path, def->target.path);
>  }
>  
> 

Makes sense. You can use STREQ_NULLABLE which will cover that in a
simpler way though. You can CC me on v2 and I'll review

Thanks,
Cole

- Cole

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

[libvirt] [PATCH v2] storage: Fix daemon crash on lookup storagepool by targetpath
Posted by Yi Li 6 years, 1 month ago
Causing a crash when storagePoolLookupByTargetPath beacuse of
Some types of storage pool have no target elements.
Use STREQ_NULLABLE instead of STREQ
Avoids segfaults when using NULL arguments.

Core was generated by `/usr/sbin/libvirtd'.
Program terminated with signal 11, Segmentation fault.
(gdb) bt
0  0x0000ffff9e951388 in strcmp () from /lib64/libc.so.6
1  0x0000ffff92103e9c in storagePoolLookupByTargetPathCallback (
    obj=0xffff7009aab0, opaque=0xffff801058b0) at storage/storage_driver.c:1649
2  0x0000ffff9f2c52a4 in virStoragePoolObjListSearchCb (
    payload=0xffff801058b0, name=<optimized out>, opaque=<optimized out>)
    at conf/virstorageobj.c:476
3  0x0000ffff9f1f2f7c in virHashSearch (ctable=0xffff800f4f60,
    iter=iter@entry=0xffff9f2c5278 <virStoragePoolObjListSearchCb>,
    data=data@entry=0xffff95af7488, name=name@entry=0x0) at util/virhash.c:696
4  0x0000ffff9f2c64f0 in virStoragePoolObjListSearch (pools=0xffff800f2ce0,
    searcher=searcher@entry=0xffff92103e68 <storagePoolLookupByTargetPathCallback>,
     opaque=<optimized out>) at conf/virstorageobj.c:505
5  0x0000ffff92101f54 in storagePoolLookupByTargetPath (conn=0xffff5c0009f0,
path=0xffff7009a850 "/vms/images") at storage/storage_driver.c:1672

Signed-off-by: Yi Li <yili@winhong.com>
---
 src/storage/storage_driver.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c
index a33328d..72ba252 100644
--- a/src/storage/storage_driver.c
+++ b/src/storage/storage_driver.c
@@ -1713,7 +1713,7 @@ storagePoolLookupByTargetPathCallback(virStoragePoolObjPtr obj,
         return false;
 
     def = virStoragePoolObjGetDef(obj);
-    return STREQ(path, def->target.path);
+    return STREQ_NULLABLE(path, def->target.path);
 }
 
 
-- 
2.7.5




--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Re: [libvirt] [PATCH v2] storage: Fix daemon crash on lookup storagepool by targetpath
Posted by Cole Robinson 6 years, 1 month ago
On 12/20/19 7:33 PM, Yi Li wrote:
> Causing a crash when storagePoolLookupByTargetPath beacuse of
> Some types of storage pool have no target elements.
> Use STREQ_NULLABLE instead of STREQ
> Avoids segfaults when using NULL arguments.
> 
> Core was generated by `/usr/sbin/libvirtd'.
> Program terminated with signal 11, Segmentation fault.
> (gdb) bt
> 0  0x0000ffff9e951388 in strcmp () from /lib64/libc.so.6
> 1  0x0000ffff92103e9c in storagePoolLookupByTargetPathCallback (
>     obj=0xffff7009aab0, opaque=0xffff801058b0) at storage/storage_driver.c:1649
> 2  0x0000ffff9f2c52a4 in virStoragePoolObjListSearchCb (
>     payload=0xffff801058b0, name=<optimized out>, opaque=<optimized out>)
>     at conf/virstorageobj.c:476
> 3  0x0000ffff9f1f2f7c in virHashSearch (ctable=0xffff800f4f60,
>     iter=iter@entry=0xffff9f2c5278 <virStoragePoolObjListSearchCb>,
>     data=data@entry=0xffff95af7488, name=name@entry=0x0) at util/virhash.c:696
> 4  0x0000ffff9f2c64f0 in virStoragePoolObjListSearch (pools=0xffff800f2ce0,
>     searcher=searcher@entry=0xffff92103e68 <storagePoolLookupByTargetPathCallback>,
>      opaque=<optimized out>) at conf/virstorageobj.c:505
> 5  0x0000ffff92101f54 in storagePoolLookupByTargetPath (conn=0xffff5c0009f0,
> path=0xffff7009a850 "/vms/images") at storage/storage_driver.c:1672
> 
> Signed-off-by: Yi Li <yili@winhong.com>

Reviewed-by: Cole Robinson <crobinso@redhat.com>

and pushed now

- Cole

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list