[libvirt] [PATCH] qemu: add pointer check in qemuMonitorLastError

Xu Yandong posted 1 patch 4 years, 7 months ago
Test syntax-check passed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/1568880067-87939-1-git-send-email-xuyandong2@huawei.com
src/qemu/qemu_monitor.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[libvirt] [PATCH] qemu: add pointer check in qemuMonitorLastError
Posted by Xu Yandong 4 years, 7 months ago
We found a exception when libvirt occurrs segmentation fault.
thread 1 is waiting object lock in qemuConnectMonitor,
qemu process exits and sends EOF event as well, so thread 2 invokes
qemuMonitorLastError but pointer mon is NULL.

Signed-off-by: Xu Yandong <xuyandong2@huawei.com>
---
 src/qemu/qemu_monitor.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index aa230b3306..28f18391a5 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -1103,7 +1103,7 @@ qemuMonitorSend(qemuMonitorPtr mon,
 virErrorPtr
 qemuMonitorLastError(qemuMonitorPtr mon)
 {
-    if (mon->lastError.code == VIR_ERR_OK)
+    if (!mon || mon->lastError.code == VIR_ERR_OK)
         return NULL;
 
     return virErrorCopyNew(&mon->lastError);
-- 
2.18.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] qemu: add pointer check in qemuMonitorLastError
Posted by Daniel Henrique Barboza 4 years, 7 months ago

On 9/19/19 5:01 AM, Xu Yandong wrote:
> We found a exception when libvirt occurrs segmentation fault.
> thread 1 is waiting object lock in qemuConnectMonitor,
> qemu process exits and sends EOF event as well, so thread 2 invokes
> qemuMonitorLastError but pointer mon is NULL.
>
> Signed-off-by: Xu Yandong <xuyandong2@huawei.com>
> ---

Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>

>   src/qemu/qemu_monitor.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
> index aa230b3306..28f18391a5 100644
> --- a/src/qemu/qemu_monitor.c
> +++ b/src/qemu/qemu_monitor.c
> @@ -1103,7 +1103,7 @@ qemuMonitorSend(qemuMonitorPtr mon,
>   virErrorPtr
>   qemuMonitorLastError(qemuMonitorPtr mon)
>   {
> -    if (mon->lastError.code == VIR_ERR_OK)
> +    if (!mon || mon->lastError.code == VIR_ERR_OK)
>           return NULL;
>   
>       return virErrorCopyNew(&mon->lastError);

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] qemu: add pointer check in qemuMonitorLastError
Posted by Michal Privoznik 4 years, 6 months ago
On 9/19/19 10:01 AM, Xu Yandong wrote:
> We found a exception when libvirt occurrs segmentation fault.
> thread 1 is waiting object lock in qemuConnectMonitor,
> qemu process exits and sends EOF event as well, so thread 2 invokes
> qemuMonitorLastError but pointer mon is NULL.
> 
> Signed-off-by: Xu Yandong <xuyandong2@huawei.com>
> ---
>   src/qemu/qemu_monitor.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
> index aa230b3306..28f18391a5 100644
> --- a/src/qemu/qemu_monitor.c
> +++ b/src/qemu/qemu_monitor.c
> @@ -1103,7 +1103,7 @@ qemuMonitorSend(qemuMonitorPtr mon,
>   virErrorPtr
>   qemuMonitorLastError(qemuMonitorPtr mon)
>   {
> -    if (mon->lastError.code == VIR_ERR_OK)
> +    if (!mon || mon->lastError.code == VIR_ERR_OK)
>           return NULL;
>   
>       return virErrorCopyNew(&mon->lastError);
> 

This works, but I think we need a better approach. The problem is, we 
register monitor FD into our event loop with unlocked @vm and only after 
that we try to lock @vm back and set priv->mon = mon (this is all done 
in qemuConnectMonitor()). I have better fix in mind but I have to run 
now, will post it tomorrow, if that's okay with you.

Michal

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