Skip to content

Commit 33e53f2

Browse files
Matthew Wilcox (Oracle)gregkh
authored andcommitted
btrfs: fix potential overflow in cluster_pages_for_defrag on 32bit arch
commit a1fbc67 upstream. On 32-bit systems, this shift will overflow for files larger than 4GB as start_index is unsigned long while the calls to btrfs_delalloc_*_space expect u64. CC: stable@vger.kernel.org # 4.4+ Fixes: df48063 ("btrfs: extent-tree: Switch to new delalloc space reserve and release") Reviewed-by: Josef Bacik <josef@toxicpanda.com> Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org> Reviewed-by: David Sterba <dsterba@suse.com> [ define the variable instead of repeating the shift ] Signed-off-by: David Sterba <dsterba@suse.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 9de4ffb commit 33e53f2

1 file changed

Lines changed: 4 additions & 6 deletions

File tree

‎fs/btrfs/ioctl.c‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1255,6 +1255,7 @@ static int cluster_pages_for_defrag(struct inode *inode,
12551255
u64 page_start;
12561256
u64 page_end;
12571257
u64 page_cnt;
1258+
u64 start = (u64)start_index << PAGE_SHIFT;
12581259
int ret;
12591260
int i;
12601261
int i_done;
@@ -1271,8 +1272,7 @@ static int cluster_pages_for_defrag(struct inode *inode,
12711272
page_cnt = min_t(u64, (u64)num_pages, (u64)file_end - start_index + 1);
12721273

12731274
ret = btrfs_delalloc_reserve_space(inode, &data_reserved,
1274-
start_index << PAGE_SHIFT,
1275-
page_cnt << PAGE_SHIFT);
1275+
start, page_cnt << PAGE_SHIFT);
12761276
if (ret)
12771277
return ret;
12781278
i_done = 0;
@@ -1361,8 +1361,7 @@ static int cluster_pages_for_defrag(struct inode *inode,
13611361
btrfs_mod_outstanding_extents(BTRFS_I(inode), 1);
13621362
spin_unlock(&BTRFS_I(inode)->lock);
13631363
btrfs_delalloc_release_space(inode, data_reserved,
1364-
start_index << PAGE_SHIFT,
1365-
(page_cnt - i_done) << PAGE_SHIFT, true);
1364+
start, (page_cnt - i_done) << PAGE_SHIFT, true);
13661365
}
13671366

13681367

@@ -1389,8 +1388,7 @@ static int cluster_pages_for_defrag(struct inode *inode,
13891388
put_page(pages[i]);
13901389
}
13911390
btrfs_delalloc_release_space(inode, data_reserved,
1392-
start_index << PAGE_SHIFT,
1393-
page_cnt << PAGE_SHIFT, true);
1391+
start, page_cnt << PAGE_SHIFT, true);
13941392
btrfs_delalloc_release_extents(BTRFS_I(inode), page_cnt << PAGE_SHIFT);
13951393
extent_changeset_free(data_reserved);
13961394
return ret;

0 commit comments

Comments
 (0)