Re: [PATCH v2] ufs: bound the cluster summary index in ufs_clusteracct()

From: Christian Brauner

Date: Wed Nov 18 2026 - 08:41:21 EST


On Wed, Nov 18, 2026 at 04:00:00PM +0800, Guikun Yang wrote:
> 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.

Meh. That's just pluggin the immediate hole. Two things:

(1) c_clusteroff comes straight from the cylinder group header as well.
A large enough c_clusteroff passes your check and we still index
past ubh->bh[]. And bailing out after ubh_setbit()/ubh_clrbit()
leaves the bitmap and the summary out of sync.

(2) If c_nclusterblks < start forw goes negative. Then i passes your
check while c_clustersumoff + (back << 2) still writes out of
bounds. With back == 0 and forw == -2 you write at
c_clustersumoff - 4.

Both reported by Sashiko.

Please validate this where it's read instead.