History

fscrypto: only allow setting encryption policy on directories

The FS_IOC_SET_ENCRYPTION_POLICY ioctl allowed setting an encryption policy on nondirectory files. This was unintentional, and in the case of nonempty regular files did not behave as expected because existing data was not actually encrypted by the ioctl. In the case of ext4, the user could also trigger filesystem errors in ->empty_dir(), e.g. due to mismatched "directory" checksums when the kernel incorrectly tried to interpret a regular file as a directory. This bug affected ext4 with kernels v4.8-rc1 or later and f2fs with kernels v4.6 and later. It appears that older kernels only permitted directories and that the check was accidentally lost during the refactoring to share the file encryption code between ext4 and f2fs. This patch restores the !S_ISDIR() check that was present in older kernels.

Eric Biggers committed 10 years ago

Commit 002ced41 parent 163ae1c1 file · +2 −0Browse files

Unified · Split

fs/crypto/policy.c+2−0
@@ -102,6 +102,8 @@ int fscrypt_process_policy(struct inode *inode, · 101 unmodified lines
102 return -EINVAL;102 return -EINVAL;
103 103
104 if (!inode_has_encryption_context(inode)) {104 if (!inode_has_encryption_context(inode)) {
105 if (!S_ISDIR(inode->i_mode))
106 return -EINVAL;
105 if (!inode->i_sb->s_cop->empty_dir)107 if (!inode->i_sb->s_cop->empty_dir)
106 return -EOPNOTSUPP;108 return -EOPNOTSUPP;
107 if (!inode->i_sb->s_cop->empty_dir(inode))109 if (!inode->i_sb->s_cop->empty_dir(inode))

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t