From fc35edc6a7a88d4a491ead88f0e1e5cb18cc819c Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mar 16 2021 04:19:35 +0000 Subject: sd-bus: initialize mutex after we allocated the wqueue That way the mutex doesn't have to be destroyed when we exit early due to OOM. (cherry picked from commit 2fe9a10d7695c4c3a748969a0d1662c624e50e5e) Related: CVE-2020-1712 patch_name: 0311-sd-bus-initialize-mutex-after-we-allocated-the-wqueu.patch present_in_specfile: true location_in_specfile: 311 squash_commits: true --- diff --git a/src/libsystemd/sd-bus/sd-bus.c b/src/libsystemd/sd-bus/sd-bus.c index 01060d1..e49d581 100644 --- a/src/libsystemd/sd-bus/sd-bus.c +++ b/src/libsystemd/sd-bus/sd-bus.c @@ -248,12 +248,12 @@ _public_ int sd_bus_new(sd_bus **ret) { b->original_pid = getpid_cached(); b->n_groups = (size_t) -1; - assert_se(pthread_mutex_init(&b->memfd_cache_mutex, NULL) == 0); - /* We guarantee that wqueue always has space for at least one entry */ if (!GREEDY_REALLOC(b->wqueue, b->wqueue_allocated, 1)) return -ENOMEM; + assert_se(pthread_mutex_init(&b->memfd_cache_mutex, NULL) == 0); + *ret = TAKE_PTR(b); return 0; }