Blob Blame History Raw
From 0c6924b8d474daf35ee30d74e5496957e503b206 Mon Sep 17 00:00:00 2001
From: Alexey Tikhonov <atikhono@redhat.com>
Date: Wed, 20 Jan 2021 15:40:34 +0100
Subject: [PATCH] SBUS: set sbus_name before dp_init_send()
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Some async task might access sbus_name before dp_initialized() was executed

Resolves: https://github.com/SSSD/sssd/issues/5466

Reviewed-by: Pavel Březina <pbrezina@redhat.com>
---
 src/providers/data_provider/dp.c | 21 ++++-----------------
 src/providers/data_provider/dp.h |  6 +++---
 src/providers/data_provider_be.c | 12 ++++++++++--
 3 files changed, 17 insertions(+), 22 deletions(-)

diff --git a/src/providers/data_provider/dp.c b/src/providers/data_provider/dp.c
index 90324d74d..64fe847b2 100644
--- a/src/providers/data_provider/dp.c
+++ b/src/providers/data_provider/dp.c
@@ -134,7 +134,6 @@ static int dp_destructor(struct data_provider *provider)
 struct dp_init_state {
     struct be_ctx *be_ctx;
     struct data_provider *provider;
-    char *sbus_name;
 };
 
 static void dp_init_done(struct tevent_req *subreq);
@@ -144,7 +143,8 @@ dp_init_send(TALLOC_CTX *mem_ctx,
              struct tevent_context *ev,
              struct be_ctx *be_ctx,
              uid_t uid,
-             gid_t gid)
+             gid_t gid,
+             const char *sbus_name)
 {
     struct dp_init_state *state;
     struct tevent_req *subreq;
@@ -177,13 +177,6 @@ dp_init_send(TALLOC_CTX *mem_ctx,
     state->provider->gid = gid;
     state->provider->be_ctx = be_ctx;
 
-    state->sbus_name = sss_iface_domain_bus(state, be_ctx->domain);
-    if (state->sbus_name == NULL) {
-        DEBUG(SSSDBG_FATAL_FAILURE, "Could not get sbus backend name.\n");
-        ret = ENOMEM;
-        goto done;
-    }
-
     /* Initialize data provider bus. Data provider can receive client
      * registration and other D-Bus methods. However no data provider
      * request will be executed as long as the modules and targets
@@ -192,7 +185,7 @@ dp_init_send(TALLOC_CTX *mem_ctx,
     talloc_set_destructor(state->provider, dp_destructor);
 
     subreq = sbus_server_create_and_connect_send(state->provider, ev,
-        state->sbus_name, NULL, sbus_address, true, 1000, uid, gid,
+        sbus_name, NULL, sbus_address, true, 1000, uid, gid,
         (sbus_server_on_connection_cb)dp_client_init,
         (sbus_server_on_connection_data)state->provider);
     if (subreq == NULL) {
@@ -270,16 +263,10 @@ done:
 }
 
 errno_t dp_init_recv(TALLOC_CTX *mem_ctx,
-                     struct tevent_req *req,
-                     const char **_sbus_name)
+                     struct tevent_req *req)
 {
-    struct dp_init_state *state;
-    state = tevent_req_data(req, struct dp_init_state);
-
     TEVENT_REQ_RETURN_ON_ERROR(req);
 
-    *_sbus_name = talloc_steal(mem_ctx, state->sbus_name);
-
     return EOK;
 }
 
diff --git a/src/providers/data_provider/dp.h b/src/providers/data_provider/dp.h
index a8b6e9f3a..95c6588ad 100644
--- a/src/providers/data_provider/dp.h
+++ b/src/providers/data_provider/dp.h
@@ -122,11 +122,11 @@ dp_init_send(TALLOC_CTX *mem_ctx,
              struct tevent_context *ev,
              struct be_ctx *be_ctx,
              uid_t uid,
-             gid_t gid);
+             gid_t gid,
+             const char *sbus_name);
 
 errno_t dp_init_recv(TALLOC_CTX *mem_ctx,
-                     struct tevent_req *req,
-                     const char **_sbus_name);
+                     struct tevent_req *req);
 
 bool _dp_target_enabled(struct data_provider *provider,
                         const char *module_name,
diff --git a/src/providers/data_provider_be.c b/src/providers/data_provider_be.c
index f059a3f96..8458146ea 100644
--- a/src/providers/data_provider_be.c
+++ b/src/providers/data_provider_be.c
@@ -565,7 +565,15 @@ errno_t be_process_init(TALLOC_CTX *mem_ctx,
         goto done;
     }
 
-    req = dp_init_send(be_ctx, be_ctx->ev, be_ctx, be_ctx->uid, be_ctx->gid);
+    be_ctx->sbus_name = sss_iface_domain_bus(be_ctx, be_ctx->domain);
+    if (be_ctx->sbus_name == NULL) {
+        DEBUG(SSSDBG_FATAL_FAILURE, "Could not get sbus backend name.\n");
+        ret = ENOMEM;
+        goto done;
+    }
+
+    req = dp_init_send(be_ctx, be_ctx->ev, be_ctx, be_ctx->uid, be_ctx->gid,
+                       be_ctx->sbus_name);
     if (req == NULL) {
         ret = ENOMEM;
         goto done;
@@ -612,7 +620,7 @@ static void dp_initialized(struct tevent_req *req)
 
     be_ctx = tevent_req_callback_data(req, struct be_ctx);
 
-    ret = dp_init_recv(be_ctx, req, &be_ctx->sbus_name);
+    ret = dp_init_recv(be_ctx, req);
     talloc_zfree(req);
     if (ret !=  EOK) {
         goto done;
-- 
2.21.3