Commit 765b8cb8 authored by Kent Overstreet's avatar Kent Overstreet
Browse files

bcachefs: Check for subvolues with bogus snapshot/inode fields



This fixes an assertion pop in btree_iter.c that checks for forgetting
to pass a snapshot ID when iterating over snapshots btrees.

Reported-by: default avatar <syzbot+0dfe05235e38653e2aee@syzkaller.appspotmail.com>
Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent 6b74fdcc
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -273,7 +273,9 @@
	x(dup_backpointer_to_bad_csum_extent,			265)	\
	x(btree_bitmap_not_marked,				266)	\
	x(sb_clean_entry_overrun,				267)	\
	x(btree_ptr_v2_written_0,				268)
	x(btree_ptr_v2_written_0,				268)	\
	x(subvol_snapshot_bad,					269)	\
	x(subvol_inode_bad,					270)

enum bch_sb_error_id {
#define x(t, n) BCH_FSCK_ERR_##t = n,
+9 −0
Original line number Diff line number Diff line
@@ -210,12 +210,21 @@ int bch2_check_subvol_children(struct bch_fs *c)
int bch2_subvolume_invalid(struct bch_fs *c, struct bkey_s_c k,
			   enum bch_validate_flags flags, struct printbuf *err)
{
	struct bkey_s_c_subvolume subvol = bkey_s_c_to_subvolume(k);
	int ret = 0;

	bkey_fsck_err_on(bkey_lt(k.k->p, SUBVOL_POS_MIN) ||
			 bkey_gt(k.k->p, SUBVOL_POS_MAX), c, err,
			 subvol_pos_bad,
			 "invalid pos");

	bkey_fsck_err_on(!subvol.v->snapshot, c, err,
			 subvol_snapshot_bad,
			 "invalid snapshot");

	bkey_fsck_err_on(!subvol.v->inode, c, err,
			 subvol_inode_bad,
			 "invalid inode");
fsck_err:
	return ret;
}