linux/fs/xfs/libxfs
Brian Foster a27ba2607e xfs: detect agfl count corruption and reset agfl
The struct xfs_agfl v5 header was originally introduced with
unexpected padding that caused the AGFL to operate with one less
slot than intended. The header has since been packed, but the fix
left an incompatibility for users who upgrade from an old kernel
with the unpacked header to a newer kernel with the packed header
while the AGFL happens to wrap around the end. The newer kernel
recognizes one extra slot at the physical end of the AGFL that the
previous kernel did not. The new kernel will eventually attempt to
allocate a block from that slot, which contains invalid data, and
cause a crash.

This condition can be detected by comparing the active range of the
AGFL to the count. While this detects a padding mismatch, it can
also trigger false positives for unrelated flcount corruption. Since
we cannot distinguish a size mismatch due to padding from unrelated
corruption, we can't trust the AGFL enough to simply repopulate the
empty slot.

Instead, avoid unnecessarily complex detection logic and and use a
solution that can handle any form of flcount corruption that slips
through read verifiers: distrust the entire AGFL and reset it to an
empty state. Any valid blocks within the AGFL are intentionally
leaked. This requires xfs_repair to rectify (which was already
necessary based on the state the AGFL was found in). The reset
mitigates the side effect of the padding mismatch problem from a
filesystem crash to a free space accounting inconsistency. The
generic approach also means that this patch can be safely backported
to kernels with or without a packed struct xfs_agfl.

Check the AGF for an invalid freelist count on initial read from
disk. If detected, set a flag on the xfs_perag to indicate that a
reset is required before the AGFL can be used. In the first
transaction that attempts to use a flagged AGFL, reset it to empty,
warn the user about the inconsistency and allow the freelist fixup
code to repopulate the AGFL with new blocks. The xfs_perag flag is
cleared to eliminate the need for repeated checks on each block
allocation operation.

This allows kernels that include the packing fix commit 96f859d52b
("libxfs: pack the agfl header structure so XFS_AGFL_SIZE is correct")
to handle older unpacked AGFL formats without a filesystem crash.

Suggested-by: Dave Chinner <david@fromorbit.com>
Signed-off-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by Dave Chiluk <chiluk+linuxxfs@indeed.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
2018-03-23 18:05:06 -07:00
..
xfs_ag_resv.c xfs: account only rmapbt-used blocks against rmapbt perag res 2018-03-11 20:27:57 -07:00
xfs_ag_resv.h xfs: account only rmapbt-used blocks against rmapbt perag res 2018-03-11 20:27:57 -07:00
xfs_alloc_btree.c Cleanup old XFS_BTREE_* traces 2018-03-11 20:27:55 -07:00
xfs_alloc_btree.h
xfs_alloc.c xfs: detect agfl count corruption and reset agfl 2018-03-23 18:05:06 -07:00
xfs_alloc.h xfs: convert XFS_AGFL_SIZE to a helper function 2018-03-11 20:27:56 -07:00
xfs_attr_leaf.c Split buffer's b_fspriv field 2018-01-29 07:27:22 -08:00
xfs_attr_leaf.h xfs: create structure verifier function for shortform xattrs 2018-01-08 10:54:46 -08:00
xfs_attr_remote.c xfs: create a new buf_ops pointer to verify structure metadata 2018-01-08 10:54:47 -08:00
xfs_attr_remote.h
xfs_attr_sf.h xfs: remove double-underscore integer types 2017-06-19 14:11:33 -07:00
xfs_attr.c xfs: cancel tx on xfs_defer_finish() error during xattr set/remove 2018-01-16 14:53:28 -08:00
xfs_bit.c libxfs: Optimize the loop for xfs_bitmap_empty 2016-01-04 16:10:19 +11:00
xfs_bit.h xfs: remove double-underscore integer types 2017-06-19 14:11:33 -07:00
xfs_bmap_btree.c Cleanup old XFS_BTREE_* traces 2018-03-11 20:27:55 -07:00
xfs_bmap_btree.h xfs: pass struct xfs_bmbt_irec to xfs_bmbt_validate_extent 2017-11-06 11:53:41 -08:00
xfs_bmap.c xfs: don't screw up direct writes when freesp is fragmented 2018-01-29 07:27:24 -08:00
xfs_bmap.h xfs: simplify xfs_reflink_convert_cow 2017-11-06 11:53:40 -08:00
xfs_btree.c Cleanup old XFS_BTREE_* traces 2018-03-11 20:27:55 -07:00
xfs_btree.h Cleanup old XFS_BTREE_* traces 2018-03-11 20:27:55 -07:00
xfs_cksum.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
xfs_da_btree.c Split buffer's b_fspriv field 2018-01-29 07:27:22 -08:00
xfs_da_btree.h xfs: remove double-underscore integer types 2017-06-19 14:11:33 -07:00
xfs_da_format.c xfs: remove double-underscore integer types 2017-06-19 14:11:33 -07:00
xfs_da_format.h xfs: refactor the geometry structure filling function 2018-01-08 10:54:48 -08:00
xfs_defer.c xfs: add the ability to join a held buffer to a defer_ops 2017-12-14 09:17:35 -08:00
xfs_defer.h xfs: add the ability to join a held buffer to a defer_ops 2017-12-14 09:17:35 -08:00
xfs_dir2_block.c Split buffer's b_fspriv field 2018-01-29 07:27:22 -08:00
xfs_dir2_data.c Split buffer's b_fspriv field 2018-01-29 07:27:22 -08:00
xfs_dir2_leaf.c xfs: convert a few more directory asserts to corruption 2018-03-11 20:27:56 -07:00
xfs_dir2_node.c xfs: convert a few more directory asserts to corruption 2018-03-11 20:27:56 -07:00
xfs_dir2_priv.h xfs: refactor short form directory structure verifier function 2018-01-08 10:54:46 -08:00
xfs_dir2_sf.c xfs: directory scrubber must walk through data block to offset 2018-01-17 21:00:46 -08:00
xfs_dir2.c xfs: refactor the geometry structure filling function 2018-01-08 10:54:48 -08:00
xfs_dir2.h xfs: directory scrubber must walk through data block to offset 2018-01-17 21:00:46 -08:00
xfs_dquot_buf.c xfs: standardize quota verification function outputs 2018-01-08 10:54:47 -08:00
xfs_errortag.h xfs: move error injection tags into their own file 2017-11-01 15:03:16 -07:00
xfs_format.h xfs: convert XFS_AGFL_SIZE to a helper function 2018-03-11 20:27:56 -07:00
xfs_fs.h xfs: check sb_agblocks and sb_agblklog when validating superblock 2018-01-17 21:00:47 -08:00
xfs_ialloc_btree.c Cleanup old XFS_BTREE_* traces 2018-03-11 20:27:55 -07:00
xfs_ialloc_btree.h xfs: use per-AG reservations for the finobt 2017-01-25 07:49:35 -08:00
xfs_ialloc.c Split buffer's b_fspriv field 2018-01-29 07:27:22 -08:00
xfs_ialloc.h xfs: add scrub cross-referencing helpers for the inode btrees 2018-01-17 21:00:44 -08:00
xfs_iext_tree.c xfs: move xfs_iext_insert tracepoint to report useful information 2017-12-14 09:20:11 -08:00
xfs_inode_buf.c New in this version: 2018-01-31 10:18:00 -08:00
xfs_inode_buf.h xfs: have buffer verifier functions report failing address 2018-01-08 10:54:46 -08:00
xfs_inode_fork.c xfs: btree format ifork loader should check for zero numrecs 2018-01-17 21:00:46 -08:00
xfs_inode_fork.h xfs: provide a centralized method for verifying inline fork data 2018-01-08 10:54:47 -08:00
xfs_log_format.h xfs: fix type usage 2017-11-16 12:06:45 -08:00
xfs_log_recover.h xfs: remove double-underscore integer types 2017-06-19 14:11:33 -07:00
xfs_log_rlimit.c xfs: trace log reservations at mount time 2018-01-08 10:54:47 -08:00
xfs_quota_defs.h xfs: standardize quota verification function outputs 2018-01-08 10:54:47 -08:00
xfs_refcount_btree.c Cleanup old XFS_BTREE_* traces 2018-03-11 20:27:55 -07:00
xfs_refcount_btree.h xfs: use the actual AG length when reserving blocks 2017-01-03 18:39:33 -08:00
xfs_refcount.c xfs: add scrub cross-referencing helpers for the refcount btrees 2018-01-17 21:00:44 -08:00
xfs_refcount.h xfs: add scrub cross-referencing helpers for the refcount btrees 2018-01-17 21:00:44 -08:00
xfs_rmap_btree.c xfs: account only rmapbt-used blocks against rmapbt perag res 2018-03-11 20:27:57 -07:00
xfs_rmap_btree.h xfs: use the actual AG length when reserving blocks 2017-01-03 18:39:33 -08:00
xfs_rmap.c xfs: add scrub cross-referencing helpers for the rmap btrees 2018-01-17 21:00:44 -08:00
xfs_rmap.h xfs: add scrub cross-referencing helpers for the rmap btrees 2018-01-17 21:00:44 -08:00
xfs_rtbitmap.c xfs: cross-reference the realtime bitmap 2018-01-17 21:00:46 -08:00
xfs_sb.c xfs: fix u32 type usage in sb validation function 2018-01-31 20:39:20 -08:00
xfs_sb.h xfs: refactor the geometry structure filling function 2018-01-08 10:54:48 -08:00
xfs_shared.h xfs: trace log reservations at mount time 2018-01-08 10:54:47 -08:00
xfs_symlink_remote.c Split buffer's b_fspriv field 2018-01-29 07:27:22 -08:00
xfs_trans_resv.c xfs: eliminate duplicate icreate tx reservation functions 2018-01-08 10:41:38 -08:00
xfs_trans_resv.h xfs: increase log reservations for reflink 2016-10-05 16:26:29 -07:00
xfs_trans_space.h xfs: reserve enough blocks to handle btree splits when remapping 2017-05-03 13:21:40 -07:00
xfs_types.h xfs: move xfs_bmbt_irec and xfs_exntst_t to xfs_types.h 2017-11-06 11:53:41 -08:00