Skip to content

Commit bdbdd47

Browse files
author
Kent Overstreet
committed
bcachefs: Fix missing validation in bch2_sb_journal_v2_validate()
Reported-by: [email protected] Signed-off-by: Kent Overstreet <[email protected]>
1 parent cab18be commit bdbdd47

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

fs/bcachefs/journal_sb.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ static int bch2_sb_journal_v2_validate(struct bch_sb *sb, struct bch_sb_field *f
104104
struct bch_sb_field_journal_v2 *journal = field_to_type(f, journal_v2);
105105
struct bch_member m = bch2_sb_member_get(sb, sb->dev_idx);
106106
int ret = -BCH_ERR_invalid_sb_journal;
107+
u64 sum = 0;
107108
unsigned nr;
108109
unsigned i;
109110
struct u64_range *b;
@@ -119,6 +120,15 @@ static int bch2_sb_journal_v2_validate(struct bch_sb *sb, struct bch_sb_field *f
119120
for (i = 0; i < nr; i++) {
120121
b[i].start = le64_to_cpu(journal->d[i].start);
121122
b[i].end = b[i].start + le64_to_cpu(journal->d[i].nr);
123+
124+
if (b[i].end <= b[i].start) {
125+
prt_printf(err, "journal buckets entry with bad nr: %llu+%llu",
126+
le64_to_cpu(journal->d[i].start),
127+
le64_to_cpu(journal->d[i].nr));
128+
goto err;
129+
}
130+
131+
sum += le64_to_cpu(journal->d[i].nr);
122132
}
123133

124134
sort(b, nr, sizeof(*b), u64_range_cmp, NULL);
@@ -148,6 +158,11 @@ static int bch2_sb_journal_v2_validate(struct bch_sb *sb, struct bch_sb_field *f
148158
}
149159
}
150160

161+
if (sum > UINT_MAX) {
162+
prt_printf(err, "too many journal buckets: %llu > %u", sum, UINT_MAX);
163+
goto err;
164+
}
165+
151166
ret = 0;
152167
err:
153168
kfree(b);

0 commit comments

Comments
 (0)