From d2ed02a94086e1221041bc59825add3d0a657e19 Mon Sep 17 00:00:00 2001 From: Mohamad Ayyash Date: Thu, 28 Apr 2016 21:49:01 -0700 Subject: Incremental Ext4 Bug: prevent out of bound boundary allocations This happens around the boundary of block groups where a slightly different block boundary is set based on size of filesystem which means allocations based on a previous filesystem layout need to verify they're not crossing that new bounday BUG: 27698960 Change-Id: I45d444b4477f14f71e8f17144523505a7525b4e2 Signed-off-by: Mohamad Ayyash --- ext4_utils/make_ext4fs.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'ext4_utils') diff --git a/ext4_utils/make_ext4fs.c b/ext4_utils/make_ext4fs.c index 6083ceaa..f45a6990 100644 --- a/ext4_utils/make_ext4fs.c +++ b/ext4_utils/make_ext4fs.c @@ -617,10 +617,6 @@ static void extract_base_fs_allocations(const char *directory, const char *mount } else { end_block = parse_num(range); } - block_file_size = end_block - start_block + 1; - if (block_file_size > real_file_block_size) { - block_file_size = real_file_block_size; - } // Assummption is that allocations are within the same block group block_group = get_block_group(start_block); if (block_group != get_block_group(end_block)) { @@ -628,6 +624,18 @@ static void extract_base_fs_allocations(const char *directory, const char *mount "block group than start block. did you change fs params?"); } block_range = strtok_r(NULL, ",", &end_string); + int bg_first_block = bgs[block_group].first_block; + int min_bg_bound = bgs[block_group].chunks[0].block + bgs[block_group].chunks[0].len; + int max_bg_bound = bgs[block_group].chunks[bgs[block_group].chunk_count - 1].block; + + if (min_bg_bound >= start_block - bg_first_block || + max_bg_bound <= end_block - bg_first_block) { + continue; + } + block_file_size = end_block - start_block + 1; + if (block_file_size > real_file_block_size) { + block_file_size = real_file_block_size; + } append_region(fs_alloc, start_block, block_file_size, block_group); reserve_bg_chunk(block_group, start_block - bgs[block_group].first_block, block_file_size); real_file_block_size -= block_file_size; -- cgit v1.2.3