Blame SOURCES/autofs-5.1.7-fix-inconsistent-locking-in-umount_subtree_mounts.patch

49b67f
autofs-5.1.7 - fix inconsistent locking in umount_subtree_mounts()
49b67f
49b67f
From: Ian Kent <raven@themaw.net>
49b67f
49b67f
Some map entry cache locking inconsistencies have crept in.
49b67f
49b67f
In umount_subtree_mounts() the cache write lock should be held when
49b67f
deleting multi-mount cache entries.
49b67f
49b67f
Signed-off-by: Ian Kent <raven@themaw.net>
49b67f
---
49b67f
 CHANGELOG          |    1 +
49b67f
 daemon/automount.c |   42 ++++++++++++++++++++++++++++++------------
49b67f
 lib/mounts.c       |    8 --------
49b67f
 3 files changed, 31 insertions(+), 20 deletions(-)
49b67f
49b67f
--- autofs-5.1.4.orig/CHANGELOG
49b67f
+++ autofs-5.1.4/CHANGELOG
49b67f
@@ -14,6 +14,7 @@
49b67f
 - eliminate clean_stale_multi_triggers().
49b67f
 - simplify mount_subtree() mount check.
49b67f
 - fix mnts_get_expire_list() expire list construction.
49b67f
+- fix inconsistent locking in umount_subtree_mounts().
49b67f
 
49b67f
 xx/xx/2018 autofs-5.1.5
49b67f
 - fix flag file permission.
49b67f
--- autofs-5.1.4.orig/daemon/automount.c
49b67f
+++ autofs-5.1.4/daemon/automount.c
49b67f
@@ -527,8 +527,11 @@ static int umount_subtree_mounts(struct
49b67f
 	struct mapent_cache *mc;
49b67f
 	struct mapent *me;
49b67f
 	unsigned int is_mm_root = 0;
49b67f
+	int cur_state;
49b67f
 	int left;
49b67f
 
49b67f
+	pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cur_state);
49b67f
+
49b67f
 	me = lookup_source_mapent(ap, path, LKP_DISTINCT);
49b67f
 	if (!me) {
49b67f
 		char *ind_key;
49b67f
@@ -548,11 +551,11 @@ static int umount_subtree_mounts(struct
49b67f
 	left = 0;
49b67f
 
49b67f
 	if (me && me->multi) {
49b67f
-		char root[PATH_MAX];
49b67f
+		char root[PATH_MAX + 1];
49b67f
+		char key[PATH_MAX + 1];
49b67f
+		struct mapent *tmp;
49b67f
+		int status;
49b67f
 		char *base;
49b67f
-		int cur_state;
49b67f
-
49b67f
-		pthread_cleanup_push(cache_lock_cleanup, mc);
49b67f
 
49b67f
 		if (!strchr(me->multi->key, '/'))
49b67f
 			/* Indirect multi-mount root */
49b67f
@@ -567,25 +570,40 @@ static int umount_subtree_mounts(struct
49b67f
 		else
49b67f
 			base = me->key + strlen(root);
49b67f
 
49b67f
-		pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cur_state);
49b67f
-		/* Lock the closest parent nesting point for umount */
49b67f
-		cache_multi_writelock(me->parent);
49b67f
-		if (umount_multi_triggers(ap, me, root, base)) {
49b67f
+		left = umount_multi_triggers(ap, me, root, base);
49b67f
+		if (left) {
49b67f
 			warn(ap->logopt,
49b67f
 			     "some offset mounts still present under %s", path);
49b67f
+		}
49b67f
+
49b67f
+		strcpy(key, me->key);
49b67f
+
49b67f
+		cache_unlock(mc);
49b67f
+		cache_writelock(mc);
49b67f
+		tmp = cache_lookup_distinct(mc, key);
49b67f
+		/* mapent went away while we waited? */
49b67f
+		if (tmp != me) {
49b67f
+			cache_unlock(mc);
49b67f
+			pthread_setcancelstate(cur_state, NULL);
49b67f
+			return 0;
49b67f
+		}
49b67f
+
49b67f
+		if (!left && is_mm_root) {
49b67f
+			status = cache_delete_offset_list(mc, me->key);
49b67f
+			if (status != CHE_OK)
49b67f
+				warn(ap->logopt, "couldn't delete offset list");
49b67f
 			left++;
49b67f
 		}
49b67f
-		cache_multi_unlock(me->parent);
49b67f
+
49b67f
 		if (ap->entry->maps &&
49b67f
 		    (ap->entry->maps->flags & MAP_FLAG_FORMAT_AMD))
49b67f
 			cache_pop_mapent(me);
49b67f
-		pthread_setcancelstate(cur_state, NULL);
49b67f
-		pthread_cleanup_pop(0);
49b67f
 	}
49b67f
-
49b67f
 	if (me)
49b67f
 		cache_unlock(mc);
49b67f
 
49b67f
+	pthread_setcancelstate(cur_state, NULL);
49b67f
+
49b67f
 	if (left || is_autofs_fs)
49b67f
 		return left;
49b67f
 
49b67f
--- autofs-5.1.4.orig/lib/mounts.c
49b67f
+++ autofs-5.1.4/lib/mounts.c
49b67f
@@ -2730,9 +2730,6 @@ int umount_multi_triggers(struct autofs_
49b67f
 	left = do_umount_multi_triggers(ap, me, root, base);
49b67f
 
49b67f
 	if (!left && me->multi == me) {
49b67f
-		struct mapent_cache *mc = me->mc;
49b67f
-		int status;
49b67f
-
49b67f
 		/*
49b67f
 		 * Special case.
49b67f
 		 * If we can't umount the root container then we can't
49b67f
@@ -2750,11 +2747,6 @@ int umount_multi_triggers(struct autofs_
49b67f
 			}
49b67f
 		}
49b67f
 
49b67f
-		/* We're done - clean out the offsets */
49b67f
-		status = cache_delete_offset_list(mc, me->key);
49b67f
-		if (status != CHE_OK)
49b67f
-			warn(ap->logopt, "couldn't delete offset list");
49b67f
-
49b67f
 	       /* check for mounted mount entry and remove it if found */
49b67f
                mnts_remove_mount(root, MNTS_MOUNTED);
49b67f
 	}