Re: [syzbot] [bcachefs?] UBSAN: shift-out-of-bounds in rewrite_old_nodes_pred

From: Edward Adam Davis
Date: Mon May 06 2024 - 07:40:20 EST


please test oob in rewrite_old_nodes_pred

#syz test https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 7367539ad4b0

diff --git a/fs/bcachefs/bkey.c b/fs/bcachefs/bkey.c
index 76e79a15ba08..1b2cb956b2e0 100644
--- a/fs/bcachefs/bkey.c
+++ b/fs/bcachefs/bkey.c
@@ -577,7 +577,7 @@ static void set_format_field(struct bkey_format *f, enum bch_bkey_fields i,
unsigned unpacked_bits = bch2_bkey_format_current.bits_per_field[i];
u64 unpacked_max = ~((~0ULL << 1) << (unpacked_bits - 1));

- bits = min(bits, unpacked_bits);
+ bits = min3(bits, unpacked_bits, 63);

offset = bits == unpacked_bits ? 0 : min(offset, unpacked_max - ((1ULL << bits) - 1));