Skip to contentSkip to conversation

e2fsck: expand checking of EA inode

PATCH Applied Jan Kara 2 participants 5 messages May 6, 2024 – May 9, 2024

lore
Share & tools
lore

Jan Kara

author
#0 lore raw

cover e2fsck: expand checking of EA inode

Hello,

customer has reported that his filesystem was reporting errors from ext4_iget() about inode with EA_INODE_FL but e2fsck was considering the filesystem as clean. Indeed the EA inode checking in e2fsck is weak and lets through several cases of corruption related to EA inodes. This series adds more strict checking of EA inodes and adds e2fsck tests for them.

Honza

author
#1 lore raw

PATCH 1/3 e2fsck: add more checks for ea inode consistency

Currently checking of EA inodes was rather weak. Add several more consistency checks.

1) Check that EA inode is a regular file.
2) Check that EA_INODE feature is set if the filesystem has EA inodes.
3) Make sure that no EA inode is referenced from directory hierarchy.

---
 e2fsck/e2fsck.h  |  6 ++++
 e2fsck/pass1.c   | 84 +++++++++++++++++++++++++++++++++++++++++-------
 e2fsck/pass2.c   | 15 +++++++++
 e2fsck/pass4.c   | 53 +++++++++++++++++++-----------
 e2fsck/problem.c | 18 +++++++++++
 e2fsck/problem.h | 12 +++++++
 6 files changed, 158 insertions(+), 30 deletions(-)
e2fsck/e2fsck.h +6 -0
index 55738fdc1d19..ae1273dc00af 100644
@@ -533,6 +533,12 @@ extern struct dx_dir_info *e2fsck_dx_dir_info_iter(e2fsck_t ctx,
 typedef __u64 ea_key_t;
 typedef __u64 ea_value_t;
 
+/*
+ * Special refcount value we use for inodes which have EA_INODE flag set but we
+ * do not yet know about any references.
+ */
+#define EA_INODE_NO_REFS (~(ea_value_t)0)
+
 extern errcode_t ea_refcount_create(size_t size, ext2_refcount_t *ret);
 extern void ea_refcount_free(ext2_refcount_t refcount);
 extern errcode_t ea_refcount_fetch(ext2_refcount_t refcount, ea_key_t ea_key,
e2fsck/pass1.c +72 -12

124 lines not on this page · raw message

e2fsck/pass2.c +15 -0
index 08ab40fa8ba1..036c0022d38a 100644
@@ -1501,6 +1501,21 @@ skip_checksum:
 			problem = PR_2_NULL_NAME;
 		}
 
+		/*
+		 * Check if inode was tracked as EA inode and has actual
+		 * references from xattrs. In that case dir entry is likely
+		 * bogus and we want to clear it. The case of EA inode without
+		 * references from xattrs will be handled in pass 4.
+		 */
+		if (!problem && ctx->ea_inode_refs) {
+			ea_value_t refs;
+
+			ea_refcount_fetch(ctx->ea_inode_refs, dirent->inode,
+					  &refs);
+			if (refs && refs != EA_INODE_NO_REFS)
+				problem = PR_2_EA_INODE_DIR_LINK;
+		}
+
 		if (problem) {
 			if (fix_problem(ctx, problem, &cd->pctx)) {
 				dirent->inode = 0;
e2fsck/pass4.c +35 -18

86 lines not on this page · raw message

e2fsck/problem.c +18 -0
index 207ebbb34ec8..e433281fab4b 100644
@@ -1309,6 +1309,16 @@ static struct e2fsck_problem problem_table[] = {
 	  N_("Orphan file @i %i is not in use, but contains data.  "),
 	  PROMPT_CLEAR, PR_PREEN_OK },
 
+	/* EA_INODE flag set on a non-regular file */
+	{ PR_1_EA_INODE_NONREG,
+	  N_("@i %i has the ea_inode flag set but is not a regular file.  "),
+	  PROMPT_CLEAR_FLAG, 0, 0, 0, 0 },
+
+	/* EA_INODE present but the file system is missing the ea_inode feature */
+	{ PR_1_EA_INODE_FEATURE,
+	  N_("@i %i references EA inode but @S is missing EA_INODE feature\n"),
+	  PROMPT_FIX, PR_PREEN_OK, 0, 0, 0 },
+
 	/* Pass 1b errors */
 
 	/* Pass 1B: Rescan for duplicate/bad blocks */
@@ -1860,6 +1870,10 @@ static struct e2fsck_problem problem_table[] = {
 	   N_("Duplicate filename @E found.  "),
 	   PROMPT_CLEAR, 0, 0, 0, 0 },
 
+	/* Directory filename is null */
+	{ PR_2_EA_INODE_DIR_LINK,
+	  N_("@E references EA @i %Di.\n"),
+	  PROMPT_CLEAR, 0, 0, 0, 0 },
 
 	/* Pass 3 errors */
 
@@ -2102,6 +2116,10 @@ static struct e2fsck_problem problem_table[] = {
 	  N_("@d @i %i ref count set to overflow but could be exact value %N.  "),
 	  PROMPT_FIX, PR_PREEN_OK, 0, 0, 0 },
 
+	{ PR_4_EA_INODE_SPURIOUS_FLAG,
+	  N_("Regular @f @i %i has EA_INODE flag set. "),
+	  PROMPT_CLEAR, PR_PREEN_OK, 0, 0, 0 },
+
 	/* Pass 5 errors */
 
 	/* Pass 5: Checking group summary information */
e2fsck/problem.h +12 -0
index b47b0c630c67..ef15b8c84358 100644
@@ -734,6 +734,12 @@ struct problem_context {
 /* Orphan file inode is not in use, but contains data */
 #define PR_1_ORPHAN_FILE_NOT_CLEAR		0x010090
 
+/* Inode has EA_INODE_FL set but is not a regular file */
+#define PR_1_EA_INODE_NONREG			0x010091
+
+/* Inode references EA inode but ea_inode feature is not enabled */
+#define PR_1_EA_INODE_FEATURE			0x010092
+
 /*
  * Pass 1b errors
  */
@@ -1061,6 +1067,9 @@ struct problem_context {
 /* Non-unique filename found, but can't rename */
 #define PR_2_NON_UNIQUE_FILE_NO_RENAME	0x020054
 
+/* EA inode referenced from directory */
+#define PR_2_EA_INODE_DIR_LINK 0x020055
+
 /*
  * Pass 3 errors
  */
@@ -1203,6 +1212,9 @@ struct problem_context {
 /* Directory ref count set to overflow but it doesn't have to be */
 #define PR_4_DIR_OVERFLOW_REF_COUNT	0x040007
 
+/* EA_INODE_FL set on normal file linked from directory hierarchy */
+#define PR_4_EA_INODE_SPURIOUS_FLAG	0x040008
+
 /*
  * Pass 5 errors
  */
Signature · 1 line
2.35.3
author
#2 lore raw

PATCH 2/3 e2fsck: add tests for EA inodes

In reply to Jan Kara

Add tests exercising EA inodes and testing various types of corruption.

---
 tests/f_ea_inode_dir_ref/expect.1           |  12 ++++++++++
 tests/f_ea_inode_dir_ref/expect.2           |   7 ++++++
 tests/f_ea_inode_dir_ref/image.gz           | Bin 0 -> 1822 bytes
 tests/f_ea_inode_dir_ref/name               |   1 +
 tests/f_ea_inode_disconnected/expect.1      |  23 ++++++++++++++++++++
 tests/f_ea_inode_disconnected/expect.2      |   7 ++++++
 tests/f_ea_inode_disconnected/image         | Bin 0 -> 1048576 bytes
 tests/f_ea_inode_disconnected/image.gz      | Bin 0 -> 1779 bytes
 tests/f_ea_inode_disconnected/name          |   1 +
 tests/f_ea_inode_no_feature/expect.1        |  12 ++++++++++
 tests/f_ea_inode_no_feature/expect.2        |   7 ++++++
 tests/f_ea_inode_no_feature/image.gz        | Bin 0 -> 1817 bytes
 tests/f_ea_inode_no_feature/name            |   1 +
 tests/f_ea_inode_spurious_flag_dir/expect.1 |  11 ++++++++++
 tests/f_ea_inode_spurious_flag_dir/expect.2 |   7 ++++++
 tests/f_ea_inode_spurious_flag_dir/image    | Bin 0 -> 1048576 bytes
 tests/f_ea_inode_spurious_flag_dir/image.gz | Bin 0 -> 1598 bytes
 tests/f_ea_inode_spurious_flag_dir/name     |   1 +
 18 files changed, 90 insertions(+)
 create mode 100644 tests/f_ea_inode_dir_ref/expect.1
 create mode 100644 tests/f_ea_inode_dir_ref/expect.2
 create mode 100644 tests/f_ea_inode_dir_ref/image.gz
 create mode 100644 tests/f_ea_inode_dir_ref/name
 create mode 100644 tests/f_ea_inode_disconnected/expect.1
 create mode 100644 tests/f_ea_inode_disconnected/expect.2
 create mode 100644 tests/f_ea_inode_disconnected/image
 create mode 100644 tests/f_ea_inode_disconnected/image.gz
 create mode 100644 tests/f_ea_inode_disconnected/name
 create mode 100644 tests/f_ea_inode_no_feature/expect.1
 create mode 100644 tests/f_ea_inode_no_feature/expect.2
 create mode 100644 tests/f_ea_inode_no_feature/image.gz
 create mode 100644 tests/f_ea_inode_no_feature/name
 create mode 100644 tests/f_ea_inode_spurious_flag_dir/expect.1
 create mode 100644 tests/f_ea_inode_spurious_flag_dir/expect.2
 create mode 100644 tests/f_ea_inode_spurious_flag_dir/image
 create mode 100644 tests/f_ea_inode_spurious_flag_dir/image.gz
 create mode 100644 tests/f_ea_inode_spurious_flag_dir/name
tests/f_ea_inode_dir_ref/expect.1 new file +12 -0
new file mode 100644
index 000000000000..fa6a872b8bf7
@@ -0,0 +1,12 @@
+Pass 1: Checking inodes, blocks, and sizes
+Pass 2: Checking directory structure
+Entry 'xlink' in / (2) references EA inode 13.
+Clear? yes
+
+Pass 3: Checking directory connectivity
+Pass 4: Checking reference counts
+Pass 5: Checking group summary information
+
+test_filesys: ***** FILE SYSTEM WAS MODIFIED *****
+test_filesys: 13/128 files (0.0% non-contiguous), 63/1024 blocks
+Exit status is 1
tests/f_ea_inode_dir_ref/expect.2 new file +7 -0
new file mode 100644
index 000000000000..24d059a300a9
@@ -0,0 +1,7 @@
+Pass 1: Checking inodes, blocks, and sizes
+Pass 2: Checking directory structure
+Pass 3: Checking directory connectivity
+Pass 4: Checking reference counts
+Pass 5: Checking group summary information
+test_filesys: 13/128 files (0.0% non-contiguous), 63/1024 blocks
+Exit status is 0
tests/f_ea_inode_dir_ref/image.gz new file binary +0 -0
new file mode 100644
index 0000000000000000000000000000000000000000..483cc725ee29f2ba26c3cff2571741d1e0c0da49
GIT binary patch
tests/f_ea_inode_dir_ref/name new file +1 -0
new file mode 100644
index 000000000000..e43cd69502f8
@@ -0,0 +1 @@
+true ea inode referenced from a directory
tests/f_ea_inode_disconnected/expect.1 new file +23 -0
new file mode 100644
index 000000000000..afc77aea6d11
@@ -0,0 +1,23 @@
+Pass 1: Checking inodes, blocks, and sizes
+Pass 2: Checking directory structure
+Pass 3: Checking directory connectivity
+Pass 4: Checking reference counts
+Unattached inode 13
+Connect to /lost+found? yes
+
+Inode 13 ref count is 2, should be 1.  Fix? yes
+
+Pass 5: Checking group summary information
+Inode bitmap differences:  -12
+Fix? yes
+
+Free inodes count wrong for group #0 (115, counted=116).
+Fix? yes
+
+Free inodes count wrong (115, counted=116).
+Fix? yes
+
+
+test_filesys: ***** FILE SYSTEM WAS MODIFIED *****
+test_filesys: 12/128 files (0.0% non-contiguous), 63/1024 blocks
+Exit status is 1
tests/f_ea_inode_disconnected/expect.2 new file +7 -0
new file mode 100644
index 000000000000..a67f9445048c
@@ -0,0 +1,7 @@
+Pass 1: Checking inodes, blocks, and sizes
+Pass 2: Checking directory structure
+Pass 3: Checking directory connectivity
+Pass 4: Checking reference counts
+Pass 5: Checking group summary information
+test_filesys: 12/128 files (0.0% non-contiguous), 63/1024 blocks
+Exit status is 0
tests/f_ea_inode_disconnected/image new file binary +0 -0
new file mode 100644
index 0000000000000000000000000000000000000000..f24547c26f63603cdf8918d3b42d518d8e31504a
GIT binary patch
tests/f_ea_inode_disconnected/image.gz new file binary +0 -0
new file mode 100644
index 0000000000000000000000000000000000000000..f440f2052f48dc0489c8d209fb050d96665facff
GIT binary patch
tests/f_ea_inode_disconnected/name new file +1 -0
new file mode 100644
index 000000000000..ce04192e8777
@@ -0,0 +1 @@
+ea inode that is not connected anywhere
tests/f_ea_inode_no_feature/expect.1 new file +12 -0
new file mode 100644
index 000000000000..f6a232bfc8f3
@@ -0,0 +1,12 @@
+Pass 1: Checking inodes, blocks, and sizes
+Inode 12 references EA inode but superblock is missing EA_INODE feature
+Fix? yes
+
+Pass 2: Checking directory structure
+Pass 3: Checking directory connectivity
+Pass 4: Checking reference counts
+Pass 5: Checking group summary information
+
+test_filesys: ***** FILE SYSTEM WAS MODIFIED *****
+test_filesys: 13/128 files (0.0% non-contiguous), 63/1024 blocks
+Exit status is 1
tests/f_ea_inode_no_feature/expect.2 new file +7 -0
new file mode 100644
index 000000000000..24d059a300a9
@@ -0,0 +1,7 @@
+Pass 1: Checking inodes, blocks, and sizes
+Pass 2: Checking directory structure
+Pass 3: Checking directory connectivity
+Pass 4: Checking reference counts
+Pass 5: Checking group summary information
+test_filesys: 13/128 files (0.0% non-contiguous), 63/1024 blocks
+Exit status is 0
tests/f_ea_inode_no_feature/image.gz new file binary +0 -0
new file mode 100644
index 0000000000000000000000000000000000000000..596d69a1c990ee5b79c7e2b291904fe5a5aab4b3
GIT binary patch
tests/f_ea_inode_no_feature/name new file +1 -0
new file mode 100644
index 000000000000..b357afb47c6b
@@ -0,0 +1 @@
+inode with ea inode but EA_INODE feature is not set
tests/f_ea_inode_spurious_flag_dir/expect.1 new file +11 -0
new file mode 100644
index 000000000000..19999ab79306
@@ -0,0 +1,11 @@
+Pass 1: Checking inodes, blocks, and sizes
+Inode 2 has the ea_inode flag set but is not a regular file.  Clear flag? yes
+
+Pass 2: Checking directory structure
+Pass 3: Checking directory connectivity
+Pass 4: Checking reference counts
+Pass 5: Checking group summary information
+
+test_filesys: ***** FILE SYSTEM WAS MODIFIED *****
+test_filesys: 11/128 files (0.0% non-contiguous), 58/1024 blocks
+Exit status is 1
tests/f_ea_inode_spurious_flag_dir/expect.2 new file +7 -0
new file mode 100644
index 000000000000..a35477094496
@@ -0,0 +1,7 @@
+Pass 1: Checking inodes, blocks, and sizes
+Pass 2: Checking directory structure
+Pass 3: Checking directory connectivity
+Pass 4: Checking reference counts
+Pass 5: Checking group summary information
+test_filesys: 11/128 files (0.0% non-contiguous), 58/1024 blocks
+Exit status is 0
tests/f_ea_inode_spurious_flag_dir/image new file binary +0 -0
new file mode 100644
index 0000000000000000000000000000000000000000..f323b6131cec7d37d5864ef02ea0f24de090a8fe
GIT binary patch
tests/f_ea_inode_spurious_flag_dir/image.gz new file binary +0 -0
new file mode 100644
index 0000000000000000000000000000000000000000..af19132ce100fc006c8b83832683dbf2bcab6b53
GIT binary patch
tests/f_ea_inode_spurious_flag_dir/name new file +1 -0
new file mode 100644
index 000000000000..8ae52ccf02f8
@@ -0,0 +1 @@
+ea inode flag set on a directory
Signature · 1 line
2.35.3
author
#3 lore raw

PATCH 3/3 e2fsck: fix golden output of several tests

In reply to Jan Kara

Some old tests of EA inodes were not in fact completely fixing the filesystem (like they were leaving directories with EA_INODE_FL set or EA inodes referenced from directory hierarchy). New e2fsck checks fix these so golden output changes. Update it.

---
 tests/f_bad_disconnected_inode/expect.1 | 8 ++++++++
 tests/f_bad_fname/expect.1              | 2 ++
 tests/f_ea_inode_self_ref/expect.1      | 2 ++
 3 files changed, 12 insertions(+)
tests/f_bad_disconnected_inode/expect.1 +8 -0
index d1479cef2880..39c6958cfa8d 100644
@@ -1,11 +1,17 @@
 Pass 1: Checking inodes, blocks, and sizes
+Inode 1 has the ea_inode flag set but is not a regular file.  Clear flag? yes
+
 Inode 1 has EXTENTS_FL flag set on filesystem without extents support.
 Clear? yes
 
 Inode 9 has the casefold flag set but is not a directory.  Clear flag? yes
 
+Inode 10 has the ea_inode flag set but is not a regular file.  Clear flag? yes
+
 Inode 14 has the casefold flag set but is not a directory.  Clear flag? yes
 
+Inode 14 has the ea_inode flag set but is not a regular file.  Clear flag? yes
+
 Inode 14 has INLINE_DATA_FL flag on filesystem without inline data support.
 Clear? yes
 
@@ -14,6 +20,8 @@ Clear? yes
 
 Inode 16 has the casefold flag set but is not a directory.  Clear flag? yes
 
+Inode 16 has the ea_inode flag set but is not a regular file.  Clear flag? yes
+
 Inode 16 has INLINE_DATA_FL flag on filesystem without inline data support.
 Clear? yes
 
tests/f_bad_fname/expect.1 +2 -0
index 66f87df2b810..60f64f67d462 100644
@@ -1,4 +1,6 @@
 Pass 1: Checking inodes, blocks, and sizes
+Inode 12 has the ea_inode flag set but is not a regular file.  Clear flag? yes
+
 Pass 2: Checking directory structure
 Entry 'AM-^?' in /ci_dir (12) has illegal UTF-8 characters in its name.
 Fix? yes
tests/f_ea_inode_self_ref/expect.1 +2 -0
index f94c04d966e5..35bea1417405 100644
@@ -7,6 +7,8 @@ Clear? yes
 Pass 2: Checking directory structure
 Pass 3: Checking directory connectivity
 Pass 4: Checking reference counts
+Regular filesystem inode 16 has EA_INODE flag set. Clear? yes
+
 Pass 5: Checking group summary information
 Block bitmap differences:  -20
 Fix? yes
Signature · 1 line
2.35.3
#4 lore raw
In reply to Jan Kara
Quoted 9 lines · Jan Kara

customer has reported that his filesystem was reporting errors from ext4_iget() about inode with EA_INODE_FL but e2fsck was considering the filesystem as clean. Indeed the EA inode checking in e2fsck is weak and lets through several cases of corruption related to EA inodes. This series adds more strict checking of EA inodes and adds e2fsck tests for them.

Honza

[...]

Applied, thanks!

[1/3] e2fsck: add more checks for ea inode consistency

      commit: 849a9e6e133a903db7b005854ec58b35dc947150
[2/3] e2fsck: add tests for EA inodes
      commit: eb01b6e22a44a26668c9f8645ca1889d67a643c1
[3/3] e2fsck: fix golden output of several tests
      commit: 7b2e837bf0eacb5c12396e994b4c7979f576019a

Best regards,

Signature · 1 line
Theodore Ts'o <[email protected]>