Commit bc2e5d5c authored by Kent Overstreet's avatar Kent Overstreet Committed by Kent Overstreet

bcachefs: Fix an out of bounds read

bch2_varint_decode() can read up to 7 bytes past the end of the buffer,
which means we need to allocate slightly larger key cache buffers.
Signed-off-by: default avatarKent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent 65c0601a
...@@ -219,8 +219,14 @@ static int btree_key_cache_fill(struct btree_trans *trans, ...@@ -219,8 +219,14 @@ static int btree_key_cache_fill(struct btree_trans *trans,
goto err; goto err;
} }
if (k.k->u64s > ck->u64s) { /*
new_u64s = roundup_pow_of_two(k.k->u64s); * bch2_varint_decode can read past the end of the buffer by at
* most 7 bytes (it won't be used):
*/
new_u64s = k.k->u64s + 1;
if (new_u64s > ck->u64s) {
new_u64s = roundup_pow_of_two(new_u64s);
new_k = kmalloc(new_u64s * sizeof(u64), GFP_NOFS); new_k = kmalloc(new_u64s * sizeof(u64), GFP_NOFS);
if (!new_k) { if (!new_k) {
ret = -ENOMEM; ret = -ENOMEM;
......
...@@ -293,6 +293,12 @@ btree_key_can_insert_cached(struct btree_trans *trans, ...@@ -293,6 +293,12 @@ btree_key_can_insert_cached(struct btree_trans *trans,
!(trans->flags & BTREE_INSERT_JOURNAL_RECLAIM)) !(trans->flags & BTREE_INSERT_JOURNAL_RECLAIM))
return BTREE_INSERT_NEED_JOURNAL_RECLAIM; return BTREE_INSERT_NEED_JOURNAL_RECLAIM;
/*
* bch2_varint_decode can read past the end of the buffer by at most 7
* bytes (it won't be used):
*/
u64s += 1;
if (u64s <= ck->u64s) if (u64s <= ck->u64s)
return BTREE_INSERT_OK; return BTREE_INSERT_OK;
......
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