git: 361f7820cde9 - stable/14 - automount: check for mounted-over autofs instances on flush

From: Konstantin Belousov <kib_at_FreeBSD.org>
Date: Tue, 24 Oct 2023 00:46:32 UTC
The branch stable/14 has been updated by kib:

URL: https://cgit.FreeBSD.org/src/commit/?id=361f7820cde9cc9e9eb7118155b6a39c1a52ef9d

commit 361f7820cde9cc9e9eb7118155b6a39c1a52ef9d
Author:     Andrew Gierth <andrew@tao146.riddles.org.uk>
AuthorDate: 2023-07-10 15:09:56 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2023-10-24 00:46:01 +0000

    automount: check for mounted-over autofs instances on flush
    
    PR:     272446
    
    (cherry picked from commit 21b8e363c4eb24c0a5659101603cc08a86d87759)
---
 usr.sbin/autofs/automount.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/usr.sbin/autofs/automount.c b/usr.sbin/autofs/automount.c
index 188bbc3a040f..cee647cb4e2c 100644
--- a/usr.sbin/autofs/automount.c
+++ b/usr.sbin/autofs/automount.c
@@ -260,6 +260,7 @@ static void
 flush_caches(void)
 {
 	struct statfs *mntbuf;
+	struct statfs statbuf;
 	int i, nitems;
 
 	nitems = getmntinfo(&mntbuf, MNT_WAIT);
@@ -274,6 +275,21 @@ flush_caches(void)
 			    mntbuf[i].f_mntonname);
 			continue;
 		}
+		/*
+		 * A direct map mountpoint may have been mounted over, in
+		 * which case we can't MNT_UPDATE it. There's an obvious race
+		 * condition remaining here, but that has to be fixed in the
+		 * kernel.
+		 */
+		if (statfs(mntbuf[i].f_mntonname, &statbuf) != 0) {
+			log_err(1, "cannot statfs %s", mntbuf[i].f_mntonname);
+			continue;
+		}
+		if (strcmp(statbuf.f_fstypename, "autofs") != 0) {
+			log_debugx("skipping %s, filesystem type is not autofs",
+			    mntbuf[i].f_mntonname);
+			continue;
+		}
 
 		flush_autofs(mntbuf[i].f_mntonname);
 	}