Commit 6d9378f3 authored by Kent Overstreet's avatar Kent Overstreet Committed by Kent Overstreet

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: default avatarKent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent e648448c
...@@ -1532,6 +1532,9 @@ void __bch2_btree_node_write(struct bch_fs *c, struct btree *b, ...@@ -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)); 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); data = btree_bounce_alloc(c, bytes, &used_mempool);
if (!b->written) { if (!b->written) {
......
...@@ -237,6 +237,9 @@ static inline ssize_t __bch_btree_u64s_remaining(struct bch_fs *c, ...@@ -237,6 +237,9 @@ static inline ssize_t __bch_btree_u64s_remaining(struct bch_fs *c,
b->whiteout_u64s; b->whiteout_u64s;
ssize_t total = c->opts.btree_node_size << 6; ssize_t total = c->opts.btree_node_size << 6;
/* Always leave one extra u64 for bch2_varint_decode: */
used++;
return total - used; return total - used;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment