Skip to content

Commit 3726a19

Browse files
JungerBoyoKent Overstreet
authored andcommitted
bcachefs: Fix NULL ptr dereference in btree_node_iter_and_journal_peek
Add NULL check for key returned from bch2_btree_and_journal_iter_peek in btree_node_iter_and_journal_peek to avoid NULL ptr dereference in bch2_bkey_buf_reassemble. When key returned from bch2_btree_and_journal_iter_peek is NULL it means that btree topology needs repair. Print topology error message with position at which node wasn't found, its parent node information and btree_id with level. Return error code returned by bch2_topology_error to ensure that topology error is handled properly by recovery. Reported-by: [email protected] Closes: https://syzkaller.appspot.com/bug?extid=005ef9aa519f30d97657 Fixes: 5222a46 ("bcachefs: BTREE_ITER_WITH_JOURNAL") Suggested-by: Alan Huang <[email protected]> Suggested-by: Kent Overstreet <[email protected]> Signed-off-by: Piotr Zalewski <[email protected]> Signed-off-by: Kent Overstreet <[email protected]>
1 parent ca959e3 commit 3726a19

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

fs/bcachefs/btree_iter.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -882,13 +882,26 @@ static noinline int btree_node_iter_and_journal_peek(struct btree_trans *trans,
882882
__bch2_btree_and_journal_iter_init_node_iter(trans, &jiter, l->b, l->iter, path->pos);
883883

884884
k = bch2_btree_and_journal_iter_peek(&jiter);
885+
if (!k.k) {
886+
struct printbuf buf = PRINTBUF;
887+
888+
prt_str(&buf, "node not found at pos ");
889+
bch2_bpos_to_text(&buf, path->pos);
890+
prt_str(&buf, " at btree ");
891+
bch2_btree_pos_to_text(&buf, c, l->b);
892+
893+
ret = bch2_fs_topology_error(c, "%s", buf.buf);
894+
printbuf_exit(&buf);
895+
goto err;
896+
}
885897

886898
bch2_bkey_buf_reassemble(out, c, k);
887899

888900
if ((flags & BTREE_ITER_prefetch) &&
889901
c->opts.btree_node_prefetch)
890902
ret = btree_path_prefetch_j(trans, path, &jiter);
891903

904+
err:
892905
bch2_btree_and_journal_iter_exit(&jiter);
893906
return ret;
894907
}

0 commit comments

Comments
 (0)