ext4 crypto: fix to check feature status before get policy
PATCH 1/1 ext4 crypto: fix to check feature status before get policy
From: Chao Yu <[email protected]>
When getting fscrypto policy via EXT4_IOC_GET_ENCRYPTION_POLICY, if encryption feature is off, it's better to return EOPNOTSUPP instead of ENODATA, so let's add ext4_has_feature_encrypt() to do the check for that.
--- fs/ext4/ioctl.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
fs/ext4/ioctl.c +4 -2
@@ -1112,9 +1112,11 @@ long ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)return -EOPNOTSUPP ;#endif } -case EXT4_IOC_GET_ENCRYPTION_POLICY : +case EXT4_IOC_GET_ENCRYPTION_POLICY : { +if (!ext4_has_feature_encrypt (sb)) +return -EOPNOTSUPP ;return fscrypt_ioctl_get_policy (filp, (void __user *)arg); - + }case EXT4_IOC_FSGETXATTR : {struct fsxattr fa;
Signature · 1 line
2.22.0
Hi,
Is this change not necessary? A month has passed...
Thanks,
Quoted 31 lines · Chao Yu
From: Chao Yu <[email protected]>
When getting fscrypto policy via
EXT4_IOC_GET_ENCRYPTION_POLICY, if encryption feature is off, it's better to return EOPNOTSUPP instead of ENODATA, so let's addext4_has_feature_encrypt()to do the check for that.Signed-off-by Chao Yu <[email protected]>--- fs/ext4/ioctl.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)fs/ext4/ioctl.c +4
-2@@ -1112,9 +1112,11 @@ long ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)return -EOPNOTSUPP ;#endif } -case EXT4_IOC_GET_ENCRYPTION_POLICY : +case EXT4_IOC_GET_ENCRYPTION_POLICY : { +if (!ext4_has_feature_encrypt (sb)) +return -EOPNOTSUPP ;return fscrypt_ioctl_get_policy (filp, (void __user *)arg); - + }case EXT4_IOC_FSGETXATTR : {struct fsxattr fa;
Eric Biggers
maintainerQuoted 30 lines · Chao Yu
Hi,
Is this change not necessary? A month has passed...
Thanks,
Quoted 23 lines · Chao Yu
From: Chao Yu <[email protected]>
When getting fscrypto policy via
EXT4_IOC_GET_ENCRYPTION_POLICY, if encryption feature is off, it's better to return EOPNOTSUPP instead of ENODATA, so let's addext4_has_feature_encrypt()to do the check for that.Signed-off-by Chao Yu <[email protected]>--- fs/ext4/ioctl.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)fs/ext4/ioctl.c +2
-1@@ -1112,9 +1112,11 @@ long ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)return -EOPNOTSUPP ;#endif } -case EXT4_IOC_GET_ENCRYPTION_POLICY : +case EXT4_IOC_GET_ENCRYPTION_POLICY : { +if (!ext4_has_feature_encrypt (sb))
Quoted 8 lines
fs/ext4/ioctl.c long ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) · line 1122
Quoted 8 lines
fs/ext4/ioctl.c +2
-1+return -EOPNOTSUPP ;return fscrypt_ioctl_get_policy (filp, (void __user *)arg); - + }case EXT4_IOC_FSGETXATTR : {struct fsxattr fa;
Sorry, I was preoccupied with all the other fscrypt changes, and was thinking of waiting until 5.5 for this to avoid a potential extra merge conflict or a potentially breaking change. Looking at this again though, the new ioctl FS_IOC_GET_ENCRYPTION_POLICY_EX *does* do the feature check, which doesn't match the documentation, which implies the check isn't done. Also, f2fs does the check in FS_IOC_GET_ENCRYPTION_POLICY, so the filesystems are inconsistent.
So, it makes some sense to apply this now. So I've gone ahead and applied the following to fscrypt.git#master, edited a bit from your original patch:
Quoted 1 line
From
0642ea2409f3bfa105570e12854b8e2628db6835Mon Sep 17 00:00:00 2001
From: Chao Yu <[email protected]>
Date: Sun, 4 Aug 2019 17:56:43 +0800
Subject: [PATCH] ext4 crypto: fix to check feature status before get policy
When getting fscrypt policy via EXT4_IOC_GET_ENCRYPTION_POLICY, if encryption feature is off, it's better to return EOPNOTSUPP instead of ENODATA, so let's add ext4_has_feature_encrypt() to do the check for that.
This makes it so that all fscrypt ioctls consistently check for the encryption feature, and makes ext4 consistent with f2fs in this regard.
[EB - removed unneeded braces, updated the documentation, and
added more explanation to commit message]
--- Documentation/filesystems/fscrypt.rst | 3 ++- fs/ext4/ioctl.c | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-)
Documentation/filesystems/fscrypt.rst +2 -1
@@ -562,7 +562,8 @@ FS_IOC_GET_ENCRYPTION_POLICY_EX can fail with the following errors: or this kernel is too old to support FS_IOC_GET_ENCRYPTION_POLICY_EX (try FS_IOC_GET_ENCRYPTION_POLICY instead) - ``EOPNOTSUPP``: the kernel was not configured with encryption - support for this filesystem + support for this filesystem, or the filesystem superblock has not + had encryption enabled on it - ``EOVERFLOW``: the file is encrypted and uses a recognized encryption policy version, but the policy struct does not fit into the provided buffer
fs/ext4/ioctl.c +2 -0
@@ -1113,6 +1113,8 @@ long ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)#endif }case EXT4_IOC_GET_ENCRYPTION_POLICY : +if (!ext4_has_feature_encrypt (sb)) +return -EOPNOTSUPP ;return fscrypt_ioctl_get_policy (filp, (void __user *)arg);case FS_IOC_GET_ENCRYPTION_POLICY_EX :
Signature · 1 line
2.23.0
Quoted 60 lines · Eric Biggers
Quoted 30 lines · Chao Yu
Hi,
Is this change not necessary? A month has passed...
Thanks,
Quoted 23 lines · Chao Yu
From: Chao Yu <[email protected]>
When getting fscrypto policy via
EXT4_IOC_GET_ENCRYPTION_POLICY, if encryption feature is off, it's better to return EOPNOTSUPP instead of ENODATA, so let's addext4_has_feature_encrypt()to do the check for that.Signed-off-by Chao Yu <[email protected]>--- fs/ext4/ioctl.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)fs/ext4/ioctl.c +2
-1@@ -1112,9 +1112,11 @@ long ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)return -EOPNOTSUPP ;#endif } -case EXT4_IOC_GET_ENCRYPTION_POLICY : +case EXT4_IOC_GET_ENCRYPTION_POLICY : { +if (!ext4_has_feature_encrypt (sb))Quoted 8 lines
fs/ext4/ioctl.c long ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) · line 1122
Quoted 8 lines
fs/ext4/ioctl.c +2
-1+return -EOPNOTSUPP ;return fscrypt_ioctl_get_policy (filp, (void __user *)arg); - + }case EXT4_IOC_FSGETXATTR : {struct fsxattr fa;Sorry, I was preoccupied with all the other fscrypt changes, and was thinking of waiting until 5.5 for this to avoid a potential extra merge conflict or a potentially breaking change. Looking at this again though, the new ioctl
FS_IOC_GET_ENCRYPTION_POLICY_EX*does* do the feature check, which doesn't match the documentation, which implies the check isn't done. Also, f2fs does the check inFS_IOC_GET_ENCRYPTION_POLICY, so the filesystems are inconsistent.So, it makes some sense to apply this now. So I've gone ahead and applied the following to fscrypt.git#master, edited a bit from your original patch:
Quoted 1 line
Quoted 1 line
From
0642ea2409f3bfa105570e12854b8e2628db6835Mon Sep 17 00:00:00 2001From: Chao Yu <[email protected]>
Date: Sun, 4 Aug 2019 17:56:43 +0800
Subject: [PATCH] ext4 crypto: fix to check feature status before get policyWhen getting fscrypt policy via
EXT4_IOC_GET_ENCRYPTION_POLICY, if encryption feature is off, it's better to return EOPNOTSUPP instead of ENODATA, so let's addext4_has_feature_encrypt()to do the check for that.
Quoted 6 lines
This makes it so that all fscrypt ioctls consistently check for the encryption feature, and makes ext4 consistent with f2fs in this regard.
Signed-off-by Chao Yu <[email protected]>[EB - removed unneeded braces, updated the documentation, and
added more explanation to commit message]
The patch looks better now, thanks for the help.
Thanks,
Quoted 34 lines
Signed-off-by Eric Biggers <[email protected]>--- Documentation/filesystems/fscrypt.rst | 3 ++- fs/ext4/ioctl.c | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-)Documentation/filesystems/fscrypt.rst +2
-1@@ -562,7 +562,8 @@ FS_IOC_GET_ENCRYPTION_POLICY_EX can fail with the following errors: or this kernel is too old to support FS_IOC_GET_ENCRYPTION_POLICY_EX (try FS_IOC_GET_ENCRYPTION_POLICY instead) - ``EOPNOTSUPP``: the kernel was not configured with encryption - support for this filesystem + support for this filesystem, or the filesystem superblock has not + had encryption enabled on it - ``EOVERFLOW``: the file is encrypted and uses a recognized encryption policy version, but the policy struct does not fit into the provided bufferfs/ext4/ioctl.c +2
-0@@ -1113,6 +1113,8 @@ long ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)#endif }case EXT4_IOC_GET_ENCRYPTION_POLICY : +if (!ext4_has_feature_encrypt (sb)) +return -EOPNOTSUPP ;return fscrypt_ioctl_get_policy (filp, (void __user *)arg);case FS_IOC_GET_ENCRYPTION_POLICY_EX :