Skip to contentSkip to conversation

e2fsck: don't allow journal inode to have encrypt flag

PATCH Applied Eric Biggers 3 participants 4 messages Nov 2, 2022 – Jan 19, 2023 fscrypt: file system level encryption support

lore
Share & tools
lore

Eric Biggers

author maintainer
#0 lore raw

PATCH v2 1/1 e2fsck: don't allow journal inode to have encrypt flag

From: Eric Biggers <[email protected]>

Since the kernel is being fixed to consider journal inodes with the 'encrypt' flag set to be invalid, also update e2fsck accordingly.

---

v2: generate the test filesystem image dynamically.

 e2fsck/journal.c                   |  3 ++-
 tests/f_badjour_encrypted/expect.1 | 30 ++++++++++++++++++++++++++++++
 tests/f_badjour_encrypted/expect.2 |  7 +++++++
 tests/f_badjour_encrypted/name     |  1 +
 tests/f_badjour_encrypted/script   | 11 +++++++++++
 5 files changed, 51 insertions(+), 1 deletion(-)
 create mode 100644 tests/f_badjour_encrypted/expect.1
 create mode 100644 tests/f_badjour_encrypted/expect.2
 create mode 100644 tests/f_badjour_encrypted/name
 create mode 100644 tests/f_badjour_encrypted/script
e2fsck/journal.c +2 -1
index d802c5e9..343e48ba 100644
@@ -1039,7 +1039,8 @@ static errcode_t e2fsck_get_journal(e2fsck_t ctx, journal_t **ret_journal)
 			tried_backup_jnl++;
 		}
 		if (!j_inode->i_ext2.i_links_count ||
-		    !LINUX_S_ISREG(j_inode->i_ext2.i_mode)) {
+		    !LINUX_S_ISREG(j_inode->i_ext2.i_mode) ||
+		    (j_inode->i_ext2.i_flags & EXT4_ENCRYPT_FL)) {
 			retval = EXT2_ET_NO_JOURNAL;
 			goto try_backup_journal;
 		}
tests/f_badjour_encrypted/expect.1 new file +30 -0
new file mode 100644
index 00000000..0b13b9eb
@@ -0,0 +1,30 @@
+Superblock has an invalid journal (inode 8).
+Clear? yes
+
+*** journal has been deleted ***
+
+Pass 1: Checking inodes, blocks, and sizes
+Journal inode is not in use, but contains data.  Clear? yes
+
+Pass 2: Checking directory structure
+Pass 3: Checking directory connectivity
+Pass 4: Checking reference counts
+Pass 5: Checking group summary information
+Block bitmap differences:  -(24--25) -(27--41) -(107--1113)
+Fix? yes
+
+Free blocks count wrong for group #0 (934, counted=1958).
+Fix? yes
+
+Free blocks count wrong (934, counted=1958).
+Fix? yes
+
+Recreate journal? yes
+
+Creating journal (1024 blocks):  Done.
+
+*** journal has been regenerated ***
+
+test_filesys: ***** FILE SYSTEM WAS MODIFIED *****
+test_filesys: 11/256 files (0.0% non-contiguous), 1114/2048 blocks
+Exit status is 1
tests/f_badjour_encrypted/expect.2 new file +7 -0
new file mode 100644
index 00000000..76934be2
@@ -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/256 files (9.1% non-contiguous), 1114/2048 blocks
+Exit status is 0
tests/f_badjour_encrypted/name new file +1 -0
new file mode 100644
index 00000000..e8f4c04f
@@ -0,0 +1 @@
+journal inode has encrypt flag
tests/f_badjour_encrypted/script new file +11 -0
new file mode 100644
index 00000000..e6778f1d
@@ -0,0 +1,11 @@
+if ! test -x $DEBUGFS_EXE; then
+	echo "$test_name: $test_description: skipped (no debugfs)"
+	return 0
+fi
+
+touch $TMPFILE
+$MKE2FS -t ext4 -b 1024 $TMPFILE 2M
+$DEBUGFS -w -R 'set_inode_field <8> flags 0x80800' $TMPFILE
+
+SKIP_GUNZIP="true"
+. $cmd_dir/run_e2fsck

base-commit: aad34909b6648579f42dade5af5b46821aa4d845

Signature · 1 line
2.38.1
Reviewed-by on v2 1/1
#1 lore raw
Quoted 7 lines · Eric Biggers

From: Eric Biggers <[email protected]>

Since the kernel is being fixed to consider journal inodes with the 'encrypt' flag set to be invalid, also update e2fsck accordingly.

Looks good.

Quoted 103 lines

---

v2: generate the test filesystem image dynamically.

e2fsck/journal.c                   |  3 ++-
tests/f_badjour_encrypted/expect.1 | 30 ++++++++++++++++++++++++++++++
tests/f_badjour_encrypted/expect.2 |  7 +++++++
tests/f_badjour_encrypted/name     |  1 +
tests/f_badjour_encrypted/script   | 11 +++++++++++
5 files changed, 51 insertions(+), 1 deletion(-)

create mode 100644 tests/f_badjour_encrypted/expect.1 create mode 100644 tests/f_badjour_encrypted/expect.2 create mode 100644 tests/f_badjour_encrypted/name create mode 100644 tests/f_badjour_encrypted/script

e2fsck/journal.c +2 -1
index d802c5e9..343e48ba 100644
@@ -1039,7 +1039,8 @@ static errcode_t e2fsck_get_journal(e2fsck_t ctx, journal_t **ret_journal)
 			tried_backup_jnl++;
 		}
 		if (!j_inode->i_ext2.i_links_count ||
-		    !LINUX_S_ISREG(j_inode->i_ext2.i_mode)) {
+		    !LINUX_S_ISREG(j_inode->i_ext2.i_mode) ||
+		    (j_inode->i_ext2.i_flags & EXT4_ENCRYPT_FL)) {
 			retval = EXT2_ET_NO_JOURNAL;
 			goto try_backup_journal;
 		}
tests/f_badjour_encrypted/expect.1 new file +30 -0
new file mode 100644
index 00000000..0b13b9eb
@@ -0,0 +1,30 @@
+Superblock has an invalid journal (inode 8).
+Clear? yes
+
+*** journal has been deleted ***
+
+Pass 1: Checking inodes, blocks, and sizes
+Journal inode is not in use, but contains data.  Clear? yes
+
+Pass 2: Checking directory structure
+Pass 3: Checking directory connectivity
+Pass 4: Checking reference counts
+Pass 5: Checking group summary information
+Block bitmap differences:  -(24--25) -(27--41) -(107--1113)
+Fix? yes
+
+Free blocks count wrong for group #0 (934, counted=1958).
+Fix? yes
+
+Free blocks count wrong (934, counted=1958).
+Fix? yes
+
+Recreate journal? yes
+
+Creating journal (1024 blocks):  Done.
+
+*** journal has been regenerated ***
+
+test_filesys: ***** FILE SYSTEM WAS MODIFIED *****
+test_filesys: 11/256 files (0.0% non-contiguous), 1114/2048 blocks
+Exit status is 1
tests/f_badjour_encrypted/expect.2 new file +7 -0
new file mode 100644
index 00000000..76934be2
@@ -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/256 files (9.1% non-contiguous), 1114/2048 blocks
+Exit status is 0
tests/f_badjour_encrypted/name new file +1 -0
new file mode 100644
index 00000000..e8f4c04f
@@ -0,0 +1 @@
+journal inode has encrypt flag
tests/f_badjour_encrypted/script new file +11 -0
new file mode 100644
index 00000000..e6778f1d
@@ -0,0 +1,11 @@
+if ! test -x $DEBUGFS_EXE; then
+	echo "$test_name: $test_description: skipped (no debugfs)"
+	return 0
+fi
+
+touch $TMPFILE
+$MKE2FS -t ext4 -b 1024 $TMPFILE 2M
+$DEBUGFS -w -R 'set_inode_field <8> flags 0x80800' $TMPFILE
+
+SKIP_GUNZIP="true"
+. $cmd_dir/run_e2fsck
Quoted 4 lines

base-commit: aad34909b6648579f42dade5af5b46821aa4d845 --
2.38.1

Cheers, Andreas

maintainer Applied
#3 lore raw
In reply to Eric Biggers
Quoted 6 lines · Eric Biggers

From: Eric Biggers <[email protected]>

Since the kernel is being fixed to consider journal inodes with the 'encrypt' flag set to be invalid, also update e2fsck accordingly.

Applied, thanks!

[1/1] e2fsck: don't allow journal inode to have encrypt flag

      commit: b0cd09e5b65373fc9f89048958c093bb1e6a1ecb

Best regards,

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