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

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