Commit 833576b3 authored by Theodore Ts'o's avatar Theodore Ts'o

ext4: Fix ext4_mb_initialize_context() to initialize all fields

Pavel Roskin pointed out that kmemcheck indicated that
ext4_mb_store_history() was accessing uninitialized values of
ac->ac_tail and ac->ac_buddy leading to garbage in the mballoc
history.  Fix this by initializing the entire structure to all zeros
first.

Also, two fields were getting doubly initialized by the caller of
ext4_mb_initialize_context, so remove them for efficiency's sake.
Signed-off-by: default avatar"Theodore Ts'o" <tytso@mit.edu>
parent ac046f1d
...@@ -4227,14 +4227,9 @@ ext4_mb_initialize_context(struct ext4_allocation_context *ac, ...@@ -4227,14 +4227,9 @@ ext4_mb_initialize_context(struct ext4_allocation_context *ac,
ext4_get_group_no_and_offset(sb, goal, &group, &block); ext4_get_group_no_and_offset(sb, goal, &group, &block);
/* set up allocation goals */ /* set up allocation goals */
memset(ac, 0, sizeof(struct ext4_allocation_context));
ac->ac_b_ex.fe_logical = ar->logical; ac->ac_b_ex.fe_logical = ar->logical;
ac->ac_b_ex.fe_group = 0;
ac->ac_b_ex.fe_start = 0;
ac->ac_b_ex.fe_len = 0;
ac->ac_status = AC_STATUS_CONTINUE; ac->ac_status = AC_STATUS_CONTINUE;
ac->ac_groups_scanned = 0;
ac->ac_ex_scanned = 0;
ac->ac_found = 0;
ac->ac_sb = sb; ac->ac_sb = sb;
ac->ac_inode = ar->inode; ac->ac_inode = ar->inode;
ac->ac_o_ex.fe_logical = ar->logical; ac->ac_o_ex.fe_logical = ar->logical;
...@@ -4245,15 +4240,7 @@ ext4_mb_initialize_context(struct ext4_allocation_context *ac, ...@@ -4245,15 +4240,7 @@ ext4_mb_initialize_context(struct ext4_allocation_context *ac,
ac->ac_g_ex.fe_group = group; ac->ac_g_ex.fe_group = group;
ac->ac_g_ex.fe_start = block; ac->ac_g_ex.fe_start = block;
ac->ac_g_ex.fe_len = len; ac->ac_g_ex.fe_len = len;
ac->ac_f_ex.fe_len = 0;
ac->ac_flags = ar->flags; ac->ac_flags = ar->flags;
ac->ac_2order = 0;
ac->ac_criteria = 0;
ac->ac_pa = NULL;
ac->ac_bitmap_page = NULL;
ac->ac_buddy_page = NULL;
ac->alloc_semp = NULL;
ac->ac_lg = NULL;
/* we have to define context: we'll we work with a file or /* we have to define context: we'll we work with a file or
* locality group. this is a policy, actually */ * locality group. this is a policy, actually */
...@@ -4521,10 +4508,7 @@ ext4_fsblk_t ext4_mb_new_blocks(handle_t *handle, ...@@ -4521,10 +4508,7 @@ ext4_fsblk_t ext4_mb_new_blocks(handle_t *handle,
} }
ac = kmem_cache_alloc(ext4_ac_cachep, GFP_NOFS); ac = kmem_cache_alloc(ext4_ac_cachep, GFP_NOFS);
if (ac) { if (!ac) {
ac->ac_sb = sb;
ac->ac_inode = ar->inode;
} else {
ar->len = 0; ar->len = 0;
*errp = -ENOMEM; *errp = -ENOMEM;
goto out1; goto out1;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment