ldap/servers/slapd/backend_manager.c | 1 + ldap/servers/slapd/daemon.c | 2 +- ldap/servers/slapd/plugin.c | 12 +++++++++--- ldap/servers/slapd/proto-slap.h | 1 + ldap/servers/slapd/util.c | 33 ++++++--------------------------- 5 files changed, 18 insertions(+), 31 deletions(-)
New commits: commit 0f4f838b29df3e33bf0751c80baf2d4e052856ef Author: William Brown firstyear@redhat.com Date: Thu Jun 2 11:04:05 2016 +1000
Ticket 48863 - remove check for vmsize from util_info_sys_pages
Bug Description: https://bugzilla.redhat.com/show_bug.cgi?id=1341709 and on another instance could not allocate cache because it would exceed memory size
In both cases I suspect that that vmsize was low, and this causes the util_info_sys_pages check to return a low pages number, which triggers the checking to fail
Fix Description: Remove the checks related to vmsize. It's either too low, or just too high and wrong. Either way, we never rely on it. Lets use reliable data.
https://fedorahosted.org/389/ticket/48863
Author: wibrown
Review by: nhosoi (Thanks!)
diff --git a/ldap/servers/slapd/util.c b/ldap/servers/slapd/util.c index 89c7579..3f17461 100644 --- a/ldap/servers/slapd/util.c +++ b/ldap/servers/slapd/util.c @@ -1538,7 +1538,7 @@ int util_info_sys_pages(size_t *pagesize, size_t *pages, size_t *procpages, size * This space is a "funny number". It's a best effort based system * where linux instead of telling us how much memory *actually* exists * for us to use, gives us a virtual memory allocation which is the - * value of ram + swap. + * value of ram + swap.... sometimes. Depends on platform. * * But none of these pages even exist or belong to us on the real system * until will malloc them AND write a non-zero to them. @@ -1569,13 +1569,12 @@ int util_info_sys_pages(size_t *pagesize, size_t *pages, size_t *procpages, size * potentially allocate: generally, this will be MemAvailable. */
- size_t vmsize = 0; size_t freesize = 0; size_t rlimsize = 0;
*pagesize = getpagesize();
- /* Get the amount of freeram, rss, and the vmsize */ + /* Get the amount of freeram, rss */
FILE *f; char fn[40], s[80]; @@ -1596,9 +1595,6 @@ int util_info_sys_pages(size_t *pagesize, size_t *pages, size_t *procpages, size /* VmRSS shows us what we are ACTUALLY using for proc pages * Rather than "funny" pages. */ - if (strncmp(s, "VmSize:", 7) == 0) { - sscanf(s+7, "%lu", (long unsigned int *)&vmsize); - } if (strncmp(s, "VmRSS:", 6) == 0) { sscanf(s+6, "%lu", (long unsigned int *)procpages); } @@ -1641,29 +1637,11 @@ int util_info_sys_pages(size_t *pagesize, size_t *pages, size_t *procpages, size /* This is in bytes, make it pages */ rlimsize = rlimsize / *pagesize; } - /* Now we have vmsize, the availpages from getrlimit, our freesize */ - vmsize /= (*pagesize / 1024);
- /* Pages is the total ram on the system. We should smaller of: - * - vmsize - * - pages - */ - LDAPDebug(LDAP_DEBUG_TRACE,"util_info_sys_pages pages=%lu, vmsize=%lu, \n", - (unsigned long) *pages, (unsigned long) vmsize,0); -#if __GNUC__ -#if __x86_64__ || __ppc64__ - /* On 64bit platforms, vmsize is set high (VmSize), and doesn't change. IE 17tb */ - if (vmsize < *pages) { - LDAPDebug(LDAP_DEBUG_TRACE,"util_info_sys_pages using vmsize for pages \n",0,0,0); - *pages = vmsize; - } else { - LDAPDebug(LDAP_DEBUG_TRACE,"util_info_sys_pages using pages for pages \n",0,0,0); - } -#else - /* On 32bit platforms, vmsize is set low (VmSize) and grows. */ + /* Pages is the total ram on the system. */ + LDAPDebug(LDAP_DEBUG_TRACE,"util_info_sys_pages pages=%lu, \n", + (unsigned long) *pages, 0,0); LDAPDebug(LDAP_DEBUG_TRACE,"util_info_sys_pages using pages for pages \n",0,0,0); -#endif -#endif
/* Availpages is how much we *could* alloc. We should take the smallest: * - pages @@ -1809,6 +1787,7 @@ int util_is_cachesize_sane(size_t *cachesize) * the remaining system mem to the cachesize instead, and log a warning */ *cachesize = (size_t)((availpages * 0.75 ) * pagesize); + slapi_log_error(SLAPI_LOG_FATAL, "util_is_cachesize_sane", "Available pages %lu, requested pages %lu, pagesize %lu\n", (unsigned long)availpages, (unsigned long)cachepages, (unsigned long)pagesize); slapi_log_error(SLAPI_LOG_FATAL, "util_is_cachesize_sane", "WARNING adjusted cachesize to %lu\n", (unsigned long)*cachesize); } #else
commit e7aabb539a8f05bc9c1c5e90c4e4a2cbfbc826cb Author: William Brown firstyear@redhat.com Date: Tue Jun 7 13:49:20 2016 +1000
Ticket 48872 - Fix segfault and use after free in plugin shutdown
Bug Description: Plugin_closeall would free the plugin password name scheme value *even* if the plugin was not a password scheme.
backend manager would call be_cleanup on the plugin *after* plugin_closeall was run. This means plugin_closeall now does not close backends, and we call plugin_free from the backend to do this.
Fix Description: Check the union type to make sure we free the pwdscheme only on password plugins.
Expose plugin_free, and call it from the backend manager. Don't close backends during the call to plugin_closeall.
https://fedorahosted.org/389/ticket/48872
Author: wibrown
Review by: mreynolds (Thanks!)
diff --git a/ldap/servers/slapd/backend_manager.c b/ldap/servers/slapd/backend_manager.c index 9084d95..979144a 100644 --- a/ldap/servers/slapd/backend_manager.c +++ b/ldap/servers/slapd/backend_manager.c @@ -323,6 +323,7 @@ be_cleanupall() slapi_pblock_set( &pb, SLAPI_BACKEND, backends[i] );
(*backends[i]->be_cleanup)( &pb ); + plugin_free(backends[i]->be_database); slapi_be_free(&backends[i]); } } diff --git a/ldap/servers/slapd/daemon.c b/ldap/servers/slapd/daemon.c index 862f6e7..90d1f7d 100644 --- a/ldap/servers/slapd/daemon.c +++ b/ldap/servers/slapd/daemon.c @@ -1318,7 +1318,7 @@ void slapd_daemon( daemon_ports_t *ports ) uniqueIDGenCleanup (); }
- plugin_closeall( 1 /* Close Backends */, 1 /* Close Globals */); + plugin_closeall( 0 /* Close Backends */, 1 /* Close Globals */);
if ( ! in_referral_mode ) { /* Close SNMP collator after the plugins closed... diff --git a/ldap/servers/slapd/plugin.c b/ldap/servers/slapd/plugin.c index 39bfcef..a2b2d75 100644 --- a/ldap/servers/slapd/plugin.c +++ b/ldap/servers/slapd/plugin.c @@ -52,7 +52,6 @@ static PRBool plugin_matches_operation (Slapi_DN *target_spec, PluginTargetData
static void plugin_config_init (struct pluginconfig *config); static void plugin_config_cleanup (struct pluginconfig *config); -static void plugin_free(struct slapdplugin *plugin); static int plugin_config_set_action (int *action, char *value); static struct pluginconfig* plugin_get_config (struct slapdplugin *plugin); static void default_plugin_init(); @@ -1951,6 +1950,10 @@ plugin_closeall(int close_backends, int close_globals) iterp = dep_plugin_entries; while (iterp) { nextp = iterp->next; + if (close_backends == 0 && iterp->plugin->plg_type == SLAPI_PLUGIN_DATABASE) { + iterp = nextp; + continue; + } slapi_entry_free(iterp->e); plugin_free(iterp->plugin); slapi_ch_free((void **)&iterp); @@ -2703,15 +2706,18 @@ plugin_add_descriptive_attributes( Slapi_Entry *e, struct slapdplugin *plugin ) /* clean up the memory associated with the plugin */ -static void +void plugin_free(struct slapdplugin *plugin) { + slapi_log_error(SLAPI_LOG_TRACE, "plugin_free", "Freeing %s \n", plugin->plg_name ); charray_free(plugin->plg_argv); slapi_ch_free_string(&plugin->plg_libpath); slapi_ch_free_string(&plugin->plg_initfunc); slapi_ch_free_string(&plugin->plg_name); slapi_ch_free_string(&plugin->plg_dn); - slapi_ch_free_string(&plugin->plg_pwdstorageschemename); + if (plugin->plg_type == SLAPI_PLUGIN_PWD_STORAGE_SCHEME) { + slapi_ch_free_string(&plugin->plg_pwdstorageschemename); + } release_componentid(plugin->plg_identity); slapi_counter_destroy(&plugin->plg_op_counter); if (!plugin->plg_group) diff --git a/ldap/servers/slapd/proto-slap.h b/ldap/servers/slapd/proto-slap.h index b8d7b86..1de1e38 100644 --- a/ldap/servers/slapd/proto-slap.h +++ b/ldap/servers/slapd/proto-slap.h @@ -879,6 +879,7 @@ void global_plugin_init(); int plugin_call_plugins( Slapi_PBlock *, int ); int plugin_setup(Slapi_Entry *plugin_entry, struct slapi_componentid *group, slapi_plugin_init_fnptr initfunc, int add_to_dit, char *returntext); +void plugin_free(struct slapdplugin *plugin); int plugin_determine_exop_plugins( const char *oid, struct slapdplugin **plugin ); int plugin_call_exop_plugins( Slapi_PBlock *pb, struct slapdplugin *p ); Slapi_Backend * plugin_extended_op_getbackend( Slapi_PBlock *pb, struct slapdplugin *p);
389-commits@lists.fedoraproject.org