bcachefs: Hack around bch2_varint_decode invalid reads

bch2_varint_decode can do reads up to 7 bytes past the end ptr, for the
sake of performance - these extra bytes are always masked off.

This won't be a problem in practice if we make sure to burn 8 bytes in
any buffer that has bkeys in it.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
This commit is contained in:
Kent Overstreet 2020-11-11 12:42:54 -05:00 committed by Kent Overstreet
parent e648448ca5
commit 6d9378f3dc
2 changed files with 6 additions and 0 deletions

View file

@ -1532,6 +1532,9 @@ void __bch2_btree_node_write(struct bch_fs *c, struct btree *b,
seq = max(seq, le64_to_cpu(i->journal_seq));
}
/* bch2_varint_decode may read up to 7 bytes past the end of the buffer: */
bytes += 8;
data = btree_bounce_alloc(c, bytes, &used_mempool);
if (!b->written) {

View file

@ -237,6 +237,9 @@ static inline ssize_t __bch_btree_u64s_remaining(struct bch_fs *c,
b->whiteout_u64s;
ssize_t total = c->opts.btree_node_size << 6;
/* Always leave one extra u64 for bch2_varint_decode: */
used++;
return total - used;
}