From 35e259ac82d3a13a56c67e3b380a744ef35b763b Mon Sep 17 00:00:00 2001 From: Christoph Hellwig Date: Sat, 19 Oct 2024 14:23:05 +0200 Subject: [PATCH] xfs: shut the file system down on corrupted used counter If a free is trying to free more blocks than the used counter the file system is clearly corrupted so shut it down. Keep the debug only assert to follow the (good?) old XFS tradition of panicing on corruption for debug builds. Signed-off-by: Christoph Hellwig --- fs/xfs/xfs_zone_alloc.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/fs/xfs/xfs_zone_alloc.c b/fs/xfs/xfs_zone_alloc.c index 75b56cd498f9..27a36a1deb0e 100644 --- a/fs/xfs/xfs_zone_alloc.c +++ b/fs/xfs/xfs_zone_alloc.c @@ -177,7 +177,14 @@ xfs_zone_free_blocks( uint64_t *used = xfs_zone_used_counter(rtg); xfs_assert_ilocked(rtg->rtg_inodes[XFS_RTGI_RMAP], XFS_ILOCK_EXCL); - ASSERT(len <= *used); + if (len > *used) { + xfs_err(mp, +"trying to free more blocks (%lld) than used counter (%lld).", + len, *used); + ASSERT(len <= *used); + xfs_force_shutdown(mp, SHUTDOWN_CORRUPT_INCORE); + return -EFSCORRUPTED; + } trace_xfs_zone_free_blocks(rtg, xfs_rtb_to_rgbno(mp, fsbno), len); -- 2.50.1