Blame SOURCES/xfsprogs-4.17.0-xfsprogs-be-careful-about-what-we-stat-in-platform_c.patch

89952e
From 98c4a01c21b99b13d8aaa406ab15b7424ee5ef9f Mon Sep 17 00:00:00 2001
89952e
From: Eric Sandeen <sandeen@redhat.com>
89952e
Date: Wed, 23 May 2018 16:30:49 -0500
89952e
Subject: [PATCH] xfsprogs: be careful about what we stat in
89952e
 platform_check_mount
89952e
89952e
After we lost ustat(2) in commit 4e7a824, we ended up with a slightly
89952e
bonkers method to determine if our target block device was mounted:
89952e
it goes through every entry returned by getmntent and stats the dir
89952e
to see if its underlying device matches ours.
89952e
89952e
Unfortunately that dir might be a hung nfs server and sadness ensues.
89952e
89952e
So just do a really simple sanity check before we try to stat the
89952e
mountpoint: does its device start with a / ?  If not, skip it.
89952e
89952e
Fixes: 4e7a824 ("libxfs/linux.c: Replace use of ustat by stat")
89952e
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
89952e
Reviewed-by: Allison Henderson <allison.henderson@oracle.com>
89952e
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
89952e
---
89952e
 libfrog/linux.c | 10 ++++++++++
89952e
 1 file changed, 10 insertions(+)
89952e
89952e
Index: xfsprogs-4.5.0/libxfs/linux.c
89952e
===================================================================
89952e
--- xfsprogs-4.5.0.orig/libxfs/linux.c
89952e
+++ xfsprogs-4.5.0/libxfs/linux.c
89952e
@@ -68,7 +68,17 @@ platform_check_ismounted(char *name, cha
89952e
 		    progname, name);
89952e
 		return 1;
89952e
 	}
89952e
+	/*
89952e
+	 * This whole business is to work out if our block device is mounted
89952e
+	 * after we lost ustat(2), see:
89952e
+	 *      4e7a824 libxfs/linux.c: Replace use of ustat by stat
89952e
+	 * We don't really want to stat every single mounted directory,
89952e
+	 * as that may include tmpfs, cgroups, procfs or - worst - hung nfs
89952e
+	 * servers.  So first, a simple check: does the "dev" start with "/" ?
89952e
+	 */
89952e
 	while ((mnt = getmntent(f)) != NULL) {
89952e
+		if (mnt->mnt_fsname[0] != '/')
89952e
+			continue;
89952e
 		if (stat64(mnt->mnt_dir, &mst) < 0)
89952e
 			continue;
89952e
 		if (mst.st_dev != s->st_rdev)
89952e
@@ -99,7 +109,17 @@ platform_check_iswritable(char *name, ch
89952e
 				"mounted filesystem\n"), progname, name);
89952e
 			return fatal;
89952e
 	}
89952e
+	/*
89952e
+	 * This whole business is to work out if our block device is mounted
89952e
+	 * after we lost ustat(2), see:
89952e
+	 *      4e7a824 libxfs/linux.c: Replace use of ustat by stat
89952e
+	 * We don't really want to stat every single mounted directory,
89952e
+	 * as that may include tmpfs, cgroups, procfs or - worst - hung nfs
89952e
+	 * servers.  So first, a simple check: does the "dev" start with "/" ?
89952e
+	 */
89952e
 	while ((mnt = getmntent(f)) != NULL) {
89952e
+		if (mnt->mnt_fsname[0] != '/')
89952e
+			continue;
89952e
 		if (stat64(mnt->mnt_fsname, &mst) < 0)
89952e
 			continue;
89952e
 		if ((mst.st_mode & S_IFMT) != S_IFBLK)