xfsprogs: ensure growfs rejects non-existent mount point
PATCH 1/1 xfsprogs: ensure growfs rejects non-existent mount point
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.
--- growfs/xfs_growfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
growfs/xfs_growfs.c +1 -1
@@ -203,7 +203,7 @@ main(int argc, char **argv)fs_table_initialise (0 ,NULL ,0 ,NULL ); fs =fs_table_lookup (argv[optind],FS_MOUNT_POINT ); -if (!fs) { +if (!fs || (strcmp (argv[optind], fs->fs_dir) !=0 )) {fprintf (stderr,_ ("%s: %s is not a mounted XFS filesystem\n" ), progname, argv[optind]);return 1 ;
Signature · 1 line
2.9.3
Quoted 18 lines · Bill O'Donnell
xfs_growfsmanpage clearly states that the filesystem must be mounted to be grown. Current behavior allowsxfs_growfsto 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.Signed-off-by Bill O'Donnell <[email protected]>--- growfs/xfs_growfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)growfs/xfs_growfs.c +0
-0
growfs/xfs_growfs.c main(int argc, char **argv) · line 206
Quoted 5 lines
growfs/xfs_growfs.c +1
-1@@ -203,7 +203,7 @@ main(int argc, char **argv)fs_table_initialise (0 ,NULL ,0 ,NULL ); fs =fs_table_lookup (argv[optind],FS_MOUNT_POINT ); -if (!fs) { +if (!fs || (strcmp (argv[optind], fs->fs_dir) !=0 )) {
The parentheses around the strcmp comparison aren't necessary.
There's a find_mountpoint() function in xfs_fsr that wants to do something similar to this. I wonder if it'd make sense to change it too? (Separate patch.)
--D
Quoted 10 lines
growfs/xfs_growfs.c +0
-0fprintf (stderr,_ ("%s: %s is not a mounted XFS filesystem\n" ), progname, argv[optind]);return 1 ;Signature · 6 lines
2.9.3 -- To unsubscribe from this list: send the line "unsubscribe linux-xfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 19 lines · Bill O'Donnell
xfs_growfsmanpage clearly states that the filesystem must be mounted to be grown. Current behavior allowsxfs_growfsto 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.Signed-off-by Bill O'Donnell <[email protected]>--- growfs/xfs_growfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)growfs/xfs_growfs.c +0
-0
growfs/xfs_growfs.c main(int argc, char **argv) · line 209
Quoted 8 lines
growfs/xfs_growfs.c +1
-1@@ -203,7 +203,7 @@ main(int argc, char **argv)fs_table_initialise (0 ,NULL ,0 ,NULL ); fs =fs_table_lookup (argv[optind],FS_MOUNT_POINT ); -if (!fs) { +if (!fs || (strcmp (argv[optind], fs->fs_dir) !=0 )) {fprintf (stderr,_ ("%s: %s is not a mounted XFS filesystem\n" ), progname, argv[optind]);return 1 ;
Looks like the right start, but I see a few problems with this.
First, fs_dir contains a full path, so if we point at a relative path, this will fail now (with a little extra error annotation):
# growfs/xfs_growfs -n mnt xfs_growfs: mnt is not a mounted XFS filesystem (failed compare to /mnt/test/mnt)
but will work if given a full path:
# growfs/xfs_growfs -n `pwd`/mnt meta-data=/dev/loop0 isize=512 agcount=4, agsize=65536 blks ...
The path stuff in libxcmd tries to boil everything down to a realpath() - see:
050a7f1 xfsprogs: handle symlinks etc in fs_table_initialise_mounts() and
ed350fc libxcmd: make all comparisons using realpath'd paths
so if you want to compare paths to what's in the fstable, you'll need to realpath() them first to get the the same canonical pathname that it has stored.
Also, if we have the same filesystem mounted
in multiple ways, say: via loop, via a secondary mount, and via a bind mount (and maybe via a symlinked mount point?):
/mnt/test/fsfile on /mnt/test/mnt type xfs (rw,loop=/dev/loop0) /dev/loop0 on /mnt/test/mnt2 type xfs (rw) /mnt/test/mnt2 on /mnt/test/mnt3 type none (rw,bind)
it will fail on all but the first one it finds in the internal table:
# growfs/xfs_growfs -n `pwd`/mnt2 xfs_growfs: /mnt/test/mnt2 is not a mounted XFS filesystem (failed compare to /mnt/test/mnt) # growfs/xfs_growfs -n `pwd`/mnt3 xfs_growfs: /mnt/test/mnt3 is not a mounted XFS filesystem (failed compare to /mnt/test/mnt)
because it the lookup stats the path, and picks the /first/ fstable entry which has a matching device, ignoring the mountpoint found in the fstable entry.
So I think all that indicates an xfstest is needed to validate the change, and a slightly different approach to finding a match.
Thanks,
-Eric
Quoted 67 lines · Eric Sandeen
Quoted 19 lines · Bill O'Donnell
xfs_growfsmanpage clearly states that the filesystem must be mounted to be grown. Current behavior allowsxfs_growfsto 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.Signed-off-by Bill O'Donnell <[email protected]>--- growfs/xfs_growfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)growfs/xfs_growfs.c +0
-0growfs/xfs_growfs.c main(int argc, char **argv) · line 209
Quoted 8 lines
growfs/xfs_growfs.c +1
-1@@ -203,7 +203,7 @@ main(int argc, char **argv)fs_table_initialise (0 ,NULL ,0 ,NULL ); fs =fs_table_lookup (argv[optind],FS_MOUNT_POINT ); -if (!fs) { +if (!fs || (strcmp (argv[optind], fs->fs_dir) !=0 )) {fprintf (stderr,_ ("%s: %s is not a mounted XFS filesystem\n" ), progname, argv[optind]);return 1 ;Looks like the right start, but I see a few problems with this.
First,
fs_dircontains a full path, so if we point at a relative path, this will fail now (with a little extra error annotation):# growfs/xfs_growfs -n mnt xfs_growfs: mnt is not a mounted XFS filesystem (failed compare to /mnt/test/mnt)but will work if given a full path:
# growfs/xfs_growfs -n `pwd`/mnt meta-data=/dev/loop0 isize=512 agcount=4, agsize=65536 blks ...The path stuff in libxcmd tries to boil everything down to a
realpath()- see:050a7f1 xfsprogs: handle symlinks etc in
fs_table_initialise_mounts()and
ed350fc libxcmd: make all comparisons using realpath'd pathsso if you want to compare paths to what's in the fstable, you'll need to
realpath()them first to get the the same canonical pathname that it has stored.Also, if we have the same filesystem mounted
in multiple ways, say: via loop, via a secondary mount, and via a bind mount (and maybe via a symlinked mount point?):
/mnt/test/fsfileon/mnt/test/mnttype xfs (rw,loop=/dev/loop0)/dev/loop0on/mnt/test/mnt2type xfs (rw)/mnt/test/mnt2on/mnt/test/mnt3type none (rw,bind)it will fail on all but the first one it finds in the internal table:
# growfs/xfs_growfs -n `pwd`/mnt2 xfs_growfs: /mnt/test/mnt2 is not a mounted XFS filesystem (failed compare to /mnt/test/mnt) # growfs/xfs_growfs -n `pwd`/mnt3 xfs_growfs: /mnt/test/mnt3 is not a mounted XFS filesystem (failed compare to /mnt/test/mnt)
Quoted 5 lines
because it the lookup stats the path, and picks the /first/ fstable entry which has a matching device, ignoring the mountpoint found in the fstable entry.
So I think all that indicates an xfstest is needed to validate the change, and a slightly different approach to finding a match.
I submitted a v2. I'll also work on an xfstest.
Thanks-
Bill
Quoted 7 lines
Thanks,
-Eric
--
To unsubscribe from this list: send the line "unsubscribe linux-xfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v2 1/1 xfsprogs: ensure growfs rejects non-existent mount point
In reply to Bill O'Donnellxfs_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.
---
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(-)
growfs/xfs_growfs.c +9 -1
@@ -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]);
include/path.h +1 -0
@@ -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 */
libxcmd/paths.c +21 -0
@@ -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,
Signature · 1 line
2.9.3
Quoted 11 lines · Bill O'Donnell
xfs_growfsmanpage clearly states that the filesystem must be mounted to be grown. Current behavior allowsxfs_growfsto 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.
Quoted 7 lines
Signed-off-by Bill O'Donnell <[email protected]>---
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.
I still need to review this one carefully, but have you made any progress towards an xfstest for this behavior?
Thanks,
-Eric
Quoted 15 lines · Eric Sandeen
Quoted 14 lines · Bill O'Donnell
xfs_growfsmanpage clearly states that the filesystem must be mounted to be grown. Current behavior allowsxfs_growfsto 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 <[email protected]>---
Quoted 7 lines
Quoted 4 lines
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.
I still need to review this one carefully, but have you made any progress towards an xfstest for this behavior?
xfstest is still a work in progress. Hopefully will have one by end of this week.
Thanks-
Bill
Quoted 7 lines
Thanks,
-Eric
--
To unsubscribe from this list: send the line "unsubscribe linux-xfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 37 lines · Bill O'Donnell
xfs_growfsmanpage clearly states that the filesystem must be mounted to be grown. Current behavior allowsxfs_growfsto 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 <[email protected]>---
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(-)growfs/xfs_growfs.c +1
-0@@ -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 ,"" );
growfs/xfs_growfs.c main(int argc, char **argv) · line 210
Quoted 9 lines
growfs/xfs_growfs.c +5
-1@@ -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 ;
Probably not the clearest error message; if realpath failed, we really don't know much at all about the path yet.
(_("Path resolution failed for %s: %s\n"), path, strerror(errno)) or something like that would be more informative if it fails..
Otherwise, I think this looks ok. I was a little unsure about keeping the old fs_table_lookup behavior around, but given that xfs_growfs is the only utility (I think) which /explicitly/ says it requires a mount point (and can have irreversible consequences if it's pointed at the wrong thing) that's probably ok.
One other suggestion would be to document the difference between the 2 lookup functions a bit more, making it more clear that one will find the fs table entry for the fs hosting the file at *path, and the other will find it only if it /is/ the mount point.
I had a concern that while you're passing a realpath'd path to the new function, the mount points in the table aren't realpath'd. But I /think/ that still works; if I mount onto a symlinked dir, it's the realpath (symlink target) that ends up in /proc/mounts.
Still, it might be safest to realpath the path found in the fs table as well prior to the comparison - if it's iterating over /etc/mtab instead of /proc/mounts on an older machine, I'm not sure what the paths end up looking like in that file.
-Eric
Quoted 51 lines
growfs/xfs_growfs.c +3
-0+ } + + fs =fs_table_lookup_mount (rpath);if (!fs) {fprintf (stderr,_ ("%s: %s is not a mounted XFS filesystem\n" ), progname, argv[optind]);include/path.h +1
-0@@ -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 */libxcmd/paths.c +21
-0@@ -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,
Quoted 12 lines · Eric Sandeen
Quoted 9 lines · Bill O'Donnell
libxcmd/paths.c +9
-0+/* +* 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;
Quoted 8 lines
libxcmd/paths.c fs_table_lookup( · line 105
Quoted 8 lines
libxcmd/paths.c +8
-0+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];
Oh, and I think we need to test the flags on the entry to be sure that it is a FS_MOUNT_POINT as well, and not a project path.
-Eric
Quoted 13 lines
libxcmd/paths.c fs_table_lookup( · line 112
Quoted 8 lines
libxcmd/paths.c +4
-0+ } +return NULL ; +} + static int fs_table_insert( char *dir,--
To unsubscribe from this list: send the line "unsubscribe linux-xfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v3 1/1 xfsprogs: ensure growfs rejects non-existent mount point
In reply to Bill O'Donnellxfs_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.
---
v3: improve error message for realpath failure. Add comments to better document the differences between fs_table_lookup() and fs_table_lookup_mount(). Use realpath() in fs_table_lookup_mount() prior to directory comparison.
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 | 31 +++++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+), 1 deletion(-)
growfs/xfs_growfs.c +9 -1
@@ -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,_ ("Path resolution failed for %s: %s\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]);
include/path.h +1 -0
@@ -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 */
libxcmd/paths.c +31 -0
@@ -65,6 +65,9 @@ fs_device_number(* Find the FS table entry for the given path. The "flags" argument * is a mask containing FS_MOUNT_POINT or FS_PROJECT_PATH (or both) * to indicate the type of table entry sought. +* fs_table_lookup() finds the fs table entry for the filesystem hosting +* the file represented in the "dir" argument. To compare against actual +* mount point entries, use fs_table_lookup_mount() instead. */ struct fs_path * fs_table_lookup(
@@ -86,6 +89,34 @@ fs_table_lookup(return NULL ; } +/* +* Find the FS table entry describing an actual mount for the given path. +* Unlike fs_table_lookup(), fs_table_lookup_mount() compares the "dir" +* argument to actual mount point entries in the table. Accordingly, it +* will find matches only if the "dir" argument is indeed mounted. +*/ +struct fs_path * +fs_table_lookup_mount ( +const char *dir) +{ +uint i; +dev_t dev =0 ; +char rpath[PATH_MAX ]; + +if (fs_device_number (dir, &dev)) +return NULL ; + +for (i =0 ; i < fs_count; i++) { +if (fs_table[i].fs_flags !=FS_MOUNT_POINT ) +continue ; +if (!realpath (fs_table[i].fs_dir, rpath)) +continue ; +if (strcmp (rpath, dir) ==0 ) +return &fs_table[i]; + } +return NULL ; +} + static int fs_table_insert( char *dir,
Signature · 1 line
2.9.3
On 4/24/17 9:29 AM, Bill O'Donnell wrote:
I probably should have mentioned this earlier but the subject and commit log are a little weird; we want this stuff to be as accurate as possible for those who come after us in 2050 when XFS is still in use. :P
"xfsprogs: ensure growfs rejects non-existent mount point"
What is a "non-existent mount point?" If it doesn't exist, how can it be a mount point? :) Maybe:
xfs_growfs: ensure target path is an active xfs mountpoint
Quoted 2 lines
xfs_growfsmanpage clearly states that the filesystem must be mounted to be grown.
..that the target path must be an active xfs mountpoint.
(the filesystem /does/ have to be mounted to be grown, it's just that growfs found it via paths which are not the mountpoint, which is not what the manpage says it requires)
Quoted 3 lines
Current behavior allows
xfs_growfs
to proceed if the filesystem /containing/ the path of the desired target is mounted.
... to proceed if the target path resides anywhere on a mounted xfs filesystem. This could lead to unexpected results.
(of course it was mounted, the problem was that it was not the mountpoint itself)
Quoted 4 lines
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.
Unless the target path is an active xfs mountpoint, reject it.
Quoted 2 lines
In order to cover bind-mounts, create a new lookup function based on the mountpoints instead of just the device name.
(we needed this with or without bind mounts so that's not really inaccurate...)
Create a new fs table lookup function which matches only active xfs mount points, not any file residing within those mountpoints.
Quoted 31 lines
Signed-off-by Bill O'Donnell <[email protected]>---
v3: improve error message for realpath failure. Add comments to better document the differences between
fs_table_lookup()andfs_table_lookup_mount(). Userealpath()infs_table_lookup_mount()prior to directory comparison.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 | 31 +++++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+), 1 deletion(-)growfs/xfs_growfs.c +1
-0@@ -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 ,"" );
growfs/xfs_growfs.c main(int argc, char **argv) · line 211
Quoted 10 lines
growfs/xfs_growfs.c +6
-1@@ -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,_ ("Path resolution failed for %s: %s\n" ), + progname, argv[optind]); +return 1 ; + }
so we get:
# growfs/xfs_growfs -n foobar Path resolution failed for xfs_growfs: foobar
That's a little odd...
What I had suggested was to use strerror to say /why/ it failed:
+ if (!realpath(argv[optind], rpath)) {
+ fprintf(stderr, _("%s: path resolution failed for %s: %s\n"),
+ progname, argv[optind], strerror(errno));
+ return 1;
+ }
so:
# xfs_growfs -n foobar xfs_growfs: path resolution failed for foobar: No such file or directory
Sorry for being the BMFH.
-Eric
Quoted 67 lines
growfs/xfs_growfs.c +2
-0+ + fs =fs_table_lookup_mount (rpath);if (!fs) {fprintf (stderr,_ ("%s: %s is not a mounted XFS filesystem\n" ), progname, argv[optind]);include/path.h +1
-0@@ -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 */libxcmd/paths.c +31
-0@@ -65,6 +65,9 @@ fs_device_number(* Find the FS table entry for the given path. The "flags" argument * is a mask containing FS_MOUNT_POINT or FS_PROJECT_PATH (or both) * to indicate the type of table entry sought. +* fs_table_lookup() finds the fs table entry for the filesystem hosting +* the file represented in the "dir" argument. To compare against actual +* mount point entries, use fs_table_lookup_mount() instead. */ struct fs_path * fs_table_lookup(@@ -86,6 +89,34 @@ fs_table_lookup(return NULL ; } +/* +* Find the FS table entry describing an actual mount for the given path. +* Unlike fs_table_lookup(), fs_table_lookup_mount() compares the "dir" +* argument to actual mount point entries in the table. Accordingly, it +* will find matches only if the "dir" argument is indeed mounted. +*/ +struct fs_path * +fs_table_lookup_mount ( +const char *dir) +{ +uint i; +dev_t dev =0 ; +char rpath[PATH_MAX ]; + +if (fs_device_number (dir, &dev)) +return NULL ; + +for (i =0 ; i < fs_count; i++) { +if (fs_table[i].fs_flags !=FS_MOUNT_POINT ) +continue ; +if (!realpath (fs_table[i].fs_dir, rpath)) +continue ; +if (strcmp (rpath, dir) ==0 ) +return &fs_table[i]; + } +return NULL ; +} + static int fs_table_insert( char *dir,
PATCH v4 1/1 xfs_growfs: ensure target path is an active xfs mountpoint
In reply to Bill O'Donnellxfs_growfs manpage clearly states that the target path must be an active xfs mountpoint.
Current behavior allows xfs_growfs to proceed if the target path resides anywhere on a mounted xfs filesystem. This could lead to unexpected results. Unless the target path is an active xfs mountpoint, reject it. Create a new fs table lookup function which matches only active xfs mount points, not any file residing within those mountpoints.
---
v4: improve commit message and subject line. Further improvement of error message for realpath() prior to table lookup in xfs_growfs.
v3: improve error message for realpath failure. Add comments to better document the differences between fs_table_lookup() and fs_table_lookup_mount(). Use realpath() in fs_table_lookup_mount() prior to directory comparison.
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 | 31 +++++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+), 1 deletion(-)
growfs/xfs_growfs.c +9 -1
@@ -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: path resolution failed for %s: %s\n" ), + progname, argv[optind],strerror (errno)); +return 1 ; + } + + fs =fs_table_lookup_mount (rpath);if (!fs) {fprintf (stderr,_ ("%s: %s is not a mounted XFS filesystem\n" ), progname, argv[optind]);
include/path.h +1 -0
@@ -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 */
libxcmd/paths.c +31 -0
@@ -65,6 +65,9 @@ fs_device_number(* Find the FS table entry for the given path. The "flags" argument * is a mask containing FS_MOUNT_POINT or FS_PROJECT_PATH (or both) * to indicate the type of table entry sought. +* fs_table_lookup() finds the fs table entry for the filesystem hosting +* the file represented in the "dir" argument. To compare against actual +* mount point entries, use fs_table_lookup_mount() instead. */ struct fs_path * fs_table_lookup(
@@ -86,6 +89,34 @@ fs_table_lookup(return NULL ; } +/* +* Find the FS table entry describing an actual mount for the given path. +* Unlike fs_table_lookup(), fs_table_lookup_mount() compares the "dir" +* argument to actual mount point entries in the table. Accordingly, it +* will find matches only if the "dir" argument is indeed mounted. +*/ +struct fs_path * +fs_table_lookup_mount ( +const char *dir) +{ +uint i; +dev_t dev =0 ; +char rpath[PATH_MAX ]; + +if (fs_device_number (dir, &dev)) +return NULL ; + +for (i =0 ; i < fs_count; i++) { +if (fs_table[i].fs_flags !=FS_MOUNT_POINT ) +continue ; +if (!realpath (fs_table[i].fs_dir, rpath)) +continue ; +if (strcmp (rpath, dir) ==0 ) +return &fs_table[i]; + } +return NULL ; +} + static int fs_table_insert( char *dir,
Signature · 1 line
2.9.3
Re: [PATCH v4] xfs_growfs: ensure target path is an active xfs mountpoint
Quoted 11 lines · Bill O'Donnell
xfs_growfsmanpage clearly states that the target path must be an active xfs mountpoint.Current behavior allows
xfs_growfsto proceed if the target path resides anywhere on a mounted xfs filesystem. This could lead to unexpected results. Unless the target path is an active xfs mountpoint, reject it. Create a new fs table lookup function which matches only active xfs mount points, not any file residing within those mountpoints.Signed-off-by Bill O'Donnell <[email protected]>
Looks good, thanks. And thanks for putting up with my pedantry.
I will probably queue this for the 4.12 release since it's fairly user-visible and 4.11 is close to release (he says, hopefully).
Quoted 110 lines
---
v4: improve commit message and subject line. Further improvement of error message for
realpath()prior to table lookup inxfs_growfs.v3: improve error message for realpath failure. Add comments to better document the differences between
fs_table_lookup()andfs_table_lookup_mount(). Userealpath()infs_table_lookup_mount()prior to directory comparison.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 | 31 +++++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+), 1 deletion(-)growfs/xfs_growfs.c +9
-1@@ -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: path resolution failed for %s: %s\n" ), + progname, argv[optind],strerror (errno)); +return 1 ; + } + + fs =fs_table_lookup_mount (rpath);if (!fs) {fprintf (stderr,_ ("%s: %s is not a mounted XFS filesystem\n" ), progname, argv[optind]);include/path.h +1
-0@@ -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 */libxcmd/paths.c +31
-0@@ -65,6 +65,9 @@ fs_device_number(* Find the FS table entry for the given path. The "flags" argument * is a mask containing FS_MOUNT_POINT or FS_PROJECT_PATH (or both) * to indicate the type of table entry sought. +* fs_table_lookup() finds the fs table entry for the filesystem hosting +* the file represented in the "dir" argument. To compare against actual +* mount point entries, use fs_table_lookup_mount() instead. */ struct fs_path * fs_table_lookup(@@ -86,6 +89,34 @@ fs_table_lookup(return NULL ; } +/* +* Find the FS table entry describing an actual mount for the given path. +* Unlike fs_table_lookup(), fs_table_lookup_mount() compares the "dir" +* argument to actual mount point entries in the table. Accordingly, it +* will find matches only if the "dir" argument is indeed mounted. +*/ +struct fs_path * +fs_table_lookup_mount ( +const char *dir) +{ +uint i; +dev_t dev =0 ; +char rpath[PATH_MAX ]; + +if (fs_device_number (dir, &dev)) +return NULL ; + +for (i =0 ; i < fs_count; i++) { +if (fs_table[i].fs_flags !=FS_MOUNT_POINT ) +continue ; +if (!realpath (fs_table[i].fs_dir, rpath)) +continue ; +if (strcmp (rpath, dir) ==0 ) +return &fs_table[i]; + } +return NULL ; +} + static int fs_table_insert( char *dir,
Re: [PATCH v4] xfs_growfs: ensure target path is an active xfs mountpoint
Quoted 11 lines · Eric Sandeen
Quoted 10 lines · Bill O'Donnell
xfs_growfsmanpage clearly states that the target path must be an active xfs mountpoint.Current behavior allows
xfs_growfsto proceed if the target path resides anywhere on a mounted xfs filesystem. This could lead to unexpected results. Unless the target path is an active xfs mountpoint, reject it. Create a new fs table lookup function which matches only active xfs mount points, not any file residing within those mountpoints.
Quoted 6 lines
Quoted 1 line
Signed-off-by Bill O'Donnell <[email protected]>Looks good, thanks. And thanks for putting up with my pedantry.
I will probably queue this for the 4.12 release since it's fairly user-visible and 4.11 is close to release (he says, hopefully).
Ofc now that Eryu has accepted the xfstests for this, we'll fail xfs/289 for a whole release cycle... :)
(Not that I particularly mind, just leaving a breadcrumb in case people start wondering why we have a test for something that isn't upstream.)
((Which you know will be me in about 3 weeks when I forget that any of this ever happened. :P))
--D
Quoted 117 lines
Reviewed-by Eric Sandeen <[email protected]>Quoted 100 lines
---
v4: improve commit message and subject line. Further improvement of error message for
realpath()prior to table lookup inxfs_growfs.v3: improve error message for realpath failure. Add comments to better document the differences between
fs_table_lookup()andfs_table_lookup_mount(). Userealpath()infs_table_lookup_mount()prior to directory comparison.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 | 31 +++++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+), 1 deletion(-)growfs/xfs_growfs.c +9
-1@@ -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: path resolution failed for %s: %s\n" ), + progname, argv[optind],strerror (errno)); +return 1 ; + } + + fs =fs_table_lookup_mount (rpath);if (!fs) {fprintf (stderr,_ ("%s: %s is not a mounted XFS filesystem\n" ), progname, argv[optind]);include/path.h +1
-0@@ -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 */libxcmd/paths.c +24
-0@@ -65,6 +65,9 @@ fs_device_number(* Find the FS table entry for the given path. The "flags" argument * is a mask containing FS_MOUNT_POINT or FS_PROJECT_PATH (or both) * to indicate the type of table entry sought. +* fs_table_lookup() finds the fs table entry for the filesystem hosting +* the file represented in the "dir" argument. To compare against actual +* mount point entries, use fs_table_lookup_mount() instead. */ struct fs_path * fs_table_lookup(@@ -86,6 +89,34 @@ fs_table_lookup(return NULL ; } +/* +* Find the FS table entry describing an actual mount for the given path. +* Unlike fs_table_lookup(), fs_table_lookup_mount() compares the "dir" +* argument to actual mount point entries in the table. Accordingly, it +* will find matches only if the "dir" argument is indeed mounted. +*/ +struct fs_path * +fs_table_lookup_mount ( +const char *dir) +{ +uint i; +dev_t dev =0 ; +char rpath[PATH_MAX ]; + +if (fs_device_number (dir, &dev)) +return NULL ; + +for (i =0 ; i < fs_count; i++) { +if (fs_table[i].fs_flags !=FS_MOUNT_POINT ) +continue ; +if (!realpath (fs_table[i].fs_dir, rpath))libxcmd/paths.c fs_table_lookup( · line 122
Quoted 10 lines
libxcmd/paths.c +7
-0+continue ; +if (strcmp (rpath, dir) ==0 ) +return &fs_table[i]; + } +return NULL ; +} + static int fs_table_insert( char *dir,--
To unsubscribe from this list: send the line "unsubscribe linux-xfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html