add patch use-generic_writepages-instead-of-__writepage-write_cache_pages
[ext4-patch-queue.git] / fix-offset-overflow-on-32bit-arches-iomap_begin
blob5438daa900a3829f115e3d474fd68c9c4ffeba8d
1 ext4: fix offset overflow on 32-bit archs in ext4_iomap_begin()
3 From: Jiri Slaby <jslaby@suse.cz>
5 ext4_iomap_begin() has a bug where offset returned in the iomap
6 structure will be truncated to unsigned long size. On 64-bit
7 architectures this is fine but on 32-bit architectures obviously not.
8 Not many places actually use the offset stored in the iomap structure
9 but one of visible failures is in SEEK_HOLE / SEEK_DATA implementation.
10 If we create a file like:
12 dd if=/dev/urandom of=file bs=1k seek=8m count=1
14 then
16 lseek64("file", 0x100000000ULL, SEEK_DATA)
18 wrongly returns 0x100000000 on unfixed kernel while it should return
19 0x200000000. Avoid the overflow by proper type cast.
21 Fixes: 545052e9e35a ("ext4: Switch to iomap for SEEK_HOLE / SEEK_DATA")
22 Signed-off-by: Jiri Slaby <jslaby@suse.cz>
23 Signed-off-by: Jan Kara <jack@suse.cz>
24 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
25 Cc: stable@vger.kernel.org # v4.15
26 ---
27  fs/ext4/inode.c | 2 +-
28  1 file changed, 1 insertion(+), 1 deletion(-)
30 diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
31 index c94780075b04..c07d6456b548 100644
32 --- a/fs/ext4/inode.c
33 +++ b/fs/ext4/inode.c
34 @@ -3524,7 +3524,7 @@ static int ext4_iomap_begin(struct inode *inode, loff_t offset, loff_t length,
35                 iomap->flags |= IOMAP_F_DIRTY;
36         iomap->bdev = inode->i_sb->s_bdev;
37         iomap->dax_dev = sbi->s_daxdev;
38 -       iomap->offset = first_block << blkbits;
39 +       iomap->offset = (u64)first_block << blkbits;
40         iomap->length = (u64)map.m_len << blkbits;
42         if (ret == 0) {
43 -- 
44 2.13.6