diff mbox series

[38/58] xfs_repair: reject regular directory dirents that point to metadata fieles

Message ID 170405010454.1809361.7205361258702682954.stgit@frogsfrogsfrogs (mailing list archive)
State Deferred, archived
Headers show
Series [01/58] xfs: don't use the incore struct xfs_sb for offsets into struct xfs_dsb | expand

Commit Message

Darrick J. Wong Dec. 31, 2023, 11:39 p.m. UTC
From: Darrick J. Wong <djwong@kernel.org>

If a directory that's in the regular (non-metadata) directory tree has
an entry that points to a metadata file, trash the dirent.  Files are
not allowed to cross between the two trees.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
---
 repair/dir2.c |    8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/repair/dir2.c b/repair/dir2.c
index 9f10fde09a1..b4ebcd56d57 100644
--- a/repair/dir2.c
+++ b/repair/dir2.c
@@ -140,6 +140,7 @@  static bool
 is_meta_ino(
 	struct xfs_mount	*mp,
 	xfs_ino_t		dirino,
+	const struct xfs_dinode	*dip,
 	xfs_ino_t		lino,
 	char			**junkreason)
 {
@@ -155,6 +156,9 @@  is_meta_ino(
 		reason = _("group quota");
 	else if (lino == mp->m_sb.sb_pquotino)
 		reason = _("project quota");
+	else if (dip->di_version >= 3 &&
+		 (dip->di_flags2 & cpu_to_be64(XFS_DIFLAG2_METADIR)))
+		reason = _("metadata directory file");
 
 	if (reason)
 		*junkreason = reason;
@@ -252,7 +256,7 @@  process_sf_dir2(
 		} else if (!libxfs_verify_dir_ino(mp, lino)) {
 			junkit = 1;
 			junkreason = _("invalid");
-		} else if (is_meta_ino(mp, ino, lino, &junkreason)) {
+		} else if (is_meta_ino(mp, ino, dip, lino, &junkreason)) {
 			/*
 			 * Directories that are not in the metadir tree should
 			 * not be linking to metadata files.
@@ -714,7 +718,7 @@  process_dir2_data(
 			 * directory since it's still structurally intact.
 			 */
 			clearreason = _("invalid");
-		} else if (is_meta_ino(mp, ino, ent_ino, &clearreason)) {
+		} else if (is_meta_ino(mp, ino, dip, ent_ino, &clearreason)) {
 			/*
 			 * Directories that are not in the metadir tree should
 			 * not be linking to metadata files.