bcachefs: Stricter checks on "key allowed in this btree"
authorKent Overstreet <kent.overstreet@linux.dev>
Fri, 18 Apr 2025 16:49:00 +0000 (12:49 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 20 Apr 2025 23:41:38 +0000 (19:41 -0400)
commit71f8e806a5e4edada72456ee3b2e2d7eab6fadee
tree813371f93e2eda25b0b1848e030831cd99dc2eef
parent417f01e726036b564e2e14c39b2be58e93bf7971
bcachefs: Stricter checks on "key allowed in this btree"

Syzbot managed to come up with a filesystem where check/repair got
rather confused at finding a reflink pointer in the inodes btree.

Currently, the "key allowed in this btree" checks only apply at commit
time, not read time - for forwards compatibility. It seems this is too
loose.

Now, strict key type allowed checks apply:
 - at commit time (no forward compatibility issues)
 - for btree node pointers
 - if it's a known btree, known key type, and the key type has the
   "BKEY_TYPE_strict_btree_checks" flag.

This means we still have the option of using generic key types - e.g.
KEY_TYPE_error, KEY_TYPE_set - on more existing btrees in the future,
while most key types that are intended for only a specific btree get
stricter checks.

Reported-by: syzbot+baee8591f336cab0958b@syzkaller.appspotmail.com
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/bcachefs_format.h
fs/bcachefs/bkey_methods.c