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

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