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

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