Skip to content

Commit d335bb3

Browse files
author
Kent Overstreet
committed
bcachefs: Ancient versions with bad bkey_formats are no longer supported
Syzbot found an assertion pop, by generating an ancient filesystem version with an invalid bkey_format (with fields that can overflow) as well as packed keys that aren't representable unpacked. This breaks key comparisons in all sorts of painful ways. Filesystems have been automatically rewriting nodes with such invalid formats for years; we can safely drop support for them. Reported-by: syzbot+8a0109511de9d4b61217@syzkaller.appspotmail.com Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
1 parent 72acab3 commit d335bb3

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

fs/bcachefs/bkey.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,7 @@ int bch2_bkey_format_invalid(struct bch_fs *c,
643643
enum bch_validate_flags flags,
644644
struct printbuf *err)
645645
{
646-
unsigned i, bits = KEY_PACKED_BITS_START;
646+
unsigned bits = KEY_PACKED_BITS_START;
647647

648648
if (f->nr_fields != BKEY_NR_FIELDS) {
649649
prt_printf(err, "incorrect number of fields: got %u, should be %u",
@@ -655,9 +655,8 @@ int bch2_bkey_format_invalid(struct bch_fs *c,
655655
* Verify that the packed format can't represent fields larger than the
656656
* unpacked format:
657657
*/
658-
for (i = 0; i < f->nr_fields; i++) {
659-
if ((!c || c->sb.version_min >= bcachefs_metadata_version_snapshot) &&
660-
bch2_bkey_format_field_overflows(f, i)) {
658+
for (unsigned i = 0; i < f->nr_fields; i++) {
659+
if (bch2_bkey_format_field_overflows(f, i)) {
661660
unsigned unpacked_bits = bch2_bkey_format_current.bits_per_field[i];
662661
u64 unpacked_max = ~((~0ULL << 1) << (unpacked_bits - 1));
663662
unsigned packed_bits = min(64, f->bits_per_field[i]);

0 commit comments

Comments
 (0)