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

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