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

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