]>
Commit | Line | Data |
---|---|---|
0f23eb5b GKH |
1 | From fe23cb65c2c394ea306f3714a17d46ab2e6a0af1 Mon Sep 17 00:00:00 2001 |
2 | From: Jiri Slaby <jslaby@suse.cz> | |
3 | Date: Thu, 22 Mar 2018 11:50:26 -0400 | |
4 | Subject: ext4: fix offset overflow on 32-bit archs in ext4_iomap_begin() | |
5 | ||
6 | From: Jiri Slaby <jslaby@suse.cz> | |
7 | ||
8 | commit fe23cb65c2c394ea306f3714a17d46ab2e6a0af1 upstream. | |
9 | ||
10 | ext4_iomap_begin() has a bug where offset returned in the iomap | |
11 | structure will be truncated to unsigned long size. On 64-bit | |
12 | architectures this is fine but on 32-bit architectures obviously not. | |
13 | Not many places actually use the offset stored in the iomap structure | |
14 | but one of visible failures is in SEEK_HOLE / SEEK_DATA implementation. | |
15 | If we create a file like: | |
16 | ||
17 | dd if=/dev/urandom of=file bs=1k seek=8m count=1 | |
18 | ||
19 | then | |
20 | ||
21 | lseek64("file", 0x100000000ULL, SEEK_DATA) | |
22 | ||
23 | wrongly returns 0x100000000 on unfixed kernel while it should return | |
24 | 0x200000000. Avoid the overflow by proper type cast. | |
25 | ||
26 | Fixes: 545052e9e35a ("ext4: Switch to iomap for SEEK_HOLE / SEEK_DATA") | |
27 | Signed-off-by: Jiri Slaby <jslaby@suse.cz> | |
28 | Signed-off-by: Jan Kara <jack@suse.cz> | |
29 | Signed-off-by: Theodore Ts'o <tytso@mit.edu> | |
30 | Cc: stable@vger.kernel.org # v4.15 | |
31 | Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> | |
32 | ||
33 | --- | |
34 | fs/ext4/inode.c | 2 +- | |
35 | 1 file changed, 1 insertion(+), 1 deletion(-) | |
36 | ||
37 | --- a/fs/ext4/inode.c | |
38 | +++ b/fs/ext4/inode.c | |
39 | @@ -3524,7 +3524,7 @@ retry: | |
40 | iomap->flags |= IOMAP_F_DIRTY; | |
41 | iomap->bdev = inode->i_sb->s_bdev; | |
42 | iomap->dax_dev = sbi->s_daxdev; | |
43 | - iomap->offset = first_block << blkbits; | |
44 | + iomap->offset = (u64)first_block << blkbits; | |
45 | iomap->length = (u64)map.m_len << blkbits; | |
46 | ||
47 | if (ret == 0) { |