From: Alan T. DeKok Date: Thu, 20 Jun 2019 17:15:01 +0000 (-0400) Subject: use local talloc ctx for modules X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=eb84b919cd39ade9ab9bb3ef4e84cb8e7c25ef90;p=thirdparty%2Ffreeradius-server.git use local talloc ctx for modules 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 --- diff --git a/src/bin/radiusd.c b/src/bin/radiusd.c index 0c498a877aa..7c8780807f1 100644 --- a/src/bin/radiusd.c +++ b/src/bin/radiusd.c @@ -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 */ diff --git a/src/bin/unit_test_attribute.c b/src/bin/unit_test_attribute.c index a0b61a3970c..340d55cfc2b 100644 --- a/src/bin/unit_test_attribute.c +++ b/src/bin/unit_test_attribute.c @@ -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(); diff --git a/src/bin/unit_test_module.c b/src/bin/unit_test_module.c index 7a8da0227e7..eb0e8ae11c4 100644 --- a/src/bin/unit_test_module.c +++ b/src/bin/unit_test_module.c @@ -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 diff --git a/src/lib/server/dl_module.c b/src/lib/server/dl_module.c index 5733d2b340a..d3ab75cb2d3 100644 --- a/src/lib/server/dl_module.c +++ b/src/lib/server/dl_module.c @@ -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; diff --git a/src/lib/server/dl_module.h b/src/lib/server/dl_module.h index 22d0439c91b..e9438fecac9 100644 --- a/src/lib/server/dl_module.h +++ b/src/lib/server/dl_module.h @@ -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 } diff --git a/src/lib/server/main_config.c b/src/lib/server/main_config.c index 51ca52de77e..9bbed01504d 100644 --- a/src/lib/server/main_config.c +++ b/src/lib/server/main_config.c @@ -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;