add patch add-fallocate-mode-blocking-for-debugging
[ext4-patch-queue.git] / FIBMAP-ioctl-causes-BUG_ON-due-to-handle-EXT_MAX_BLOCKS
blob7df512f9e7efa617ac06dc4f6dce7da9c8f8527d
1 ext4: FIBMAP ioctl causes BUG_ON due to handle EXT_MAX_BLOCKS
3 From: Kazuya Mio <k-mio@sx.jp.nec.com>
5 When we try to get 2^32-1 block of the file which has the extent
6 (ee_block=2^32-2, ee_len=1) with FIBMAP ioctl, it causes BUG_ON
7 in ext4_ext_put_gap_in_cache().
9 To avoid the problem, ext4_map_blocks() needs to check the file logical block
10 number. ext4_ext_put_gap_in_cache() called via ext4_map_blocks() cannot
11 handle 2^32-1 because the maximum file logical block number is 2^32-2.
13 Note that ext4_ind_map_blocks() returns -EIO when the block number is invalid.
14 So ext4_map_blocks() should also return the same errno.
16 Signed-off-by: Kazuya Mio <k-mio@sx.jp.nec.com>
17 Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
18 Cc: stable@vger.kernel.org
19 ---
20 fs/ext4/inode.c |    4 ++++
21  1 file changed, 4 insertions(+)
23 To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
24 the body of a message to majordomo@vger.kernel.org
25 More majordomo info at  http://vger.kernel.org/majordomo-info.html
27 diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
28 index 24bfd7f..b0d5860 100644
29 --- a/fs/ext4/inode.c
30 +++ b/fs/ext4/inode.c
31 @@ -515,6 +515,10 @@ int ext4_map_blocks(handle_t *handle, struct inode *inode,
32                   "logical block %lu\n", inode->i_ino, flags, map->m_len,
33                   (unsigned long) map->m_lblk);
35 +       /* We can handle the block number less than EXT_MAX_BLOCKS */
36 +       if (unlikely(map->m_lblk >= EXT_MAX_BLOCKS))
37 +               return -EIO;
39         /* Lookup extent status tree firstly */
40         if (ext4_es_lookup_extent(inode, map->m_lblk, &es)) {
41                 ext4_es_lru_add(inode);