[PATCH 2/4] fscrypt: Validate the test_dummy_encryption policy for new inodes
From: Baokun Li
Date: Tue Nov 03 2026 - 11:43:01 EST
Policies set through FS_IOC_SET_ENCRYPTION_POLICY or inherited from
an encrypted directory are validated, but the test_dummy_encryption
policy is not.
fscrypt_prepare_new_inode() applies it directly to the new inode.
As a result, a v1 dummy policy on a filesystem whose block size
exceeds the page size is used unchecked, and data written under
it is lost at writeback.
Fix this by validating dummy policy in fscrypt_prepare_new_inode()
before applying it. Inodes in an encrypted directory inherit an
already validated policy, so the check only concerns the unencrypted
case where the dummy policy is used.
Signed-off-by: Baokun Li <libaokun@xxxxxxxxxxxxxxxxx>
---
fs/crypto/keysetup.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/fs/crypto/keysetup.c b/fs/crypto/keysetup.c
index a77b889d7578..497ba67ec6fe 100644
--- a/fs/crypto/keysetup.c
+++ b/fs/crypto/keysetup.c
@@ -763,6 +763,14 @@ int fscrypt_prepare_new_inode(struct inode *dir, struct inode *inode,
!S_ISLNK(inode->i_mode))
return 0;
+ /*
+ * A policy inherited from an encrypted directory was validated
+ * when the directory's key was set up. The test dummy policy was
+ * not, so check it here.
+ */
+ if (!IS_ENCRYPTED(dir) && !fscrypt_supported_policy(policy, inode))
+ return -EINVAL;
+
*encrypt_ret = true;
get_random_bytes(nonce, FSCRYPT_FILE_NONCE_SIZE);
--
2.43.7