Commit cddf8a2c authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Theodore Ts'o
Browse files

fs: move fiemap range validation into the file systems instances



Replace fiemap_check_flags with a fiemap_prep helper that also takes the
inode and mapped range, and performs the sanity check and truncation
previously done in fiemap_check_range.  This way the validation is inside
the file system itself and thus properly works for the stacked overlayfs
case as well.

Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarAmir Goldstein <amir73il@gmail.com>
Reviewed-by: default avatarDarrick J. Wong <darrick.wong@oracle.com>
Link: https://lore.kernel.org/r/20200523073016.2944131-7-hch@lst.de


Signed-off-by: default avatarTheodore Ts'o <tytso@mit.edu>
parent 27328818
Loading
Loading
Loading
Loading
+7 −5
Original line number Diff line number Diff line
@@ -203,16 +203,18 @@ EINTR once fatal signal received.


Flag checking should be done at the beginning of the ->fiemap callback via the
fiemap_check_flags() helper:
fiemap_prep() helper:

int fiemap_check_flags(struct fiemap_extent_info *fieinfo, u32 fs_flags);
int fiemap_prep(struct inode *inode, struct fiemap_extent_info *fieinfo,
		u64 start, u64 *len, u32 supported_flags);

The struct fieinfo should be passed in as received from ioctl_fiemap(). The
set of fiemap flags which the fs understands should be passed via fs_flags. If
fiemap_check_flags finds invalid user flags, it will place the bad values in
fiemap_prep finds invalid user flags, it will place the bad values in
fieinfo->fi_flags and return -EBADR. If the file system gets -EBADR, from
fiemap_check_flags(), it should immediately exit, returning that error back to
ioctl_fiemap().
fiemap_prep(), it should immediately exit, returning that error back to
ioctl_fiemap().  Additionally the range is validate against the supported
maximum file size.


For each extent in the request range, the file system should call
+1 −1
Original line number Diff line number Diff line
@@ -8250,7 +8250,7 @@ static int btrfs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
{
	int	ret;

	ret = fiemap_check_flags(fieinfo, BTRFS_FIEMAP_FLAGS);
	ret = fiemap_prep(inode, fieinfo, start, &len, BTRFS_FIEMAP_FLAGS);
	if (ret)
		return ret;

+4 −2
Original line number Diff line number Diff line
@@ -3408,8 +3408,10 @@ static int smb3_fiemap(struct cifs_tcon *tcon,
	int i, num, rc, flags, last_blob;
	u64 next;

	if (fiemap_check_flags(fei, FIEMAP_FLAG_SYNC))
		return -EBADR;
	rc = fiemap_prep(d_inode(cfile->dentry), fei, start, &len,
			FIEMAP_FLAG_SYNC);
	if (rc)
		return rc;

	xid = get_xid();
 again:
+3 −2
Original line number Diff line number Diff line
@@ -4938,8 +4938,9 @@ int ext4_get_es_cache(struct inode *inode, struct fiemap_extent_info *fieinfo,
		fieinfo->fi_flags &= ~FIEMAP_FLAG_CACHE;
	}

	if (fiemap_check_flags(fieinfo, FIEMAP_FLAG_SYNC))
		return -EBADR;
	error = fiemap_prep(inode, fieinfo, start, &len, FIEMAP_FLAG_SYNC);
	if (error)
		return error;

	error = ext4_fiemap_check_ranges(inode, start, &len);
	if (error)
+2 −1
Original line number Diff line number Diff line
@@ -1825,7 +1825,8 @@ int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
			return ret;
	}

	ret = fiemap_check_flags(fieinfo, FIEMAP_FLAG_SYNC | FIEMAP_FLAG_XATTR);
	ret = fiemap_prep(inode, fieinfo, start, &len,
			FIEMAP_FLAG_SYNC | FIEMAP_FLAG_XATTR);
	if (ret)
		return ret;

Loading