Skip to content

Commit 1373f88

Browse files
jankaragregkh
authored andcommitted
ext4: don't allow overlapping system zones
[ Upstream commit bf9a379 ] Currently, add_system_zone() just silently merges two added system zones that overlap. However the overlap should not happen and it generally suggests that some unrelated metadata overlap which indicates the fs is corrupted. We should have caught such problems earlier (e.g. in ext4_check_descriptors()) but add this check as another line of defense. In later patch we also use this for stricter checking of journal inode extent tree. Reviewed-by: Lukas Czerner <lczerner@redhat.com> Signed-off-by: Jan Kara <jack@suse.cz> Link: https://lore.kernel.org/r/20200728130437.7804-3-jack@suse.cz Signed-off-by: Theodore Ts'o <tytso@mit.edu> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent b3ddf6b commit 1373f88

1 file changed

Lines changed: 13 additions & 23 deletions

File tree

fs/ext4/block_validity.c

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ static int add_system_zone(struct ext4_system_blocks *system_blks,
6868
ext4_fsblk_t start_blk,
6969
unsigned int count)
7070
{
71-
struct ext4_system_zone *new_entry = NULL, *entry;
71+
struct ext4_system_zone *new_entry, *entry;
7272
struct rb_node **n = &system_blks->root.rb_node, *node;
7373
struct rb_node *parent = NULL, *new_node = NULL;
7474

@@ -79,30 +79,20 @@ static int add_system_zone(struct ext4_system_blocks *system_blks,
7979
n = &(*n)->rb_left;
8080
else if (start_blk >= (entry->start_blk + entry->count))
8181
n = &(*n)->rb_right;
82-
else {
83-
if (start_blk + count > (entry->start_blk +
84-
entry->count))
85-
entry->count = (start_blk + count -
86-
entry->start_blk);
87-
new_node = *n;
88-
new_entry = rb_entry(new_node, struct ext4_system_zone,
89-
node);
90-
break;
91-
}
82+
else /* Unexpected overlap of system zones. */
83+
return -EFSCORRUPTED;
9284
}
9385

94-
if (!new_entry) {
95-
new_entry = kmem_cache_alloc(ext4_system_zone_cachep,
96-
GFP_KERNEL);
97-
if (!new_entry)
98-
return -ENOMEM;
99-
new_entry->start_blk = start_blk;
100-
new_entry->count = count;
101-
new_node = &new_entry->node;
102-
103-
rb_link_node(new_node, parent, n);
104-
rb_insert_color(new_node, &system_blks->root);
105-
}
86+
new_entry = kmem_cache_alloc(ext4_system_zone_cachep,
87+
GFP_KERNEL);
88+
if (!new_entry)
89+
return -ENOMEM;
90+
new_entry->start_blk = start_blk;
91+
new_entry->count = count;
92+
new_node = &new_entry->node;
93+
94+
rb_link_node(new_node, parent, n);
95+
rb_insert_color(new_node, &system_blks->root);
10696

10797
/* Can we merge to the left? */
10898
node = rb_prev(new_node);

0 commit comments

Comments
 (0)