f2fs: fix to use per-inode maxbytes in f2fs_fiemap

F2FS inode may have different max size,
so change to use per-inode maxbytes.

Signed-off-by: Chengguang Xu <cgxu519@mykernel.net>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
This commit is contained in:
Chengguang Xu 2021-03-09 13:21:18 +08:00 committed by Jaegeuk Kim
parent e1175f0229
commit 0bb2045ce5
1 changed files with 10 additions and 0 deletions

View File

@ -1837,6 +1837,7 @@ int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
int ret = 0; int ret = 0;
bool compr_cluster = false; bool compr_cluster = false;
unsigned int cluster_size = F2FS_I(inode)->i_cluster_size; unsigned int cluster_size = F2FS_I(inode)->i_cluster_size;
loff_t maxbytes;
if (fieinfo->fi_flags & FIEMAP_FLAG_CACHE) { if (fieinfo->fi_flags & FIEMAP_FLAG_CACHE) {
ret = f2fs_precache_extents(inode); ret = f2fs_precache_extents(inode);
@ -1850,6 +1851,15 @@ int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
inode_lock(inode); inode_lock(inode);
maxbytes = max_file_blocks(inode) << F2FS_BLKSIZE_BITS;
if (start > maxbytes) {
ret = -EFBIG;
goto out;
}
if (len > maxbytes || (maxbytes - len) < start)
len = maxbytes - start;
if (fieinfo->fi_flags & FIEMAP_FLAG_XATTR) { if (fieinfo->fi_flags & FIEMAP_FLAG_XATTR) {
ret = f2fs_xattr_fiemap(inode, fieinfo); ret = f2fs_xattr_fiemap(inode, fieinfo);
goto out; goto out;