Blame SOURCES/autofs-5.1.7-fix-direct-mount-deadlock.patch

96dc52
autofs-5.1.7 - fix direct mount deadlock
96dc52
96dc52
From: Ian Kent <raven@themaw.net>
96dc52
96dc52
When umounting direct mounts at exit or when umounting mounts no
96dc52
longer in the map on re-load a deadlock can occur.
96dc52
96dc52
Signed-off-by: Ian Kent <raven@themaw.net>
96dc52
---
96dc52
 CHANGELOG       |    1 +
96dc52
 daemon/direct.c |   22 +++++++++++++++++++++-
96dc52
 daemon/state.c  |   14 +++++++++-----
96dc52
 3 files changed, 31 insertions(+), 6 deletions(-)
96dc52
96dc52
--- autofs-5.1.7.orig/CHANGELOG
96dc52
+++ autofs-5.1.7/CHANGELOG
96dc52
@@ -73,6 +73,7 @@
96dc52
 - use mapent tree root for tree_mapent_add_node().
96dc52
 - eliminate redundant cache lookup in tree_mapent_add_node().
96dc52
 - fix hosts map offset order.
96dc52
+- fix direct mount deadlock.
96dc52
 
96dc52
 25/01/2021 autofs-5.1.7
96dc52
 - make bind mounts propagation slave by default.
96dc52
--- autofs-5.1.7.orig/daemon/direct.c
96dc52
+++ autofs-5.1.7/daemon/direct.c
96dc52
@@ -84,11 +84,27 @@ static void mnts_cleanup(void *arg)
96dc52
 int do_umount_autofs_direct(struct autofs_point *ap, struct mapent *me)
96dc52
 {
96dc52
 	struct ioctl_ops *ops = get_ioctl_ops();
96dc52
+	struct mapent_cache *mc = me->mc;
96dc52
 	char buf[MAX_ERR_BUF];
96dc52
 	int ioctlfd = -1, rv, left, retries;
96dc52
+	char key[PATH_MAX + 1];
96dc52
+	struct mapent *tmp;
96dc52
 	int opened = 0;
96dc52
 
96dc52
-	left = umount_multi(ap, me->key, 0);
96dc52
+	if (me->len > PATH_MAX) {
96dc52
+		error(ap->logopt, "path too long");
96dc52
+		return 1;
96dc52
+	}
96dc52
+	strcpy(key, me->key);
96dc52
+
96dc52
+	cache_unlock(mc);
96dc52
+	left = umount_multi(ap, key, 0);
96dc52
+	cache_readlock(mc);
96dc52
+	tmp = cache_lookup_distinct(mc, key);
96dc52
+	if (tmp != me) {
96dc52
+		error(ap->logopt, "key %s no longer in mapent cache", key);
96dc52
+		return -1;
96dc52
+	}
96dc52
 	if (left) {
96dc52
 		warn(ap->logopt, "could not unmount %d dirs under %s",
96dc52
 		     left, me->key);
96dc52
@@ -213,6 +229,7 @@ int umount_autofs_direct(struct autofs_p
96dc52
 		mc = map->mc;
96dc52
 		pthread_cleanup_push(cache_lock_cleanup, mc);
96dc52
 		cache_readlock(mc);
96dc52
+restart:
96dc52
 		me = cache_enumerate(mc, NULL);
96dc52
 		while (me) {
96dc52
 			int error;
96dc52
@@ -230,6 +247,9 @@ int umount_autofs_direct(struct autofs_p
96dc52
 			 * failed umount.
96dc52
 			 */
96dc52
 			error = do_umount_autofs_direct(ap, me);
96dc52
+			/* cache became invalid, restart */
96dc52
+			if (error == -1)
96dc52
+				goto restart;
96dc52
 			if (!error)
96dc52
 				goto done;
96dc52
 
96dc52
--- autofs-5.1.7.orig/daemon/state.c
96dc52
+++ autofs-5.1.7/daemon/state.c
96dc52
@@ -324,11 +324,12 @@ static void do_readmap_cleanup(void *arg
96dc52
 	return;
96dc52
 }
96dc52
 
96dc52
-static void do_readmap_mount(struct autofs_point *ap,
96dc52
+static int do_readmap_mount(struct autofs_point *ap,
96dc52
 			     struct map_source *map, struct mapent *me, time_t now)
96dc52
 {
96dc52
 	struct mapent_cache *nc;
96dc52
 	struct mapent *ne, *nested, *valid;
96dc52
+	int ret = 0;
96dc52
 
96dc52
 	nc = ap->entry->master->nc;
96dc52
 
96dc52
@@ -387,7 +388,7 @@ static void do_readmap_mount(struct auto
96dc52
 				cache_unlock(vmc);
96dc52
 				error(ap->logopt,
96dc52
 				     "failed to find expected existing valid map entry");
96dc52
-				return;
96dc52
+				return ret;
96dc52
 			}
96dc52
 			/* Take over the mount if there is one */
96dc52
 			valid->ioctlfd = me->ioctlfd;
96dc52
@@ -406,14 +407,14 @@ static void do_readmap_mount(struct auto
96dc52
 					ap->exp_runfreq = runfreq;
96dc52
 			}
96dc52
 		} else if (!is_mounted(me->key, MNTS_REAL))
96dc52
-			do_umount_autofs_direct(ap, me);
96dc52
+			ret = do_umount_autofs_direct(ap, me);
96dc52
 		else
96dc52
 			debug(ap->logopt,
96dc52
 			      "%s is mounted", me->key);
96dc52
 	} else
96dc52
 		do_mount_autofs_direct(ap, me, get_exp_timeout(ap, map));
96dc52
 
96dc52
-	return;
96dc52
+	return ret;
96dc52
 }
96dc52
 
96dc52
 static void *do_readmap(void *arg)
96dc52
@@ -480,9 +481,12 @@ static void *do_readmap(void *arg)
96dc52
 			mc = map->mc;
96dc52
 			pthread_cleanup_push(cache_lock_cleanup, mc);
96dc52
 			cache_readlock(mc);
96dc52
+restart:
96dc52
 			me = cache_enumerate(mc, NULL);
96dc52
 			while (me) {
96dc52
-				do_readmap_mount(ap, map, me, now);
96dc52
+				int ret = do_readmap_mount(ap, map, me, now);
96dc52
+				if (ret == -1)
96dc52
+					goto restart;
96dc52
 				me = cache_enumerate(mc, me);
96dc52
 			}
96dc52
 			lookup_prune_one_cache(ap, map->mc, now);