]> git.apps.os.sepia.ceph.com Git - xfsprogs-dev.git/commit
xfs_repair: dont leak buffer when discarding directories
authorDarrick J. Wong <djwong@kernel.org>
Wed, 3 May 2023 15:15:15 +0000 (08:15 -0700)
committerCarlos Maiolino <cem@kernel.org>
Wed, 10 May 2023 13:59:58 +0000 (15:59 +0200)
commit5fda1858ae6c1fd85f4cd87b7beff4588b39fdea
treecb5eb058c00deed789880e6508d0cb29ee2528a2
parent7655596449b536f4f1be45bff3c0055eb0955e68
xfs_repair: dont leak buffer when discarding directories

Commit 1f7c7553489c tried to reduce the memory requirements of phase 6
of repair by redesigning longform_dir2_entry_check without the bplist
array.  Unfortunately, none of us noticed that the code that rejects a
dir block with a bad header now leaks the xfs_buf object because we no
longer have a bplist to drop the buffer references.  Any time we hold a
buffer and decide to move on in the dabno loop, we must release the
buffer.

The immediate result of this error is that dir_binval complains about
the recursive lock count of the buffer when we blow out the directory.
However, if the block is reallocated by another thread, repair will
deadlock when it tries to get the buffer and cannot take the buffer
lock.

Found via xfs/113 fuzzing data format directory blocks.  For whatever
reason this happens much more frequently when su=128k,sw=4, but this
applies to everyone equally.

While we're at it, make the relse at the bottom of the function run for
any remaining buffer reference, even if this isn't a block format
directory to avoid leaving a landmine in case we ever add a "goto
fix" inside the loop for a non-block directory.

Fixes: 1f7c7553489 ("repair: don't duplicate names in phase 6")
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Carlos Maiolino <cmaiolino@redhat.com>
Signed-off-by: Carlos Maiolino <cem@kernel.org>
repair/phase6.c