You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by co...@apache.org on 2019/04/01 14:29:14 UTC

svn commit: r1856735 - in /httpd/httpd/trunk: CHANGES modules/ldap/util_ldap.c modules/ldap/util_ldap_cache.c

Author: covener
Date: Mon Apr  1 14:29:14 2019
New Revision: 1856735

URL: http://svn.apache.org/viewvc?rev=1856735&view=rev
Log:
PR63305: fix graceful restart crashes in LDAP

The cache destruction was not protected by the lock used by other
cache callers.

Pull the static cleanup function into util_ldap.c so it's convenient to 
use the existing locking.

Submitted By: Martin Fúsek <mfusek newps.cz>
Commited By: covener


Modified:
    httpd/httpd/trunk/CHANGES
    httpd/httpd/trunk/modules/ldap/util_ldap.c
    httpd/httpd/trunk/modules/ldap/util_ldap_cache.c

Modified: httpd/httpd/trunk/CHANGES
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/CHANGES?rev=1856735&r1=1856734&r2=1856735&view=diff
==============================================================================
--- httpd/httpd/trunk/CHANGES [utf-8] (original)
+++ httpd/httpd/trunk/CHANGES [utf-8] Mon Apr  1 14:29:14 2019
@@ -1,6 +1,10 @@
                                                          -*- coding: utf-8 -*-
 Changes with Apache 2.5.1
 
+  *) mod_ldap: Avoid potential crashes in util_ldap_cache_module_kill() or other
+     LDAP related functions during graceful restart of a busy server. PR63305.
+     [Martin Fúsek <mfusek newps.cz>]
+
   *) mod_cache: Fix parsing of quoted Cache-Control token arguments.
      PR 63288. [Yann Ylavic]
 

Modified: httpd/httpd/trunk/modules/ldap/util_ldap.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/ldap/util_ldap.c?rev=1856735&r1=1856734&r2=1856735&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/ldap/util_ldap.c (original)
+++ httpd/httpd/trunk/modules/ldap/util_ldap.c Mon Apr  1 14:29:14 2019
@@ -81,7 +81,12 @@ static APR_INLINE apr_status_t ldap_cach
     if (st->util_ldap_cache_lock) { 
         apr_status_t rv = apr_global_mutex_lock(st->util_ldap_cache_lock);
         if (rv != APR_SUCCESS) { 
-            ap_log_rerror(APLOG_MARK, APLOG_CRIT, rv, r, APLOGNO(10134) "LDAP cache lock failed");
+            if (r) {
+                ap_log_rerror(APLOG_MARK, APLOG_CRIT, rv, r, APLOGNO(10134) "LDAP cache lock failed");
+            }
+            else { 
+                ap_log_error(APLOG_MARK, APLOG_CRIT, rv, NULL, APLOGNO(10134) "LDAP cache lock failed");
+            }
             ap_assert(0);
         }
     }
@@ -92,7 +97,12 @@ static APR_INLINE apr_status_t ldap_cach
     if (st->util_ldap_cache_lock) { 
         apr_status_t rv = apr_global_mutex_unlock(st->util_ldap_cache_lock);
         if (rv != APR_SUCCESS) { 
-            ap_log_rerror(APLOG_MARK, APLOG_CRIT, rv, r, APLOGNO(10135) "LDAP cache lock failed");
+            if (r != NULL) {
+                ap_log_rerror(APLOG_MARK, APLOG_CRIT, rv, r, APLOGNO(10135) "LDAP cache unlock failed");
+            }
+            else { 
+                ap_log_error(APLOG_MARK, APLOG_CRIT, rv, NULL, APLOGNO(10135) "LDAP cache unlock failed");
+            }
             ap_assert(0);
         }
     }
@@ -111,6 +121,25 @@ static void util_ldap_strdup (char **str
     }
 }
 
+static apr_status_t util_ldap_cache_module_kill(void *data)
+{
+    util_ldap_state_t *st = data;
+
+    util_ald_destroy_cache(st->util_ldap_cache);
+#if APR_HAS_SHARED_MEMORY
+    if (st->cache_rmm != NULL) {
+        apr_rmm_destroy (st->cache_rmm);
+        st->cache_rmm = NULL;
+    }
+    if (st->cache_shm != NULL) {
+        apr_status_t result = apr_shm_destroy(st->cache_shm);
+        st->cache_shm = NULL;
+        return result;
+    }
+#endif
+    return APR_SUCCESS;
+}
+
 /*
  * Status Handler
  * --------------
@@ -2932,6 +2961,18 @@ static int util_ldap_pre_config(apr_pool
     return OK;
 }
 
+static apr_status_t util_ldap_cache_module_kill_locked(void *data)
+{
+    apr_status_t result;
+    util_ldap_state_t *st = data;
+
+    ldap_cache_lock(st, NULL);
+    result = util_ldap_cache_module_kill(data);
+    ldap_cache_unlock(st, NULL);
+
+    return result;
+}
+
 static int util_ldap_post_config(apr_pool_t *p, apr_pool_t *plog,
                                  apr_pool_t *ptemp, server_rec *s)
 {
@@ -2979,6 +3020,8 @@ static int util_ldap_post_config(apr_poo
             return DONE;
         }
 
+        apr_pool_cleanup_register(st->pool, st , util_ldap_cache_module_kill_locked, apr_pool_cleanup_null);
+
         result = ap_global_mutex_create(&st->util_ldap_cache_lock, NULL,
                                         ldap_cache_mutex_type, NULL, s, p, 0);
         if (result != APR_SUCCESS) {

Modified: httpd/httpd/trunk/modules/ldap/util_ldap_cache.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/ldap/util_ldap_cache.c?rev=1856735&r1=1856734&r2=1856735&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/ldap/util_ldap_cache.c (original)
+++ httpd/httpd/trunk/modules/ldap/util_ldap_cache.c Mon Apr  1 14:29:14 2019
@@ -396,26 +396,6 @@ void util_ldap_dn_compare_node_display(r
 }
 
 
-/* ------------------------------------------------------------------ */
-static apr_status_t util_ldap_cache_module_kill(void *data)
-{
-    util_ldap_state_t *st = data;
-
-    util_ald_destroy_cache(st->util_ldap_cache);
-#if APR_HAS_SHARED_MEMORY
-    if (st->cache_rmm != NULL) {
-        apr_rmm_destroy (st->cache_rmm);
-        st->cache_rmm = NULL;
-    }
-    if (st->cache_shm != NULL) {
-        apr_status_t result = apr_shm_destroy(st->cache_shm);
-        st->cache_shm = NULL;
-        return result;
-    }
-#endif
-    return APR_SUCCESS;
-}
-
 apr_status_t util_ldap_cache_init(apr_pool_t *pool, util_ldap_state_t *st)
 {
 #if APR_HAS_SHARED_MEMORY
@@ -449,8 +429,6 @@ apr_status_t util_ldap_cache_init(apr_po
 
 #endif
 
-    apr_pool_cleanup_register(st->pool, st , util_ldap_cache_module_kill, apr_pool_cleanup_null);
-
     st->util_ldap_cache =
         util_ald_create_cache(st,
                               st->search_cache_size,