Skip to contentSkip to conversation

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

PATCH In review David Hildenbrand 2 participants 2 messages Jan 11, 2022

lore
Share & tools
lore
#0 lore raw

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

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 <[email protected]>
Cc Michael S. Tsirkin <[email protected]>
Cc Pankaj Gupta <[email protected]>
Cc Daniel P. Berrangé <[email protected]>
Cc Michal Privoznik <[email protected]>
---
 util/oslib-posix.c | 1 +
 1 file changed, 1 insertion(+)
util/oslib-posix.c +1 -0
index 9efdc74bba..ac0dbc2adc 100644
@@ -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;
Signature · 1 line
2.33.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 20 lines

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 <[email protected]>
Cc Michael S. Tsirkin <[email protected]>
Cc Pankaj Gupta <[email protected]>
Cc Daniel P. Berrangé <[email protected]>
Cc Michal Privoznik <[email protected]>
---
 util/oslib-posix.c | 1 +
 1 file changed, 1 insertion(+)
util/oslib-posix.c +0 -0
index 9efdc74bba..ac0dbc2adc 100644

util/oslib-posix.c void os_mem_prealloc(int fd, char *area, size_t memory, int smp_cpus,

Quoted 8 lines
util/oslib-posix.c +1 -1
@@ -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;
--
Quoted 2 lines

2.33.1