From: Bill O'Donnell <billodo@redhat.com>
To: linux-xfs@vger.kernel.org
Subject: [PATCH v2] xfsprogs: ensure growfs rejects non-existent mount point
Date: Tue, 11 Apr 2017 12:22:35 -0500	[thread overview]
Message-ID: <20170411172235.9361-1-billodo@redhat.com> (raw)
In-Reply-To: <20170407175809.8540-1-billodo@redhat.com>
xfs_growfs manpage clearly states that the filesystem must
be mounted to be grown. Current behavior allows xfs_growfs
to proceed if the filesystem /containing/ the path
of the desired target is mounted. This is not the specified
behavior. Instead, also check the targeted fs argument against
the entry found in the fstable lookup. Unless the targeted
fs is actually mounted, reject the command.
In order to cover bind-mounts, create a new lookup function
based on the mountpoints instead of just the device name.
Signed-off-by: Bill O'Donnell <billodo@redhat.com>
---
v2: in order to properly handle relative pathnames, symlinks,
and bind-mounts, use realpath to establish canonical path name.
This also requires the introduction of a lookup function based
on the target mountpoint.
 growfs/xfs_growfs.c | 10 +++++++++-
 include/path.h      |  1 +
 libxcmd/paths.c     | 21 +++++++++++++++++++++
 3 files changed, 31 insertions(+), 1 deletion(-)
diff --git a/growfs/xfs_growfs.c b/growfs/xfs_growfs.c
index a294e14..a61e2f1 100644
--- a/growfs/xfs_growfs.c
+++ b/growfs/xfs_growfs.c
@@ -133,6 +133,7 @@ main(int argc, char **argv)
 	int			spinodes;
 	int			rmapbt_enabled;
 	int			reflink_enabled;
+	char			rpath[PATH_MAX];
 
 	progname = basename(argv[0]);
 	setlocale(LC_ALL, "");
@@ -202,7 +203,14 @@ main(int argc, char **argv)
 		aflag = 1;
 
 	fs_table_initialise(0, NULL, 0, NULL);
-	fs = fs_table_lookup(argv[optind], FS_MOUNT_POINT);
+
+	if (!realpath(argv[optind], rpath)) {
+		fprintf(stderr, _("%s: %s is not a mounted XFS filesystem\n"),
+			progname, argv[optind]);
+		return 1;
+	}
+
+	fs = fs_table_lookup_mount(rpath);
 	if (!fs) {
 		fprintf(stderr, _("%s: %s is not a mounted XFS filesystem\n"),
 			progname, argv[optind]);
diff --git a/include/path.h b/include/path.h
index d077bac..1d3a902 100644
--- a/include/path.h
+++ b/include/path.h
@@ -56,6 +56,7 @@ extern void fs_table_insert_project_path(char *__dir, uint __projid);
 
 
 extern fs_path_t *fs_table_lookup(const char *__dir, uint __flags);
+extern fs_path_t *fs_table_lookup_mount(const char *__dir);
 
 typedef struct fs_cursor {
 	uint		count;		/* total count of mount entries	*/
diff --git a/libxcmd/paths.c b/libxcmd/paths.c
index 816acc2..10927c6 100644
--- a/libxcmd/paths.c
+++ b/libxcmd/paths.c
@@ -86,6 +86,27 @@ fs_table_lookup(
 	return NULL;
 }
 
+/*
+ * Find the FS table entry for the given path. Compare
+ * the path to mountpoint entries in the table.
+ */
+struct fs_path *
+fs_table_lookup_mount(
+	const char *dir)
+{
+	uint		i;
+	dev_t		dev = 0;
+
+	if (fs_device_number(dir, &dev))
+		return NULL;
+
+	for (i = 0; i < fs_count; i++) {
+		if (strcmp(fs_table[i].fs_dir, dir) == 0)
+			return &fs_table[i];
+	}
+	return NULL;
+}
+
 static int
 fs_table_insert(
 	char		*dir,
-- 
2.9.3
next prev parent reply	other threads:[~2017-04-11 17:22 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-07 17:58 [PATCH] xfsprogs: ensure growfs rejects non-existent mount point Bill O'Donnell
2017-04-07 18:33 ` Darrick J. Wong
2017-04-07 18:51 ` Eric Sandeen
2017-04-11 23:20   ` Bill O'Donnell
2017-04-11 17:22 ` Bill O'Donnell [this message]
2017-04-19 22:05   ` [PATCH v2] " Eric Sandeen
2017-04-19 22:08     ` Bill O'Donnell
2017-04-20 22:22   ` Eric Sandeen
2017-04-20 22:43     ` Eric Sandeen
2017-04-24 14:29 ` [PATCH v3] " Bill O'Donnell
2017-04-26 22:23   ` Eric Sandeen
2017-04-27 18:23 ` [PATCH v4] xfs_growfs: ensure target path is an active xfs mountpoint Bill O'Donnell
2017-04-27 19:15   ` Eric Sandeen
2017-05-03 16:08     ` Darrick J. Wong
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox
  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):
  git send-email \
    --in-reply-to=20170411172235.9361-1-billodo@redhat.com \
    --to=billodo@redhat.com \
    --cc=linux-xfs@vger.kernel.org \
    /path/to/YOUR_REPLY
  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
  Be sure your reply has a Subject: header at the top and a blank line
  before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).