e2fsck: set the encrypt feature if the filesystem has encrypted inodes
PATCH v2 1/1 e2fsck: set the encrypt feature if the filesystem has encrypted inodes
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.
---
Changes from v1:
- Check info->file_ranges_count == 0 so the question is not repeated for every single encrypted inode if the user declines to fix the problem [Eric Biggers].
- Add 'xgettext:no-c-format' to the PR_1_ENCRYPT_FEATURE string [Eric Biggers].
- Create an empty file instead of a file with data to reduce the size of the compressed image [Eric Biggers].
e2fsck/encrypted_files.c | 14 +++++++ e2fsck/problem.c | 9 +++++ 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 -> 1158 bytes tests/f_encrypt_feature_missing/mkimage.sh | 43 +++++++++++++++++++++ tests/f_encrypt_feature_missing/name | 1 + 8 files changed, 89 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
e2fsck/encrypted_files.c +14 -0
@@ -389,6 +389,20 @@ int add_encrypted_file(e2fsck_t ctx, struct problem_context *pctx)return 0 ; } +/* +* If the inode is encrypted but the filesystem does not have +* the encrypt feature, the fix is to set it. If the user declines, +* we should not ask the same question for all the encrypted inodes +* in the filesystem, so use 'file_ranges_count' to do it on the +* first one only. +*/ +if (info->file_ranges_count ==0 && + !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); }
e2fsck/problem.c +9 -0
@@ -1319,6 +1319,15 @@ 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, +/* xgettext:no-c-format */ +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 */
e2fsck/problem.h +3 -0
@@ -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 */
tests/f_encrypt_feature_missing/expect.1 new file +12 -0
@@ -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), 19/128 blocks +Exit status is 1
tests/f_encrypt_feature_missing/expect.2 new file +7 -0
@@ -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), 19/128 blocks +Exit status is 0
tests/f_encrypt_feature_missing/image.gz new file binary +0 -0
tests/f_encrypt_feature_missing/mkimage.sh new file +43 -0
43 lines not on this page · raw message
tests/f_encrypt_feature_missing/name new file +1 -0
@@ -0,0 +1 @@ +encrypted inode but no encrypt feature
Signature · 1 line
2.47.3
Quoted 16 lines · Alberto Garcia
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.
Quoted 4 lines
Fix this by adding a new problem (
PR_1_ENCRYPT_FEATURE) and a regression test.Signed-off-by Alberto Garcia <[email protected]>
- Eric
Quoted 17 lines · Eric Biggers
Quoted 16 lines · Alberto Garcia
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.
Quoted 7 lines
Quoted 4 lines
Fix this by adding a new problem (
PR_1_ENCRYPT_FEATURE) and a regression test.Signed-off-by Alberto Garcia <[email protected]>Reviewed-by Eric Biggers <[email protected]>
As I mentioned on v1 though, it would be nice if the function comment of add_encrypted_file() were to be updated to mention the new behavior.
- Eric