Commit d47df4f6 authored by Kent Overstreet's avatar Kent Overstreet

bcachefs: Fix array-index-out-of-bounds

We use 0 size arrays as markers, but ubsan doesn't know that - cast them
to a pointer to fix the splat.

Also, make sure this code gets tested a bit more.
Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent f770a6e9
...@@ -1064,7 +1064,7 @@ void bch2_bkey_swab_key(const struct bkey_format *_f, struct bkey_packed *k) ...@@ -1064,7 +1064,7 @@ void bch2_bkey_swab_key(const struct bkey_format *_f, struct bkey_packed *k)
{ {
const struct bkey_format *f = bkey_packed(k) ? _f : &bch2_bkey_format_current; const struct bkey_format *f = bkey_packed(k) ? _f : &bch2_bkey_format_current;
u8 *l = k->key_start; u8 *l = k->key_start;
u8 *h = (u8 *) (k->_data + f->key_u64s) - 1; u8 *h = (u8 *) ((u64 *) k->_data + f->key_u64s) - 1;
while (l < h) { while (l < h) {
swap(*l, *h); swap(*l, *h);
......
...@@ -398,8 +398,12 @@ void __bch2_bkey_compat(unsigned level, enum btree_id btree_id, ...@@ -398,8 +398,12 @@ void __bch2_bkey_compat(unsigned level, enum btree_id btree_id,
for (i = 0; i < nr_compat; i++) for (i = 0; i < nr_compat; i++)
switch (!write ? i : nr_compat - 1 - i) { switch (!write ? i : nr_compat - 1 - i) {
case 0: case 0:
if (big_endian != CPU_BIG_ENDIAN) if (big_endian != CPU_BIG_ENDIAN) {
bch2_bkey_swab_key(f, k);
} else if (IS_ENABLED(CONFIG_BCACHEFS_DEBUG)) {
bch2_bkey_swab_key(f, k); bch2_bkey_swab_key(f, k);
bch2_bkey_swab_key(f, k);
}
break; break;
case 1: case 1:
if (version < bcachefs_metadata_version_bkey_renumber) if (version < bcachefs_metadata_version_bkey_renumber)
......
...@@ -129,7 +129,8 @@ static inline void bch2_bkey_compat(unsigned level, enum btree_id btree_id, ...@@ -129,7 +129,8 @@ static inline void bch2_bkey_compat(unsigned level, enum btree_id btree_id,
struct bkey_packed *k) struct bkey_packed *k)
{ {
if (version < bcachefs_metadata_version_current || if (version < bcachefs_metadata_version_current ||
big_endian != CPU_BIG_ENDIAN) big_endian != CPU_BIG_ENDIAN ||
IS_ENABLED(CONFIG_BCACHEFS_DEBUG))
__bch2_bkey_compat(level, btree_id, version, __bch2_bkey_compat(level, btree_id, version,
big_endian, write, f, k); big_endian, write, f, k);
......
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