WSL2-Linux-Kernel/fs/xfs/libxfs
Dave Chinner 160ae76fa1 libxfs: directory node splitting does not have an extra block
xfsprogs source commit 4280e59dcbc4cd8e01585efe788a68eb378048e8

xfs_da3_split() has to handle all three versions of the
directory/attribute btree structure. The attr tree is v1, the dir
tre is v2 or v3. The main difference between the v1 and v2/3 trees
is the way tree nodes are split - in the v1 tree we can require a
double split to occur because the object to be inserted may be
larger than the space made by splitting a leaf. In this case we need
to do a double split - one to split the full leaf, then another to
allocate an empty leaf block in the correct location for the new
entry.  This does not happen with dir (v2/v3) formats as the objects
being inserted are always guaranteed to fit into the new space in
the split blocks.

Indeed, for directories they *may* be an extra block on this buffer
pointer. However, it's guaranteed not to be a leaf block (i.e. a
directory data block) - the directory code only ever places hash
index or free space blocks in this pointer (as a cursor of
sorts), and so to use it as a directory data block will immediately
corrupt the directory.

The problem is that the code assumes that there may be extra blocks
that we need to link into the tree once we've split the root, but
this is not true for either dir or attr trees, because the extra
attr block is always consumed by the last node split before we split
the root. Hence the linking in an extra block is always wrong at the
root split level, and this manifests itself in repair as a directory
corruption in a repaired directory, leaving the directory rebuild
incomplete.

This is a dir v2 zero-day bug - it was in the initial dir v2 commit
that was made back in February 1998.

Fix this by ensuring the linking of the blocks after the root split
never tries to make use of the extra blocks that may be held in the
cursor. They are held there for other purposes and should never be
touched by the root splitting code.

Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Dave Chinner <david@fromorbit.com>
2016-07-22 09:51:05 +10:00
..
xfs_alloc.c libxfs: make xfs_alloc_fix_freelist non-static 2016-01-04 16:10:42 +11:00
xfs_alloc.h libxfs: make xfs_alloc_fix_freelist non-static 2016-01-04 16:10:42 +11:00
xfs_alloc_btree.c xfs: move buffer invalidation to xfs_btree_free_block 2016-02-08 14:58:07 +11:00
xfs_alloc_btree.h
xfs_attr.c xfs: better xfs_trans_alloc interface 2016-04-06 09:19:55 +10:00
xfs_attr_leaf.c xfs: print name of verifier if it fails 2016-01-04 16:10:19 +11:00
xfs_attr_leaf.h xfs: xfs_attr_inactive leaves inconsistent attr fork state behind 2015-05-29 07:40:08 +10:00
xfs_attr_remote.c xfs: eliminate committed arg from xfs_bmap_finish 2016-01-11 11:34:01 +11:00
xfs_attr_remote.h
xfs_attr_sf.h xfs: move struct xfs_attr_shortform to xfs_da_format.h 2016-02-08 15:00:01 +11:00
xfs_bit.c libxfs: Optimize the loop for xfs_bitmap_empty 2016-01-04 16:10:19 +11:00
xfs_bit.h
xfs_bmap.c xfs: update for 4.7-rc1 2016-05-26 10:13:40 -07:00
xfs_bmap.h xfs: eliminate committed arg from xfs_bmap_finish 2016-01-11 11:34:01 +11:00
xfs_bmap_btree.c Merge branch 'xfs-misc-fixes-4.6-2' into for-next 2016-03-07 09:34:54 +11:00
xfs_bmap_btree.h
xfs_btree.c xfs: move buffer invalidation to xfs_btree_free_block 2016-02-08 14:58:07 +11:00
xfs_btree.h libxfs: refactor short btree block verification 2016-01-04 16:13:21 +11:00
xfs_cksum.h
xfs_da_btree.c libxfs: directory node splitting does not have an extra block 2016-07-22 09:51:05 +10:00
xfs_da_btree.h
xfs_da_format.c xfs: move most of xfs_sb.h to xfs_format.h 2014-11-28 14:27:09 +11:00
xfs_da_format.h xfs: move struct xfs_attr_shortform to xfs_da_format.h 2016-02-08 15:00:01 +11:00
xfs_dir2.c xfs: mode di_mode to vfs inode 2016-02-09 16:54:58 +11:00
xfs_dir2.h xfs: move type conversion functions to xfs_dir.h 2014-12-04 09:43:17 +11:00
xfs_dir2_block.c xfs: print name of verifier if it fails 2016-01-04 16:10:19 +11:00
xfs_dir2_data.c xfs: print name of verifier if it fails 2016-01-04 16:10:19 +11:00
xfs_dir2_leaf.c xfs: print name of verifier if it fails 2016-01-04 16:10:19 +11:00
xfs_dir2_node.c xfs: always set rvalp in xfs_dir2_node_trim_free 2016-03-15 11:44:18 +11:00
xfs_dir2_priv.h xfs: move type conversion functions to xfs_dir.h 2014-12-04 09:43:17 +11:00
xfs_dir2_sf.c xfs: factor out a helper to initialize a local format inode fork 2016-04-06 07:41:43 +10:00
xfs_dquot_buf.c xfs: handle dquot buffer readahead in log recovery correctly 2016-01-12 07:04:01 +11:00
xfs_format.h Merge branch 'xfs-setxattr-promotion' into for-next 2016-01-19 08:16:08 +11:00
xfs_fs.h xfs: use FS_XFLAG definitions directly 2016-01-04 16:44:15 +11:00
xfs_ialloc.c xfs: fix computation of inode btree maxlevels 2016-03-07 08:39:56 +11:00
xfs_ialloc.h Merge branch 'xfs-misc-fixes-for-4.2-3' into for-next 2015-06-23 08:49:01 +10:00
xfs_ialloc_btree.c xfs: move buffer invalidation to xfs_btree_free_block 2016-02-08 14:58:07 +11:00
xfs_ialloc_btree.h xfs: allocate sparse inode chunks on full chunk allocation failure 2015-05-29 09:18:32 +10:00
xfs_inode_buf.c xfs: mode di_mode to vfs inode 2016-02-09 16:54:58 +11:00
xfs_inode_buf.h xfs: mode di_mode to vfs inode 2016-02-09 16:54:58 +11:00
xfs_inode_fork.c Merge branch 'xfs-4.7-inode-reclaim' into for-next 2016-05-20 10:34:00 +10:00
xfs_inode_fork.h xfs: factor out a helper to initialize a local format inode fork 2016-04-06 07:41:43 +10:00
xfs_log_format.h xfs: remove transaction types 2016-04-06 09:20:36 +10:00
xfs_log_recover.h xfs: support a crc verification only log record pass 2016-01-04 15:55:10 +11:00
xfs_log_rlimit.c xfs: move most of xfs_sb.h to xfs_format.h 2014-11-28 14:27:09 +11:00
xfs_quota_defs.h xfs: wire up Q_XGETNEXTQUOTA / get_nextdqblk 2016-02-08 11:27:38 +11:00
xfs_rtbitmap.c Merge branch 'xfs-gut-icdinode-4.6' into for-next 2016-03-07 09:30:32 +11:00
xfs_sb.c xfs: better xfs_trans_alloc interface 2016-04-06 09:19:55 +10:00
xfs_sb.h xfs: remove unused function definitions 2016-02-08 14:58:07 +11:00
xfs_shared.h xfs: remove transaction types 2016-04-06 09:20:36 +10:00
xfs_symlink_remote.c xfs: print name of verifier if it fails 2016-01-04 16:10:19 +11:00
xfs_trans_resv.c xfs: consolidate superblock logging functions 2015-01-22 09:10:31 +11:00
xfs_trans_resv.h xfs: clean up XFS_MIN_FREELIST macros 2015-06-22 10:13:30 +10:00
xfs_trans_space.h xfs: clean up XFS_MIN_FREELIST macros 2015-06-22 10:13:30 +10:00
xfs_types.h xfs: move xfs_types.h to libxfs 2015-01-09 10:46:31 +11:00