Re: [syzbot] [bcachefs?] KASAN: slab-out-of-bounds Read in journal_entry_dev_usage_to_text
From: Edward Adam Davis
Date: Mon Jul 29 2024 - 22:22:36 EST
entry bytes too small ?
#syz test: upstream 1722389b0d86
diff --git a/fs/bcachefs/sb-clean.c b/fs/bcachefs/sb-clean.c
index 47f10ab57f40..a10d3e6e8119 100644
--- a/fs/bcachefs/sb-clean.c
+++ b/fs/bcachefs/sb-clean.c
@@ -303,6 +303,7 @@ static void bch2_sb_clean_to_text(struct printbuf *out, struct bch_sb *sb,
for (entry = clean->start;
entry != vstruct_end(&clean->field);
entry = vstruct_next(entry)) {
+ unsigned bytes = vstruct_bytes(entry);
if ((void *) vstruct_next(entry) > vstruct_end(&clean->field))
break;
@@ -310,6 +311,11 @@ static void bch2_sb_clean_to_text(struct printbuf *out, struct bch_sb *sb,
!entry->u64s)
continue;
+ printk("entry bytes:%u, jedu: %u, %s\n", bytes,
+ sizeof(struct jset_entry_dev_usage), __func__);
+ if (bytes < sizeof(struct jset_entry_dev_usage))
+ continue;
+
bch2_journal_entry_to_text(out, NULL, entry);
prt_newline(out);
}