fs_contigsumsize is read from the on-disk superblock into uspi->s_contigsumsize with no validation, and c_clustersumoff is read from each cylinder-group header with no validation. In ufs_clusteracct() the two combine into a derived array index: i = back + forw + 1; if (i > uspi->s_contigsumsize) i = uspi->s_contigsumsize; fs32_add(sb, ubh_get_addr(UCPI_UBH(ucpi), ucpi->c_clustersumoff + (i << 2)), cnt); The clamp itself uses the attacker-controlled value as its bound. ubh_get_addr() expands to ubh->bh[begin >> s_fshift], so a crafted pair indexes bh[UFS_MAXFRAG] past the end of the 136-byte ufs_cg_private_info allocation: UBSAN: array-index-out-of-bounds in fs/ufs/balloc.c:892 index 15 is out of range for type 'buffer_head *[8]' KASAN: slab-out-of-bounds Read of size 8 0 bytes to the right of 136-byte region [ffff...,ffff...) allocated by ufs_load_cylinder Kernel panic - not syncing Reproduced 3/3 with a crafted 44bsd image (clustersumoff = 440, fs_contigsumsize = 0x20000, giving i = 1880 and begin = 7960, so begin >> s_fshift = 15). A negative image differing only in the fs_contigsumsize byte (0x20000 -> 0) writes 4096 bytes cleanly. Both 7.3 and mainline are affected; syzbot has no report for this. This is distinct from the earlier "five unvalidated cylinder-group offsets" report: that fix bounds the offsets against s_cgsize and the reproducer set fs_contigsumsize to 0, disabling cluster accounting. Here all five offsets are in range, cgsize passes the bound added by the fs_cgsize fix, and the overflow comes from the (i << 2) derived index with a large s_contigsumsize. In a valid FFS layout the cluster summary array sits immediately before the cluster bitmap, so c_clustersumoff + 4*(i+1) must fit below c_clusteroff. Check that invariant before the update and skip the accounting otherwise. Reported-by: Guikun Yang --- fs/ufs/balloc.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/fs/ufs/balloc.c b/fs/ufs/balloc.c index 628edfde3..3858699db 100644 --- a/fs/ufs/balloc.c +++ b/fs/ufs/balloc.c @@ -889,6 +889,9 @@ static void ufs_clusteracct(struct super_block * sb, i = back + forw + 1; if (i > uspi->s_contigsumsize) i = uspi->s_contigsumsize; + if (ucpi->c_clusteroff < (i + 1) * sizeof(__fs32) || + ucpi->c_clusteroff - (i + 1) * sizeof(__fs32) < ucpi->c_clustersumoff) + return; fs32_add(sb, (__fs32*)ubh_get_addr(UCPI_UBH(ucpi), ucpi->c_clustersumoff + (i << 2)), cnt); if (back > 0) fs32_sub(sb, (__fs32*)ubh_get_addr(UCPI_UBH(ucpi), ucpi->c_clustersumoff + (back << 2)), cnt); -- 2.53.0.windows.1