Skip to content

Commit f390552

Browse files
author
Kent Overstreet
committed
bcachefs: Add missing validation for superblock section clean
We were forgetting to check for jset entries that overrun the end of the section - both in validate and to_text(); to_text() needs to be safe for types that fail to validate. Reported-by: syzbot+c48865e11e7e893ec4ab@syzkaller.appspotmail.com Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
1 parent 6b8cbfc commit f390552

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

fs/bcachefs/sb-clean.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,17 @@ static int bch2_sb_clean_validate(struct bch_sb *sb,
278278
return -BCH_ERR_invalid_sb_clean;
279279
}
280280

281+
for (struct jset_entry *entry = clean->start;
282+
entry != vstruct_end(&clean->field);
283+
entry = vstruct_next(entry)) {
284+
if ((void *) vstruct_next(entry) > vstruct_end(&clean->field)) {
285+
prt_str(err, "entry type ");
286+
bch2_prt_jset_entry_type(err, le16_to_cpu(entry->type));
287+
prt_str(err, " overruns end of section");
288+
return -BCH_ERR_invalid_sb_clean;
289+
}
290+
}
291+
281292
return 0;
282293
}
283294

@@ -295,6 +306,9 @@ static void bch2_sb_clean_to_text(struct printbuf *out, struct bch_sb *sb,
295306
for (entry = clean->start;
296307
entry != vstruct_end(&clean->field);
297308
entry = vstruct_next(entry)) {
309+
if ((void *) vstruct_next(entry) > vstruct_end(&clean->field))
310+
break;
311+
298312
if (entry->type == BCH_JSET_ENTRY_btree_keys &&
299313
!entry->u64s)
300314
continue;

0 commit comments

Comments
 (0)