Blame SOURCES/autofs-5.1.8-fix-hosts-map-deadlock-on-restart.patch

591f3a
autofs-5.1.8 - fix hosts map deadlock on restart
591f3a
591f3a
From: Ian Kent <raven@themaw.net>
591f3a
591f3a
When starting automount(8) with a hosts map that has mounts that were
591f3a
in use at the last exit a deadlock can occur.
591f3a
591f3a
In this case automount(8) will perform the same steps but not actually
591f3a
perform the mount to re-construct the context of each mount. But, with
591f3a
the hosts map, that leads to calling back into the sun parse module
591f3a
while holding the map module read lock which will again try and take
591f3a
the write lock.
591f3a
591f3a
Fix this by only taking the write lock in the mount code path if the
591f3a
module handle has not already been opened.
591f3a
591f3a
Signed-off-by: Ian Kent <raven@themaw.net>
591f3a
---
591f3a
 CHANGELOG           |    1 +
591f3a
 daemon/lookup.c     |   22 ++++++++++++----------
591f3a
 modules/parse_amd.c |   18 ++++++++++--------
591f3a
 3 files changed, 23 insertions(+), 18 deletions(-)
591f3a
591f3a
--- autofs-5.1.4.orig/CHANGELOG
591f3a
+++ autofs-5.1.4/CHANGELOG
591f3a
@@ -99,6 +99,7 @@
591f3a
 - fix parse module instance mutex naming.
591f3a
 - serialise lookup module open and reinit.
591f3a
 - coverity fix for invalid access.
591f3a
+- fix hosts map deadlock on restart.
591f3a
 
591f3a
 xx/xx/2018 autofs-5.1.5
591f3a
 - fix flag file permission.
591f3a
--- autofs-5.1.4.orig/daemon/lookup.c
591f3a
+++ autofs-5.1.4/daemon/lookup.c
591f3a
@@ -815,19 +815,21 @@ int do_lookup_mount(struct autofs_point
591f3a
 	struct lookup_mod *lookup;
591f3a
 	int status;
591f3a
 
591f3a
-	map_module_writelock(map);
591f3a
 	if (!map->lookup) {
591f3a
-		status = open_lookup(map->type, "",
591f3a
-				     map->format, map->argc, map->argv, &lookup);
591f3a
-		if (status != NSS_STATUS_SUCCESS) {
591f3a
-			map_module_unlock(map);
591f3a
-			debug(ap->logopt,
591f3a
-			      "lookup module %s open failed", map->type);
591f3a
-			return status;
591f3a
+		map_module_writelock(map);
591f3a
+		if (!map->lookup) {
591f3a
+			status = open_lookup(map->type, "",
591f3a
+					     map->format, map->argc, map->argv, &lookup);
591f3a
+			if (status != NSS_STATUS_SUCCESS) {
591f3a
+				map_module_unlock(map);
591f3a
+				debug(ap->logopt,
591f3a
+				      "lookup module %s open failed", map->type);
591f3a
+				return status;
591f3a
+			}
591f3a
+			map->lookup = lookup;
591f3a
 		}
591f3a
-		map->lookup = lookup;
591f3a
+		map_module_unlock(map);
591f3a
 	}
591f3a
-	map_module_unlock(map);
591f3a
 
591f3a
 	master_source_current_wait(ap->entry);
591f3a
 	ap->entry->current = map;
591f3a
--- autofs-5.1.4.orig/modules/parse_amd.c
591f3a
+++ autofs-5.1.4/modules/parse_amd.c
591f3a
@@ -1370,17 +1370,19 @@ static int do_host_mount(struct autofs_p
591f3a
 		}
591f3a
 	}
591f3a
 
591f3a
-	map_module_writelock(instance);
591f3a
 	if (!instance->lookup) {
591f3a
-		status = open_lookup("hosts", MODPREFIX, NULL, argc, pargv, &lookup);
591f3a
-		if (status != NSS_STATUS_SUCCESS) {
591f3a
-			map_module_unlock(instance);
591f3a
-			debug(ap->logopt, "open lookup module hosts failed");
591f3a
-			goto out;
591f3a
+		map_module_writelock(instance);
591f3a
+		if (!instance->lookup) {
591f3a
+			status = open_lookup("hosts", MODPREFIX, NULL, argc, pargv, &lookup);
591f3a
+			if (status != NSS_STATUS_SUCCESS) {
591f3a
+				map_module_unlock(instance);
591f3a
+				debug(ap->logopt, "open lookup module hosts failed");
591f3a
+				goto out;
591f3a
+			}
591f3a
+			instance->lookup = lookup;
591f3a
 		}
591f3a
-		instance->lookup = lookup;
591f3a
+		map_module_unlock(instance);
591f3a
 	}
591f3a
-	map_module_unlock(instance);
591f3a
 
591f3a
 	cache_writelock(source->mc);
591f3a
 	me = cache_lookup_distinct(source->mc, name);