Skip to content

Commit d2ed02a

Browse files
committed
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 <[email protected]>
1 parent dedf8f9 commit d2ed02a

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

ext4_utils/make_ext4fs.c

+12-4
Original file line numberDiff line numberDiff line change
@@ -617,17 +617,25 @@ static void extract_base_fs_allocations(const char *directory, const char *mount
617617
} else {
618618
end_block = parse_num(range);
619619
}
620-
block_file_size = end_block - start_block + 1;
621-
if (block_file_size > real_file_block_size) {
622-
block_file_size = real_file_block_size;
623-
}
624620
// Assummption is that allocations are within the same block group
625621
block_group = get_block_group(start_block);
626622
if (block_group != get_block_group(end_block)) {
627623
critical_error("base file allocation's end block is in a different "
628624
"block group than start block. did you change fs params?");
629625
}
630626
block_range = strtok_r(NULL, ",", &end_string);
627+
int bg_first_block = bgs[block_group].first_block;
628+
int min_bg_bound = bgs[block_group].chunks[0].block + bgs[block_group].chunks[0].len;
629+
int max_bg_bound = bgs[block_group].chunks[bgs[block_group].chunk_count - 1].block;
630+
631+
if (min_bg_bound >= start_block - bg_first_block ||
632+
max_bg_bound <= end_block - bg_first_block) {
633+
continue;
634+
}
635+
block_file_size = end_block - start_block + 1;
636+
if (block_file_size > real_file_block_size) {
637+
block_file_size = real_file_block_size;
638+
}
631639
append_region(fs_alloc, start_block, block_file_size, block_group);
632640
reserve_bg_chunk(block_group, start_block - bgs[block_group].first_block, block_file_size);
633641
real_file_block_size -= block_file_size;

0 commit comments

Comments
 (0)