Skip to content

Commit 6f1b228

Browse files
gtmothtorvalds
authored andcommitted
ocfs2: fix race between searching chunks and release journal_head from buffer_head
Encountered a race between ocfs2_test_bg_bit_allocatable() and jbd2_journal_put_journal_head() resulting in the below vmcore. PID: 106879 TASK: ffff880244ba9c00 CPU: 2 COMMAND: "loop3" Call trace: panic oops_end no_context __bad_area_nosemaphore bad_area_nosemaphore __do_page_fault do_page_fault page_fault [exception RIP: ocfs2_block_group_find_clear_bits+316] ocfs2_block_group_find_clear_bits [ocfs2] ocfs2_cluster_group_search [ocfs2] ocfs2_search_chain [ocfs2] ocfs2_claim_suballoc_bits [ocfs2] __ocfs2_claim_clusters [ocfs2] ocfs2_claim_clusters [ocfs2] ocfs2_local_alloc_slide_window [ocfs2] ocfs2_reserve_local_alloc_bits [ocfs2] ocfs2_reserve_clusters_with_limit [ocfs2] ocfs2_reserve_clusters [ocfs2] ocfs2_lock_refcount_allocators [ocfs2] ocfs2_make_clusters_writable [ocfs2] ocfs2_replace_cow [ocfs2] ocfs2_refcount_cow [ocfs2] ocfs2_file_write_iter [ocfs2] lo_rw_aio loop_queue_work kthread_worker_fn kthread ret_from_fork When ocfs2_test_bg_bit_allocatable() called bh2jh(bg_bh), the bg_bh->b_private NULL as jbd2_journal_put_journal_head() raced and released the jounal head from the buffer head. Needed to take bit lock for the bit 'BH_JournalHead' to fix this race. Link: https://lkml.kernel.org/r/1634820718-6043-1-git-send-email-gautham.ananthakrishna@oracle.com Signed-off-by: Gautham Ananthakrishna <[email protected]> Reviewed-by: Joseph Qi <[email protected]> Cc: <[email protected]> Cc: Mark Fasheh <[email protected]> Cc: Joel Becker <[email protected]> Cc: Junxiao Bi <[email protected]> Cc: Changwei Ge <[email protected]> Cc: Gang He <[email protected]> Cc: Jun Piao <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 337546e commit 6f1b228

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

fs/ocfs2/suballoc.c

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1251,22 +1251,26 @@ static int ocfs2_test_bg_bit_allocatable(struct buffer_head *bg_bh,
12511251
{
12521252
struct ocfs2_group_desc *bg = (struct ocfs2_group_desc *) bg_bh->b_data;
12531253
struct journal_head *jh;
1254-
int ret;
1254+
int ret = 1;
12551255

12561256
if (ocfs2_test_bit(nr, (unsigned long *)bg->bg_bitmap))
12571257
return 0;
12581258

12591259
if (!buffer_jbd(bg_bh))
12601260
return 1;
12611261

1262-
jh = bh2jh(bg_bh);
1263-
spin_lock(&jh->b_state_lock);
1264-
bg = (struct ocfs2_group_desc *) jh->b_committed_data;
1265-
if (bg)
1266-
ret = !ocfs2_test_bit(nr, (unsigned long *)bg->bg_bitmap);
1267-
else
1268-
ret = 1;
1269-
spin_unlock(&jh->b_state_lock);
1262+
jbd_lock_bh_journal_head(bg_bh);
1263+
if (buffer_jbd(bg_bh)) {
1264+
jh = bh2jh(bg_bh);
1265+
spin_lock(&jh->b_state_lock);
1266+
bg = (struct ocfs2_group_desc *) jh->b_committed_data;
1267+
if (bg)
1268+
ret = !ocfs2_test_bit(nr, (unsigned long *)bg->bg_bitmap);
1269+
else
1270+
ret = 1;
1271+
spin_unlock(&jh->b_state_lock);
1272+
}
1273+
jbd_unlock_bh_journal_head(bg_bh);
12701274

12711275
return ret;
12721276
}

0 commit comments

Comments
 (0)