A filesystem without the encrypt feature can still contain encrypted inodes, either due to corruption or because the image was crafted that way. e2fsck currently accepts such inodes without complaint. Since those inodes can be decrypted, this should be fixed by setting the encrypt feature on the filesystem. Note that the Linux kernel does not currently support encryption when the block size is larger than the page size. After this change, such a filesystem will be rejected at mount time (see the kernel commit 709f0f1f1bf5, "ext4: add checks for large folio incompatibilities when BS > PS"). However, since this depends on the page size of the machine where the filesystem is mounted, and the kernel could lift that limitation in the future, e2fsck does not take it into account. Fix this by adding a new problem (PR_1_ENCRYPT_FEATURE) and a regression test. Signed-off-by: Alberto Garcia --- e2fsck/encrypted_files.c | 7 ++++ e2fsck/problem.c | 8 ++++ e2fsck/problem.h | 3 ++ tests/f_encrypt_feature_missing/expect.1 | 12 ++++++ tests/f_encrypt_feature_missing/expect.2 | 7 ++++ tests/f_encrypt_feature_missing/image.gz | Bin 0 -> 5566 bytes tests/f_encrypt_feature_missing/mkimage.sh | 43 +++++++++++++++++++++ tests/f_encrypt_feature_missing/name | 1 + 8 files changed, 81 insertions(+) create mode 100644 tests/f_encrypt_feature_missing/expect.1 create mode 100644 tests/f_encrypt_feature_missing/expect.2 create mode 100644 tests/f_encrypt_feature_missing/image.gz create mode 100755 tests/f_encrypt_feature_missing/mkimage.sh create mode 100644 tests/f_encrypt_feature_missing/name diff --git a/e2fsck/encrypted_files.c b/e2fsck/encrypted_files.c index 16be2d6d..9ddce4da 100644 --- a/e2fsck/encrypted_files.c +++ b/e2fsck/encrypted_files.c @@ -389,6 +389,13 @@ int add_encrypted_file(e2fsck_t ctx, struct problem_context *pctx) return 0; } + /* The inode is encrypted, so the filesystem needs the encrypt feature */ + if (!ext2fs_has_feature_encrypt(ctx->fs->super) && + fix_problem(ctx, PR_1_ENCRYPT_FEATURE, pctx)) { + ext2fs_set_feature_encrypt(ctx->fs->super); + ext2fs_mark_super_dirty(ctx->fs); + } + /* Store this ino => policy_id mapping in the encrypted_file_info. */ return append_ino_and_policy_id(ctx, pctx, ino, policy_id); } diff --git a/e2fsck/problem.c b/e2fsck/problem.c index e433281f..d8766a65 100644 --- a/e2fsck/problem.c +++ b/e2fsck/problem.c @@ -1319,6 +1319,14 @@ static struct e2fsck_problem problem_table[] = { N_("@i %i references EA inode but @S is missing EA_INODE feature\n"), PROMPT_FIX, PR_PREEN_OK, 0, 0, 0 }, + /* + * Encrypted inode found but the filesystem is missing the + * encrypt feature + */ + { PR_1_ENCRYPT_FEATURE, + N_("@i %i is encrypted but @S is missing ENCRYPT feature\n"), + PROMPT_FIX, PR_PREEN_OK, 0, 0, 0 }, + /* Pass 1b errors */ /* Pass 1B: Rescan for duplicate/bad blocks */ diff --git a/e2fsck/problem.h b/e2fsck/problem.h index ef15b8c8..ae1bde26 100644 --- a/e2fsck/problem.h +++ b/e2fsck/problem.h @@ -740,6 +740,9 @@ struct problem_context { /* Inode references EA inode but ea_inode feature is not enabled */ #define PR_1_EA_INODE_FEATURE 0x010092 +/* Encrypted inode found but encrypt feature is not enabled */ +#define PR_1_ENCRYPT_FEATURE 0x010093 + /* * Pass 1b errors */ diff --git a/tests/f_encrypt_feature_missing/expect.1 b/tests/f_encrypt_feature_missing/expect.1 new file mode 100644 index 00000000..6a2a02d7 --- /dev/null +++ b/tests/f_encrypt_feature_missing/expect.1 @@ -0,0 +1,12 @@ +Pass 1: Checking inodes, blocks, and sizes +Inode 12 is encrypted but superblock is missing ENCRYPT 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), 20/128 blocks +Exit status is 1 diff --git a/tests/f_encrypt_feature_missing/expect.2 b/tests/f_encrypt_feature_missing/expect.2 new file mode 100644 index 00000000..8fee27c1 --- /dev/null +++ b/tests/f_encrypt_feature_missing/expect.2 @@ -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), 20/128 blocks +Exit status is 0 diff --git a/tests/f_encrypt_feature_missing/image.gz b/tests/f_encrypt_feature_missing/image.gz new file mode 100644 index 0000000000000000000000000000000000000000..d3e627e7338e73b24713e41d7c41ffcf42479745 GIT binary patch literal 5566 zcmeHKS5Om-vc`fUNJl^rP(YC0TL>T^RjPEP{D4wJ4<%HQCIUe^NR=wR_a+iLA=0HJ zp(pejVyNdobLYS3zTc-ibH9h({dRU{+w8-##gdR%@#CFu-*Ixaad=O(i@dK#XLe3> zXu~L~p7u29ZpXRU)UN7n4TP)Q6`UR2H1-hE$2m`JDRoBp*M$Bc|4Sd3RV{ z)$5Cg$M(#1i*L=fUrYK~H+p*R3Sj8hle=YtuJ|ey{*s93+JrcW>?hLWH~DT0Zpi&8 zIJzsdY`Gk1wfxN2w-Iwl<&T~XR-i|<$jrAyuA!k}J26P~eBuzZ zPQFMHXZ_HqkjqT0%S7}yeuPFH5M;Iy1O?xgxQ|)4|LyxXE_-)(^{#Cn{}=mPhDw7- zus3)9;h`Sri!1ct*|pd}?=^RpOq=Yt^QQAcDj52VK#*QRGheuU>K}DF=*Q!4b*J7Y z`eQ;uvXlc%ze+u$JP_JLqhrq*M*VvxuCJanh7w)w0MVnN??MG`6tD9fl5M5V_U>)W zfw%nNq1QQx8+T0TP|Y6O(cDp;_{|TQv8J}R8}qAJzG!m1tIMz8~!$0tC|iRD>~nd+BocsdjdyziG7~^XI59&(>$(MEva@=+zbcEbq?_qs>BS z{xzjU^7OR=4jtQdasa#tomXPj!w&myni zsIo`;G7R~Sf=S*Kg^SHv{#cmr8}@Q%zI~KN6WLhb=o2n`|DSZ1_@@^tH=!}dE;nrd z_=rM<4L$x-*#B4#(fQ4P2mQzRQ+D|C)doq<-raM=jzvo|v=AFE zd+(pvOT3d+TJbRtN;IwjO5hK45A^)NI7EIXaO^g%%j zW0SqDQe5(ej&{bRCl#lW1W8>(alQv1Nl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C zb+)m9l9^-gmR#PY$EnOB;L|2Z77cV)r*l!{z2Oc_a8zf`qTT!a`=tFXDK3UH4b~2O z%$_G+LBS6+99FR4fUb0Gvl}CPJjOabdT{5wlyj3+sA3_nNv4#ar@<_I#w?XX*5vFW zaJwM=C)+72WCae#>4Jc*aDuy2#h|%z$e(~8TKCl zn1GT;Im@kWVUZWj5ik=4z{zCo=~*&;?tUvcX!g&lsvOjE$GgpY?HM1%9AeZ`zh^d9 z|7z;oL|r$cW{ak5e+AXKV6U&%E%29JMyaDvu=Hw^t3q zz1aQ>a`GE;K?dM-gUd?$8^BT4;J}M_9g(SGszMKYx}{58PpjJ27W@!=Zd715pQQ+T zYBu1J@byt4lzY~Sa2y#BmT2ScHThN-Xq{oQ_X_O>7ZlGq(e}UD*$~^zzVZu%WmGOB zG*1k8d6SY2ly)fPGGzophkFNB>f8n1f?Hne%+-H6tR1=_+wMM_x?DPK%_pv7(P7QB rtO6h5181!(f;K`1&Vy|%3(5b!mH)^8l?mK9+}ujktTQGeA|d)0UVJ`O literal 0 HcmV?d00001 diff --git a/tests/f_encrypt_feature_missing/mkimage.sh b/tests/f_encrypt_feature_missing/mkimage.sh new file mode 100755 index 00000000..ca36a3fd --- /dev/null +++ b/tests/f_encrypt_feature_missing/mkimage.sh @@ -0,0 +1,43 @@ +#!/bin/bash + +# This is the script that was used to create the image.gz in this directory. +# +# It creates a filesystem with an encrypted directory and file, and then +# clears the encrypt feature flag. e2fsck should notice that the +# filesystem contains encrypted inodes and offer to set the feature again. +# +# This must be run as root on a kernel with ext4 encryption support. + +# For the purposes of this test both v1 and v2 policies are equally fine. +# v2 policies need fscryptctl from https://github.com/google/fscryptctl +policy_version=1 + +set -e -u +umask 0022 + +mkdir -p mnt +umount mnt &> /dev/null || true + +# Create an image with the 'encrypt' feature set +dd if=/dev/zero of=image bs=4096 count=128 +mke2fs -O encrypt -b 4096 -N 128 image +mount image mnt + +# Create an encrypted directory (ino 12) containing an encrypted file (ino 13) +dir=mnt/edir +mkdir $dir +if [ "$policy_version" = "2" ]; then + policy="$(head -c 32 /dev/zero | fscryptctl add_key mnt)" + fscryptctl set_policy "$policy" $dir +else + echo password | e4crypt add_key $dir +fi +echo foo > $dir/encrypted_file + +umount mnt +rmdir mnt + +# Clear the encrypt feature, leaving the encrypted inodes in place +debugfs -w -R "feature -encrypt" image + +gzip -9 -f image diff --git a/tests/f_encrypt_feature_missing/name b/tests/f_encrypt_feature_missing/name new file mode 100644 index 00000000..51def291 --- /dev/null +++ b/tests/f_encrypt_feature_missing/name @@ -0,0 +1 @@ +encrypted inode but no encrypt feature -- 2.47.3