]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs_io: set fs_path when opening files on foreign filesystems
authorDarrick J. Wong <djwong@kernel.org>
Thu, 16 Feb 2023 21:53:04 +0000 (13:53 -0800)
committerCarlos Maiolino <cem@kernel.org>
Thu, 23 Feb 2023 08:54:27 +0000 (09:54 +0100)
Ted noticed that the following command:

$ xfs_io -c 'fsmap -d 0 0' /mnt
xfs_io: xfsctl(XFS_IOC_GETFSMAP) iflags=0x0 ["/mnt"]: Invalid argument

doesn't work on an ext4 filesystem.  The above command is supposed to
issue a GETFSMAP query against the "data" device.  Although the manpage
doesn't claim support for ext4, it turns out that this you get this
trace data:

          xfs_io-4144  [002]   210.965642: ext4_getfsmap_low_key: dev
7:0 keydev 163:2567 block 0 len 0 owner 0 flags 0x0
          xfs_io-4144  [002]   210.965645: ext4_getfsmap_high_key: dev
7:0 keydev 32:5277:0 block 0 len 0 owner -1 flags 0xffffffff

Notice the random garbage in the keydev field -- this happens because
openfile (in xfs_io) doesn't initialize *fs_path if the caller doesn't
supply a geometry structure or the opened file isn't on an XFS
filesystem.  IOWs, we feed random heap garbage to the kernel, and the
kernel rejects the call unnecessarily.

Fix this to set the fspath information even for foreign filesystems.

Reported-by: tytso@mit.edu
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Carlos Maiolino <cmaiolino@redhat.com>
Signed-off-by: Carlos Maiolino <cem@kernel.org>
io/open.c

index d8072664c1657f1c9d4640864e98ff6b161acf27..15850b5557bc5b277fd04f29e49e01e4c5c2572b 100644 (file)
--- a/io/open.c
+++ b/io/open.c
@@ -116,7 +116,7 @@ openfile(
        }
 
        if (!geom || !platform_test_xfs_fd(fd))
-               return fd;
+               goto set_fspath;
 
        if (flags & IO_PATH) {
                /* Can't call ioctl() on O_PATH fds */
@@ -150,6 +150,7 @@ openfile(
                }
        }
 
+set_fspath:
        if (fs_path) {
                fsp = fs_table_lookup(path, FS_MOUNT_POINT);
                if (!fsp)