xfs: fix problems in the attr leaf freemap code [1/3]

Running generic/753 for hours revealed data corruption problems in the
 attr leaf block space management code.  Under certain circumstances,
 freemap entries are left with zero size but a nonzero offset.  If that
 offset happens to be the same offset as the end of the entries array
 during an attr set operation, the leaf entry table expansion will push
 the freemap record offset upwards without checking for overlap with any
 other freemap entries.  If there happened to be a second freemap entry
 overlapping with the newly allocated leaf entry space, then the next
 attr set operation might find that space and overwrite the leaf entry,
 thereby corrupting the leaf block.
 
 Fix this by zeroing the freemap offset any time we set the size to zero.
 If a subsequent attr set operation finds no space in the freemap, it
 will compact the block and regenerate the freemaps.
 
 With a bit of luck, this should all go splendidly.
 
 Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
 -----BEGIN PGP SIGNATURE-----
 
 iHUEABYKAB0WIQQ2qTKExjcn+O1o2YRKO3ySh0YRpgUCaXbguQAKCRBKO3ySh0YR
 pkF1AP4z66Qfdm4+mY6fs7N33FponI2dzp8R7nnljENif1yq0wEAqH63iSpDplhR
 ojPVgBKTQR6atxFJVl/AF9YtFPnXHwc=
 =BeEI
 -----END PGP SIGNATURE-----

Merge tag 'attr-leaf-freemap-fixes-7.0_2026-01-25' of https://git.kernel.org/pub/scm/linux/kernel/git/djwong/xfs-linux into xfs-7.0-merge

xfs: fix problems in the attr leaf freemap code [1/3]

Running generic/753 for hours revealed data corruption problems in the
attr leaf block space management code.  Under certain circumstances,
freemap entries are left with zero size but a nonzero offset.  If that
offset happens to be the same offset as the end of the entries array
during an attr set operation, the leaf entry table expansion will push
the freemap record offset upwards without checking for overlap with any
other freemap entries.  If there happened to be a second freemap entry
overlapping with the newly allocated leaf entry space, then the next
attr set operation might find that space and overwrite the leaf entry,
thereby corrupting the leaf block.

Fix this by zeroing the freemap offset any time we set the size to zero.
If a subsequent attr set operation finds no space in the freemap, it
will compact the block and regenerate the freemaps.

With a bit of luck, this should all go splendidly.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
Signed-off-by: Carlos Maiolino <cem@kernel.org>
This commit is contained in:
Carlos Maiolino 2026-01-28 10:15:07 +01:00
commit 2744d7adb2
3 changed files with 155 additions and 63 deletions