summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWei Fang <fangwei1@huawei.com>2017-01-22 12:21:02 +0800
committerJaegeuk Kim <jaegeuk@kernel.org>2017-02-22 20:24:49 -0800
commitb86e33075ed1909d8002745b56ecf73b833db143 (patch)
tree75079cb01fdebff99bed6bad25eb16757bdbb2ea
parentdc91de78e5e1d44238b5dd2b57d2e8e67cbc00a1 (diff)
downloadop-kernel-dev-b86e33075ed1909d8002745b56ecf73b833db143.zip
op-kernel-dev-b86e33075ed1909d8002745b56ecf73b833db143.tar.gz
f2fs: fix a dead loop in f2fs_fiemap()
A dead loop can be triggered in f2fs_fiemap() using the test case as below: ... fd = open(); fallocate(fd, 0, 0, 4294967296); ioctl(fd, FS_IOC_FIEMAP, fiemap_buf); ... It's caused by an overflow in __get_data_block(): ... bh->b_size = map.m_len << inode->i_blkbits; ... map.m_len is an unsigned int, and bh->b_size is a size_t which is 64 bits on 64 bits archtecture, type conversion from an unsigned int to a size_t will result in an overflow. In the above-mentioned case, bh->b_size will be zero, and f2fs_fiemap() will call get_data_block() at block 0 again an again. Fix this by adding a force conversion before left shift. Signed-off-by: Wei Fang <fangwei1@huawei.com> Acked-by: Chao Yu <yuchao0@huawei.com> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
-rw-r--r--fs/f2fs/data.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
index 2ea8021..3b5f1d1 100644
--- a/fs/f2fs/data.c
+++ b/fs/f2fs/data.c
@@ -964,7 +964,7 @@ static int __get_data_block(struct inode *inode, sector_t iblock,
if (!err) {
map_bh(bh, inode->i_sb, map.m_pblk);
bh->b_state = (bh->b_state & ~F2FS_MAP_FLAGS) | map.m_flags;
- bh->b_size = map.m_len << inode->i_blkbits;
+ bh->b_size = (u64)map.m_len << inode->i_blkbits;
}
return err;
}
OpenPOWER on IntegriCloud