• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1From b0cd09e5b65373fc9f89048958c093bb1e6a1ecb Mon Sep 17 00:00:00 2001
2From: Eric Biggers <ebiggers@google.com>
3Date: Wed, 2 Nov 2022 15:05:51 -0700
4Subject: e2fsck: don't allow journal inode to have encrypt flag
5
6Since the kernel is being fixed to consider journal inodes with the
7'encrypt' flag set to be invalid, also update e2fsck accordingly.
8
9Signed-off-by: Eric Biggers <ebiggers@google.com>
10Reviewed-by: Andreas Dilger <adilger@dilger.ca>
11Signed-off-by: Theodore Ts'o <tytso@mit.edu>
12---
13 e2fsck/journal.c                   |  3 ++-
14 tests/f_badjour_encrypted/expect.1 | 30 ++++++++++++++++++++++++++++++
15 tests/f_badjour_encrypted/expect.2 |  7 +++++++
16 tests/f_badjour_encrypted/name     |  1 +
17 tests/f_badjour_encrypted/script   | 11 +++++++++++
18 5 files changed, 51 insertions(+), 1 deletion(-)
19 create mode 100644 tests/f_badjour_encrypted/expect.1
20 create mode 100644 tests/f_badjour_encrypted/expect.2
21 create mode 100644 tests/f_badjour_encrypted/name
22 create mode 100644 tests/f_badjour_encrypted/script
23
24diff --git a/e2fsck/journal.c b/e2fsck/journal.c
25index 1646b479..1bfabb02 100644
26--- a/e2fsck/journal.c
27+++ b/e2fsck/journal.c
28@@ -1039,7 +1039,8 @@ static errcode_t e2fsck_get_journal(e2fsck_t ctx, journal_t **ret_journal)
29 			tried_backup_jnl++;
30 		}
31 		if (!j_inode->i_ext2.i_links_count ||
32-		    !LINUX_S_ISREG(j_inode->i_ext2.i_mode)) {
33+		    !LINUX_S_ISREG(j_inode->i_ext2.i_mode) ||
34+		    (j_inode->i_ext2.i_flags & EXT4_ENCRYPT_FL)) {
35 			retval = EXT2_ET_NO_JOURNAL;
36 			goto try_backup_journal;
37 		}
38diff --git a/tests/f_badjour_encrypted/expect.1 b/tests/f_badjour_encrypted/expect.1
39new file mode 100644
40index 00000000..0b13b9eb
41--- /dev/null
42+++ b/tests/f_badjour_encrypted/expect.1
43@@ -0,0 +1,30 @@
44+Superblock has an invalid journal (inode 8).
45+Clear? yes
46+
47+*** journal has been deleted ***
48+
49+Pass 1: Checking inodes, blocks, and sizes
50+Journal inode is not in use, but contains data.  Clear? yes
51+
52+Pass 2: Checking directory structure
53+Pass 3: Checking directory connectivity
54+Pass 4: Checking reference counts
55+Pass 5: Checking group summary information
56+Block bitmap differences:  -(24--25) -(27--41) -(107--1113)
57+Fix? yes
58+
59+Free blocks count wrong for group #0 (934, counted=1958).
60+Fix? yes
61+
62+Free blocks count wrong (934, counted=1958).
63+Fix? yes
64+
65+Recreate journal? yes
66+
67+Creating journal (1024 blocks):  Done.
68+
69+*** journal has been regenerated ***
70+
71+test_filesys: ***** FILE SYSTEM WAS MODIFIED *****
72+test_filesys: 11/256 files (0.0% non-contiguous), 1114/2048 blocks
73+Exit status is 1
74diff --git a/tests/f_badjour_encrypted/expect.2 b/tests/f_badjour_encrypted/expect.2
75new file mode 100644
76index 00000000..76934be2
77--- /dev/null
78+++ b/tests/f_badjour_encrypted/expect.2
79@@ -0,0 +1,7 @@
80+Pass 1: Checking inodes, blocks, and sizes
81+Pass 2: Checking directory structure
82+Pass 3: Checking directory connectivity
83+Pass 4: Checking reference counts
84+Pass 5: Checking group summary information
85+test_filesys: 11/256 files (9.1% non-contiguous), 1114/2048 blocks
86+Exit status is 0
87diff --git a/tests/f_badjour_encrypted/name b/tests/f_badjour_encrypted/name
88new file mode 100644
89index 00000000..e8f4c04f
90--- /dev/null
91+++ b/tests/f_badjour_encrypted/name
92@@ -0,0 +1 @@
93+journal inode has encrypt flag
94diff --git a/tests/f_badjour_encrypted/script b/tests/f_badjour_encrypted/script
95new file mode 100644
96index 00000000..e6778f1d
97--- /dev/null
98+++ b/tests/f_badjour_encrypted/script
99@@ -0,0 +1,11 @@
100+if ! test -x $DEBUGFS_EXE; then
101+	echo "$test_name: $test_description: skipped (no debugfs)"
102+	return 0
103+fi
104+
105+touch $TMPFILE
106+$MKE2FS -t ext4 -b 1024 $TMPFILE 2M
107+$DEBUGFS -w -R 'set_inode_field <8> flags 0x80800' $TMPFILE
108+
109+SKIP_GUNZIP="true"
110+. $cmd_dir/run_e2fsck
111--
112cgit
113
114