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

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