Skip to contentSkip to conversation

ocfs2: validate dr_fs_generation of dir index root blocks

PATCH Superseded Joseph Qi 2 participants 2 messages Sep 4 – Sep 5 OCFS2

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Joseph Qi

author maintainer
#0 lore raw

PATCH 1/1 ocfs2: validate dr_fs_generation of dir index root blocks

ocfs2_validate_dx_root() does not verify dr_fs_generation against the superblock generation, unlike the extent and xattr block validators which check h_fs_generation and xb_fs_generation respectively. The field is documented as "Must match super block".

Without the check, a stale dir index root block left on the device from a previously formatted filesystem at the same physical block number can pass validation as long as its signature, dr_blkno and checksum match. Its index entries and suballocator information would then be used in the new filesystem context.

Reject dir index root blocks whose dr_fs_generation does not match the mounted filesystem, like the extent and xattr block validators do.

---
 fs/ocfs2/dir.c | 8 ++++++++
 1 file changed, 8 insertions(+)
fs/ocfs2/dir.c +8 -0
index 6bb6aa133f01..329680b46227 100644
@@ -613,6 +613,14 @@ static int ocfs2_validate_dx_root(struct super_block *sb,
 		goto bail;
 	}
 
+	if (le32_to_cpu(dx_root->dr_fs_generation) != OCFS2_SB(sb)->fs_generation) {
+		ret = ocfs2_error(sb,
+				  "Dir Index Root # %llu has an invalid dr_fs_generation of #%u\n",
+				  (unsigned long long)bh->b_blocknr,
+				  le32_to_cpu(dx_root->dr_fs_generation));
+		goto bail;
+	}
+
 	/*
 	 * Dir index root blocks are allocated from a per-slot suballocator,
 	 * so the slot must be in range.  Otherwise removing the index passes
Signature · 1 line
2.39.3
reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · Joseph Qi

ocfs2_validate_dx_root() does not verify dr_fs_generation against the superblock generation, unlike the extent and xattr block validators which check h_fs_generation and xb_fs_generation respectively. The field is documented as "Must match super block".

Without the check, a stale dir index root block left on the device from a previously formatted filesystem at the same physical block number can pass validation as long as its signature, dr_blkno and checksum match. Its index entries and suballocator information would then be used in the new filesystem context.

Quoted 4 lines

Reject dir index root blocks whose dr_fs_generation does not match the mounted filesystem, like the extent and xattr block validators do.

LGTM.

Quoted 26 lines
---
 fs/ocfs2/dir.c | 8 ++++++++
 1 file changed, 8 insertions(+)
fs/ocfs2/dir.c +8 -0
index 6bb6aa133f01..329680b46227 100644
@@ -613,6 +613,14 @@ static int ocfs2_validate_dx_root(struct super_block *sb,
 		goto bail;
 	}
 
+	if (le32_to_cpu(dx_root->dr_fs_generation) != OCFS2_SB(sb)->fs_generation) {
+		ret = ocfs2_error(sb,
+				  "Dir Index Root # %llu has an invalid dr_fs_generation of #%u\n",
+				  (unsigned long long)bh->b_blocknr,
+				  le32_to_cpu(dx_root->dr_fs_generation));
+		goto bail;
+	}
+
 	/*
 	 * Dir index root blocks are allocated from a per-slot suballocator,
 	 * so the slot must be in range.  Otherwise removing the index passes
Signature · 1 line
2.39.3