Skip to content

Commit fcdbc1d

Browse files
author
Kent Overstreet
committed
bcachefs: Check for journal entries overruning end of sb clean section
Fix a missing bounds check in superblock validation. Note that we don't yet have repair code for this case - repair code for individual items is generally low priority, since the whole superblock is checksummed, validated prior to write, and we have backups. Reported-by: lei lu <llfamsec@gmail.com> Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
1 parent 0389c09 commit fcdbc1d

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

fs/bcachefs/sb-clean.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ int bch2_sb_clean_validate_late(struct bch_fs *c, struct bch_sb_field_clean *cle
2929
for (entry = clean->start;
3030
entry < (struct jset_entry *) vstruct_end(&clean->field);
3131
entry = vstruct_next(entry)) {
32+
if (vstruct_end(entry) > vstruct_end(&clean->field)) {
33+
bch_err(c, "journal entry (u64s %u) overran end of superblock clean section (u64s %u) by %zu",
34+
le16_to_cpu(entry->u64s), le32_to_cpu(clean->field.u64s),
35+
(u64 *) vstruct_end(entry) - (u64 *) vstruct_end(&clean->field));
36+
bch2_sb_error_count(c, BCH_FSCK_ERR_sb_clean_entry_overrun);
37+
return -BCH_ERR_fsck_repair_unimplemented;
38+
}
39+
3240
ret = bch2_journal_entry_validate(c, NULL, entry,
3341
le16_to_cpu(c->disk_sb.sb->version),
3442
BCH_SB_BIG_ENDIAN(c->disk_sb.sb),

fs/bcachefs/sb-errors_types.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,8 @@
271271
x(btree_root_unreadable_and_scan_found_nothing, 263) \
272272
x(snapshot_node_missing, 264) \
273273
x(dup_backpointer_to_bad_csum_extent, 265) \
274-
x(btree_bitmap_not_marked, 266)
274+
x(btree_bitmap_not_marked, 266) \
275+
x(sb_clean_entry_overrun, 267)
275276

276277
enum bch_sb_error_id {
277278
#define x(t, n) BCH_FSCK_ERR_##t = n,

0 commit comments

Comments
 (0)