chiark / gitweb /
tmpfiles: silently ignore any path that passes through autofs (#6506)
authorNeilBrown <neil@brown.name>
Mon, 4 Sep 2017 13:35:07 +0000 (23:35 +1000)
committerSven Eden <yamakuzure@gmx.net>
Mon, 4 Sep 2017 13:35:07 +0000 (23:35 +1000)
If a path passes though an autofs filesystem, then accessing
the path might trigger and automount.  As elogind-tmpfiles is run before
the network is up, and as automounts are often used for networked
filesystems, this can cause a deadlock.

So chase_symlinks is enhance to accept a new flag which tells it
to check for autofs, and return -EREMOTE if autofs is found.

tmpfiles is changed to check just before acting on a path so that it
can avoid autofs even if a symlink was created earlier by tmpfiles
that would send this path through an autofs.

This fixes a deadlock that happens when /home is listed in /etc/fstab as
x-elogind.automount for an NFS directory.

src/basic/fs-util.c
src/basic/fs-util.h

index cf5c80eca4d27b15cf7d6c3014ea9f5777839295..c8b5ad4322f680f11fb070b12b1a00385e51af32 100644 (file)
@@ -23,6 +23,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <sys/stat.h>
+#include <linux/magic.h>
 #include <time.h>
 #include <unistd.h>
 
@@ -733,6 +734,9 @@ int chase_symlinks(const char *path, const char *original_root, unsigned flags,
 
                 if (fstat(child, &st) < 0)
                         return -errno;
+                if ((flags & CHASE_NO_AUTOFS) &&
+                    fd_check_fstype(child, AUTOFS_SUPER_MAGIC) > 0)
+                        return -EREMOTE;
 
                 if (S_ISLNK(st.st_mode)) {
                         char *joined;
index 4c6bb659afa6014d7e7a0b4be22f96b21dec400f..a9ec7611d121982f473dfbd296a3a8a3ece21354 100644 (file)
@@ -96,6 +96,7 @@ int inotify_add_watch_fd(int fd, int what, uint32_t mask);
 enum {
         CHASE_PREFIX_ROOT = 1,   /* If set, the specified path will be prefixed by the specified root before beginning the iteration */
         CHASE_NONEXISTENT = 2,   /* If set, it's OK if the path doesn't actually exist. */
+        CHASE_NO_AUTOFS = 4,     /* If set, return -EREMOTE if autofs mount point found */
 };
 
 int chase_symlinks(const char *path_with_prefix, const char *root, unsigned flags, char **ret);