Skip to content

Commit e49be14

Browse files
dlrobertsonkdave
authored andcommitted
btrfs: init csum_list before possible free
The scrub_ctx csum_list member must be initialized before scrub_free_ctx is called. If the csum_list is not initialized beforehand, the list_empty call in scrub_free_csums will result in a null deref if the allocation fails in the for loop. Fixes: a2de733 ("btrfs: scrub") CC: stable@vger.kernel.org # 3.0+ Reviewed-by: Nikolay Borisov <nborisov@suse.com> Signed-off-by: Dan Robertson <dan@dlrobertson.com> Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent 57a50e2 commit e49be14

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

fs/btrfs/scrub.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,7 @@ static noinline_for_stack struct scrub_ctx *scrub_setup_ctx(
584584
sctx->pages_per_rd_bio = SCRUB_PAGES_PER_RD_BIO;
585585
sctx->curr = -1;
586586
sctx->fs_info = fs_info;
587+
INIT_LIST_HEAD(&sctx->csum_list);
587588
for (i = 0; i < SCRUB_BIOS_PER_SCTX; ++i) {
588589
struct scrub_bio *sbio;
589590

@@ -608,7 +609,6 @@ static noinline_for_stack struct scrub_ctx *scrub_setup_ctx(
608609
atomic_set(&sctx->workers_pending, 0);
609610
atomic_set(&sctx->cancel_req, 0);
610611
sctx->csum_size = btrfs_super_csum_size(fs_info->super_copy);
611-
INIT_LIST_HEAD(&sctx->csum_list);
612612

613613
spin_lock_init(&sctx->list_lock);
614614
spin_lock_init(&sctx->stat_lock);

0 commit comments

Comments
 (0)