xfs: repair inode mode by scanning dirs [v29.3 01/18]

One missing piece of functionality in the inode record repair code is
 figuring out what to do with a file whose mode is so corrupt that we
 cannot tell us the type of the file.  Originally this was done by
 guessing the mode from the ondisk inode contents, but Christoph didn't
 like that because it read from data fork block 0, which could be user
 controlled data.
 
 Therefore, I've replaced all that with a directory scanner that looks
 for any dirents that point to the file with the garbage mode.  If so,
 the ftype in the dirent will tell us exactly what mode to set on the
 file.  Since users cannot directly write to the ftype field of a dirent,
 this should be safe.
 
 This has been running on the djcloud for months with no problems.  Enjoy!
 
 Signed-off-by: Darrick J. Wong <djwong@kernel.org>
 -----BEGIN PGP SIGNATURE-----
 
 iHUEABYKAB0WIQQ2qTKExjcn+O1o2YRKO3ySh0YRpgUCZdlBYAAKCRBKO3ySh0YR
 pvYaAQCdHMP4V94sw+jI46FHgqBAEEuqZUjq8cHwZPrtDzZc5QEA4fsbzR8yXJsw
 imsHjftkRhSEav0LVXhPCbaFfphbUQ0=
 =O1cc
 -----END PGP SIGNATURE-----

Merge tag 'repair-inode-mode-6.9_2024-02-23' of https://git.kernel.org/pub/scm/linux/kernel/git/djwong/xfs-linux into xfs-6.9-mergeC

xfs: repair inode mode by scanning dirs

One missing piece of functionality in the inode record repair code is
figuring out what to do with a file whose mode is so corrupt that we
cannot tell us the type of the file.  Originally this was done by
guessing the mode from the ondisk inode contents, but Christoph didn't
like that because it read from data fork block 0, which could be user
controlled data.

Therefore, I've replaced all that with a directory scanner that looks
for any dirents that point to the file with the garbage mode.  If so,
the ftype in the dirent will tell us exactly what mode to set on the
file.  Since users cannot directly write to the ftype field of a dirent,
this should be safe.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Chandan Babu R <chandanbabu@kernel.org>

* tag 'repair-inode-mode-6.9_2024-02-23' of https://git.kernel.org/pub/scm/linux/kernel/git/djwong/xfs-linux:
  xfs: repair file modes by scanning for a dirent pointing to us
  xfs: create a macro for decoding ftypes in tracepoints
  xfs: create a predicate to determine if two xfs_names are the same
  xfs: create a static name for the dot entry too
  xfs: iscan batching should handle unallocated inodes too
  xfs: cache a bunch of inodes for repair scans
  xfs: stagger the starting AG of scrub iscans to reduce contention
  xfs: allow scrub to hook metadata updates in other writers
  xfs: implement live inode scan for scrub
  xfs: speed up xfs_iwalk_adjust_start a little bit
This commit is contained in:
Chandan Babu R 2024-02-24 09:40:39 +05:30
commit 8e3ef44f9b
15 changed files with 1436 additions and 19 deletions