Skip to content

Commit

Permalink
ext2fs: fix integer overflow in rb_get_bmap_range
Browse files Browse the repository at this point in the history
bmap_rb_extent is defined as __u64:blk __u64:count.  So count can
exceed INT_MAX on populated filesystems.

TESTCASE: xfstest ext4/004

Signed-off-by: Dmitry Monakhov <dmonakhov@openvz.org>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
  • Loading branch information
Dmitry Monakhov authored and tytso committed Dec 11, 2014
1 parent 2503048 commit e50e985
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions lib/ext2fs/blkmap64_rb.c
Original file line number Diff line number Diff line change
Expand Up @@ -733,8 +733,7 @@ static errcode_t rb_get_bmap_range(ext2fs_generic_bitmap bitmap,
struct rb_node *parent = NULL, *next, **n;
struct ext2fs_rb_private *bp;
struct bmap_rb_extent *ext;
int count;
__u64 pos;
__u64 count, pos;

bp = (struct ext2fs_rb_private *) bitmap->private;
n = &bp->root.rb_node;
Expand Down Expand Up @@ -765,9 +764,9 @@ static errcode_t rb_get_bmap_range(ext2fs_generic_bitmap bitmap,
if (pos >= start + num)
break;
if (pos < start) {
count -= start - pos;
if (count < 0)
if (pos + count < start)
continue;
count -= start - pos;
pos = start;
}
if (pos + count > start + num)
Expand Down

0 comments on commit e50e985

Please sign in to comment.