Skip to content

Commit 2045fc4

Browse files
t-gianKent Overstreet
authored andcommitted
bcachefs: Fix invalid shift in validate_sb_layout()
Add check on layout->sb_max_size_bits against BCH_SB_LAYOUT_SIZE_BITS_MAX to prevent UBSAN shift-out-of-bounds in validate_sb_layout(). Reported-by: [email protected] Closes: https://syzkaller.appspot.com/bug?extid=089fad5a3a5e77825426 Fixes: 03ef80b ("bcachefs: Ignore unknown mount options") Tested-by: [email protected] Signed-off-by: Gianfranco Trad <[email protected]> Signed-off-by: Kent Overstreet <[email protected]>
1 parent a069f01 commit 2045fc4

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

fs/bcachefs/errcode.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@
222222
x(BCH_ERR_invalid_sb_layout, invalid_sb_layout_type) \
223223
x(BCH_ERR_invalid_sb_layout, invalid_sb_layout_nr_superblocks) \
224224
x(BCH_ERR_invalid_sb_layout, invalid_sb_layout_superblocks_overlap) \
225+
x(BCH_ERR_invalid_sb_layout, invalid_sb_layout_sb_max_size_bits) \
225226
x(BCH_ERR_invalid_sb, invalid_sb_members_missing) \
226227
x(BCH_ERR_invalid_sb, invalid_sb_members) \
227228
x(BCH_ERR_invalid_sb, invalid_sb_disk_groups) \

fs/bcachefs/super-io.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,11 @@ static int validate_sb_layout(struct bch_sb_layout *layout, struct printbuf *out
287287
return -BCH_ERR_invalid_sb_layout_nr_superblocks;
288288
}
289289

290+
if (layout->sb_max_size_bits > BCH_SB_LAYOUT_SIZE_BITS_MAX) {
291+
prt_printf(out, "Invalid superblock layout: max_size_bits too high");
292+
return -BCH_ERR_invalid_sb_layout_sb_max_size_bits;
293+
}
294+
290295
max_sectors = 1 << layout->sb_max_size_bits;
291296

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

0 commit comments

Comments
 (0)