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

Gianfranco Trad
2024-10-23T20:48:03Z

[-- Attachment #1: Type: text/plain, Size: 9 bytes --]

#syz test

[-- Attachment #2: 0001-bcachefs-Fix-invalid-shift-in-validate_sb_layout.patch --]
[-- Type: text/x-patch, Size: 876 bytes --]

From 071c4a6311a1ff53ec6097ebca4561d1880271c3 Mon Sep 17 00:00:00 2001
From: Gianfranco Trad <gianf.trad@gmail.com>
Date: Wed, 23 Oct 2024 22:42:56 +0200
Subject: [PATCH] bcachefs: Fix invalid shift in validate_sb_layout()

Signed-off-by: Gianfranco Trad <gianf.trad@gmail.com>
---
fs/bcachefs/super-io.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/bcachefs/super-io.c b/fs/bcachefs/super-io.c
index ce7410d72089..428172897501 100644
--- a/fs/bcachefs/super-io.c
+++ b/fs/bcachefs/super-io.c
@@ -287,7 +287,7 @@ static int validate_sb_layout(struct bch_sb_layout *layout, struct printbuf *out
return -BCH_ERR_invalid_sb_layout_nr_superblocks;
}

- max_sectors = 1 << layout->sb_max_size_bits;
+ max_sectors = 1 << min(BCH_SB_LAYOUT_SIZE_BITS_MAX, layout->sb_max_size_bits);

prev_offset = le64_to_cpu(layout->sb_offset[0]);

--
2.43.0