]> git.apps.os.sepia.ceph.com Git - xfsprogs-dev.git/commit
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)
commit647078745f10a3a41fbb2fe1ce6a8b9e608fdaaa
treef55fc5bad078f0c1b17a3c69a44f15e366bf48b8
parent085fce0ba2e7222e943b1c756c03de84639361b8
xfs_io: set fs_path when opening files on foreign filesystems

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