xfs: fix agf/agfl verification on v4 filesystems
authorDave Chinner <dchinner@redhat.com>
Mon, 5 Jun 2023 04:48:15 +0000 (14:48 +1000)
committerDave Chinner <david@fromorbit.com>
Mon, 5 Jun 2023 04:48:15 +0000 (14:48 +1000)
commite0a8de7da35e5b22b44fa1013ccc0716e17b0c14
tree0b95fd1f09e0bcf15430fe1db8e942ffc7ee4a57
parent1e473279f492faf33ed3fbb3ecf8eec9f56b951c
xfs: fix agf/agfl verification on v4 filesystems

When a v4 filesystem has fl_last - fl_first != fl_count, we do not
not detect the corruption and allow the AGF to be used as it if was
fully valid. On V5 filesystems, we reset the AGFL to empty in these
cases and avoid the corruption at a small cost of leaked blocks.

If we don't catch the corruption on V4 filesystems, bad things
happen later when an allocation attempts to trim the free list
and either double-frees stale entries in the AGFl or tries to free
NULLAGBNO entries.

Either way, this is bad. Prevent this from happening by using the
AGFL_NEED_RESET logic for v4 filesysetms, too.

Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Dave Chinner <david@fromorbit.com>
fs/xfs/libxfs/xfs_alloc.c