[PATCH] tests: vhost-user-test: release mutex on protocol violation

Paolo Bonzini posted 1 patch 1 year ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20230427125423.103536-1-pbonzini@redhat.com
Maintainers: Thomas Huth <thuth@redhat.com>, Laurent Vivier <lvivier@redhat.com>, Paolo Bonzini <pbonzini@redhat.com>
tests/qtest/vhost-user-test.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
[PATCH] tests: vhost-user-test: release mutex on protocol violation
Posted by Paolo Bonzini 1 year ago
chr_read() is printing an error message and returning with s->data_mutex taken.
This can potentially cause a hang.  Reported by Coverity.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 tests/qtest/vhost-user-test.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/tests/qtest/vhost-user-test.c b/tests/qtest/vhost-user-test.c
index bf9f7c4248ca..e4f95b2858f0 100644
--- a/tests/qtest/vhost-user-test.c
+++ b/tests/qtest/vhost-user-test.c
@@ -351,7 +351,7 @@ static void chr_read(void *opaque, const uint8_t *buf, int size)
         if (size != msg.size) {
             qos_printf("%s: Wrong message size received %d != %d\n",
                        __func__, size, msg.size);
-            return;
+            goto out;
         }
     }
 
@@ -509,6 +509,7 @@ static void chr_read(void *opaque, const uint8_t *buf, int size)
         break;
     }
 
+out:
     g_mutex_unlock(&s->data_mutex);
 }
 
-- 
2.40.0
Re: [PATCH] tests: vhost-user-test: release mutex on protocol violation
Posted by Thomas Huth 1 year ago
On 27/04/2023 14.54, Paolo Bonzini wrote:
> chr_read() is printing an error message and returning with s->data_mutex taken.
> This can potentially cause a hang.  Reported by Coverity.
> 
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>   tests/qtest/vhost-user-test.c | 3 ++-
>   1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/tests/qtest/vhost-user-test.c b/tests/qtest/vhost-user-test.c
> index bf9f7c4248ca..e4f95b2858f0 100644
> --- a/tests/qtest/vhost-user-test.c
> +++ b/tests/qtest/vhost-user-test.c
> @@ -351,7 +351,7 @@ static void chr_read(void *opaque, const uint8_t *buf, int size)
>           if (size != msg.size) {
>               qos_printf("%s: Wrong message size received %d != %d\n",
>                          __func__, size, msg.size);
> -            return;
> +            goto out;
>           }
>       }
>   
> @@ -509,6 +509,7 @@ static void chr_read(void *opaque, const uint8_t *buf, int size)
>           break;
>       }
>   
> +out:
>       g_mutex_unlock(&s->data_mutex);
>   }
>   

Reviewed-by: Thomas Huth <thuth@redhat.com>