]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
use local talloc ctx for modules
authorAlan T. DeKok <aland@freeradius.org>
Thu, 20 Jun 2019 17:15:01 +0000 (13:15 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Thu, 20 Jun 2019 17:15:54 +0000 (13:15 -0400)
because if we use the global ctx, AND it's mprotected, THEN
we can't open new connections after startup.  Because the new
connections link to the module and increase its reference count

src/bin/radiusd.c
src/bin/unit_test_attribute.c
src/bin/unit_test_module.c
src/lib/server/dl_module.c
src/lib/server/dl_module.h
src/lib/server/main_config.c

index 0c498a877aa4206f4aa0e64007e814f03e1a1250..7c8780807f1e3480c3bee9e291396fa7fe2f8dd9 100644 (file)
@@ -167,6 +167,7 @@ int main(int argc, char *argv[])
        size_t          pool_size = 0;
        void            *pool_page_start = NULL, *pool_page_end = NULL;
        bool            do_mprotect;
+       dl_module_loader_t *dl_modules = NULL;
 
        /*
         *      Setup talloc callbacks so we get useful errors
@@ -456,7 +457,8 @@ int main(int argc, char *argv[])
         *      config file parser.  Note that we pass an empty path
         *      here, as we haven't yet read the configuration file.
         */
-       if (!dl_module_loader_init(global_ctx, NULL)) {
+       dl_modules = dl_module_loader_init(NULL);
+       if (!dl_modules) {
                fr_perror("%s", program);
                EXIT_WITH_FAILURE;
        }
@@ -1007,6 +1009,11 @@ cleanup:
         */
        main_config_free(&config);
 
+       /*
+        *      Free the modules that we loaded.
+        */
+       if (dl_modules) talloc_free(dl_modules);
+
        /*
         *  Cleanup everything else
         */
index a0b61a3970ceefec7e8d1f0d2f86501d425e7cc9..340d55cfc2b812e6ec3fbe8e4509f100ac83f5ab 100644 (file)
@@ -1450,6 +1450,7 @@ int main(int argc, char *argv[])
        fr_dict_t               *dict = NULL;
        int                     ret = EXIT_SUCCESS;
        TALLOC_CTX              *autofree = talloc_autofree_context();
+       dl_module_loader_t      *dl_modules = NULL;
 
 #ifndef NDEBUG
        if (fr_fault_setup(autofree, getenv("PANIC_ACTION"), argv[0]) < 0) {
@@ -1524,7 +1525,8 @@ int main(int argc, char *argv[])
                EXIT_WITH_FAILURE;
        }
 
-       if (!dl_module_loader_init(autofree, NULL)) {
+       dl_modules = dl_module_loader_init(NULL);
+       if (!dl_modules) {
                fr_perror("unit_test_attribute");
                EXIT_WITH_FAILURE;
        }
@@ -1579,6 +1581,7 @@ int main(int argc, char *argv[])
         *      memory, so we get clean talloc reports.
         */
 cleanup:
+       if (dl_modules) talloc_free(dl_modules);
        fr_dict_free(&dict);
        xlat_free();
        fr_strerror_free();
index 7a8da0227e75147c1e71d8a237ae0e96d91129b9..eb0e8ae11c45bd29208c2a8a735bc9aaaf47aa10 100644 (file)
@@ -601,6 +601,7 @@ int main(int argc, char *argv[])
 
        char                    *p;
        main_config_t           *config;
+       dl_module_loader_t      *dl_modules = NULL;
 
        config = main_config_alloc(autofree);
        if (!config) {
@@ -743,7 +744,8 @@ int main(int argc, char *argv[])
         *      Initialize the DL infrastructure, which is used by the
         *      config file parser.
         */
-       if (!dl_module_loader_init(autofree, config->lib_dir)) {
+       dl_modules = dl_module_loader_init(config->lib_dir);
+       if (!dl_modules) {
                fr_perror("%s", config->name);
                EXIT_WITH_FAILURE;
        }
@@ -1180,6 +1182,8 @@ cleanup:
         */
        fr_dict_free(&dict);
 
+       if (dl_modules) talloc_free(dl_modules);
+
        /*
         *  Now we're sure no more triggers can fire, free the
         *  trigger tree
index 5733d2b340af7d78069e5af4dfca3d1c0135eb0e..d3ab75cb2d36e86318b61c00d930ba0e0aad4546 100644 (file)
@@ -582,7 +582,7 @@ dl_loader_t *dl_loader_from_module_loader(dl_module_loader_t *dl_module_l)
 /** Initialise structures needed by the dynamic linker
  *
  */
-dl_module_loader_t *dl_module_loader_init(TALLOC_CTX *ctx, char const *lib_dir)
+dl_module_loader_t *dl_module_loader_init(char const *lib_dir)
 {
        if (dl_module_loader) {         
                /*
@@ -595,7 +595,7 @@ dl_module_loader_t *dl_module_loader_init(TALLOC_CTX *ctx, char const *lib_dir)
                return dl_module_loader;
        }
 
-       dl_module_loader = talloc_zero(ctx, dl_module_loader_t);
+       dl_module_loader = talloc_zero(NULL, dl_module_loader_t);
        if (!dl_module_loader) {
                ERROR("Failed initialising uctx for dl_loader");
                return NULL;
index 22d0439c91b8a15f6d4a5245830401cb9ac81fb8..e9438fecac99a59de0683608c4b5d43a81d0ffdb 100644 (file)
@@ -174,7 +174,7 @@ char const          *dl_module_search_path(void);
 
 dl_loader_t            *dl_loader_from_module_loader(dl_module_loader_t *dl_module_loader);
 
-dl_module_loader_t     *dl_module_loader_init(TALLOC_CTX *ctx, char const *lib_dir);
+dl_module_loader_t     *dl_module_loader_init(char const *lib_dir);
 
 #ifdef __cplusplus
 }
index 51ca52de77edfe6c7df9090a77c969aa0bc96be2..9bbed01504d1b5542a4dfe928f191262ad80cdee 100644 (file)
@@ -401,7 +401,7 @@ static int lib_dir_parse(UNUSED TALLOC_CTX *ctx, UNUSED void *out, UNUSED void *
         *      Initialize the DL infrastructure, which is used by the
         *      config file parser.  And also add in the search path.
         */
-       if (!dl_module_loader_init(NULL, main_config->lib_dir)) {
+       if (!dl_module_loader_init(main_config->lib_dir)) {
                cf_log_err(ci, "Failed initializing 'lib_dir': %s",
                           fr_strerror());
                return -1;