[PATCH v1] util/oslib-posix: Fix missing unlock in the error path of os_mem_prealloc()

David Hildenbrand posted 1 patch 2 years, 2 months ago
Test checkpatch passed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20220111120830.119912-1-david@redhat.com
util/oslib-posix.c | 1 +
1 file changed, 1 insertion(+)
[PATCH v1] util/oslib-posix: Fix missing unlock in the error path of os_mem_prealloc()
Posted by David Hildenbrand 2 years, 2 months ago
We're missing an unlock in case installing the signal handler failed.
Fortunately, we barely see this error in real life.

Fixes: a960d6642d39 ("util/oslib-posix: Support concurrent os_mem_prealloc() invocation")
Fixes: CID 1468941
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Michael S. Tsirkin <mst@redhat.com>
Cc: Pankaj Gupta <pankaj.gupta@ionos.com>
Cc: Daniel P. Berrangé <berrange@redhat.com>
Cc: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: David Hildenbrand <david@redhat.com>
---
 util/oslib-posix.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/util/oslib-posix.c b/util/oslib-posix.c
index 9efdc74bba..ac0dbc2adc 100644
--- a/util/oslib-posix.c
+++ b/util/oslib-posix.c
@@ -683,6 +683,7 @@ void os_mem_prealloc(int fd, char *area, size_t memory, int smp_cpus,
 
         ret = sigaction(SIGBUS, &act, &sigbus_oldact);
         if (ret) {
+            qemu_mutex_unlock(&sigbus_mutex);
             error_setg_errno(errp, errno,
                 "os_mem_prealloc: failed to install signal handler");
             return;
-- 
2.33.1


Re: [PATCH v1] util/oslib-posix: Fix missing unlock in the error path of os_mem_prealloc()
Posted by Pankaj Gupta 2 years, 2 months ago
> We're missing an unlock in case installing the signal handler failed.
> Fortunately, we barely see this error in real life.
>
> Fixes: a960d6642d39 ("util/oslib-posix: Support concurrent os_mem_prealloc() invocation")
> Fixes: CID 1468941
> Cc: Paolo Bonzini <pbonzini@redhat.com>
> Cc: Michael S. Tsirkin <mst@redhat.com>
> Cc: Pankaj Gupta <pankaj.gupta@ionos.com>
> Cc: Daniel P. Berrangé <berrange@redhat.com>
> Cc: Michal Privoznik <mprivozn@redhat.com>
> Signed-off-by: David Hildenbrand <david@redhat.com>
> ---
>  util/oslib-posix.c | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/util/oslib-posix.c b/util/oslib-posix.c
> index 9efdc74bba..ac0dbc2adc 100644
> --- a/util/oslib-posix.c
> +++ b/util/oslib-posix.c
> @@ -683,6 +683,7 @@ void os_mem_prealloc(int fd, char *area, size_t memory, int smp_cpus,
>
>          ret = sigaction(SIGBUS, &act, &sigbus_oldact);
>          if (ret) {
> +            qemu_mutex_unlock(&sigbus_mutex);
>              error_setg_errno(errp, errno,
>                  "os_mem_prealloc: failed to install signal handler");
>              return;
> --

Reviewed-by: Pankaj Gupta <pankaj.gupta@ionos.com>

> 2.33.1
>