mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-08-27 11:19:37 +00:00
ext4: fix overflows in SEEK_HOLE, SEEK_DATA implementations
ext4_lblk_t is just u32 so multiplying it by blocksize can easily overflow for files larger than 4 GB. Fix that by properly typing the block offsets before shifting. Signed-off-by: Jan Kara <jack@suse.cz> Signed-off-by: Theodore Ts'o <tytso@mit.edu> Reviewed-by: Zheng Liu <wenqing.lz@taobao.com>
This commit is contained in:
parent
eaf3793728
commit
e7293fd146
1 changed files with 7 additions and 7 deletions
|
@ -312,7 +312,7 @@ static int ext4_find_unwritten_pgoff(struct inode *inode,
|
||||||
blkbits = inode->i_sb->s_blocksize_bits;
|
blkbits = inode->i_sb->s_blocksize_bits;
|
||||||
startoff = *offset;
|
startoff = *offset;
|
||||||
lastoff = startoff;
|
lastoff = startoff;
|
||||||
endoff = (map->m_lblk + map->m_len) << blkbits;
|
endoff = (loff_t)(map->m_lblk + map->m_len) << blkbits;
|
||||||
|
|
||||||
index = startoff >> PAGE_CACHE_SHIFT;
|
index = startoff >> PAGE_CACHE_SHIFT;
|
||||||
end = endoff >> PAGE_CACHE_SHIFT;
|
end = endoff >> PAGE_CACHE_SHIFT;
|
||||||
|
@ -457,7 +457,7 @@ static loff_t ext4_seek_data(struct file *file, loff_t offset, loff_t maxsize)
|
||||||
ret = ext4_map_blocks(NULL, inode, &map, 0);
|
ret = ext4_map_blocks(NULL, inode, &map, 0);
|
||||||
if (ret > 0 && !(map.m_flags & EXT4_MAP_UNWRITTEN)) {
|
if (ret > 0 && !(map.m_flags & EXT4_MAP_UNWRITTEN)) {
|
||||||
if (last != start)
|
if (last != start)
|
||||||
dataoff = last << blkbits;
|
dataoff = (loff_t)last << blkbits;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -468,7 +468,7 @@ static loff_t ext4_seek_data(struct file *file, loff_t offset, loff_t maxsize)
|
||||||
ext4_es_find_delayed_extent_range(inode, last, last, &es);
|
ext4_es_find_delayed_extent_range(inode, last, last, &es);
|
||||||
if (es.es_len != 0 && in_range(last, es.es_lblk, es.es_len)) {
|
if (es.es_len != 0 && in_range(last, es.es_lblk, es.es_len)) {
|
||||||
if (last != start)
|
if (last != start)
|
||||||
dataoff = last << blkbits;
|
dataoff = (loff_t)last << blkbits;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -486,7 +486,7 @@ static loff_t ext4_seek_data(struct file *file, loff_t offset, loff_t maxsize)
|
||||||
}
|
}
|
||||||
|
|
||||||
last++;
|
last++;
|
||||||
dataoff = last << blkbits;
|
dataoff = (loff_t)last << blkbits;
|
||||||
} while (last <= end);
|
} while (last <= end);
|
||||||
|
|
||||||
mutex_unlock(&inode->i_mutex);
|
mutex_unlock(&inode->i_mutex);
|
||||||
|
@ -540,7 +540,7 @@ static loff_t ext4_seek_hole(struct file *file, loff_t offset, loff_t maxsize)
|
||||||
ret = ext4_map_blocks(NULL, inode, &map, 0);
|
ret = ext4_map_blocks(NULL, inode, &map, 0);
|
||||||
if (ret > 0 && !(map.m_flags & EXT4_MAP_UNWRITTEN)) {
|
if (ret > 0 && !(map.m_flags & EXT4_MAP_UNWRITTEN)) {
|
||||||
last += ret;
|
last += ret;
|
||||||
holeoff = last << blkbits;
|
holeoff = (loff_t)last << blkbits;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -551,7 +551,7 @@ static loff_t ext4_seek_hole(struct file *file, loff_t offset, loff_t maxsize)
|
||||||
ext4_es_find_delayed_extent_range(inode, last, last, &es);
|
ext4_es_find_delayed_extent_range(inode, last, last, &es);
|
||||||
if (es.es_len != 0 && in_range(last, es.es_lblk, es.es_len)) {
|
if (es.es_len != 0 && in_range(last, es.es_lblk, es.es_len)) {
|
||||||
last = es.es_lblk + es.es_len;
|
last = es.es_lblk + es.es_len;
|
||||||
holeoff = last << blkbits;
|
holeoff = (loff_t)last << blkbits;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -566,7 +566,7 @@ static loff_t ext4_seek_hole(struct file *file, loff_t offset, loff_t maxsize)
|
||||||
&map, &holeoff);
|
&map, &holeoff);
|
||||||
if (!unwritten) {
|
if (!unwritten) {
|
||||||
last += ret;
|
last += ret;
|
||||||
holeoff = last << blkbits;
|
holeoff = (loff_t)last << blkbits;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue