[PATCH 4.9 014/117] fscrypt: use EEXIST when file already uses different policy

From: Greg Kroah-Hartman
Date: Mon Nov 09 2020 - 08:42:37 EST


From: Eric Biggers <ebiggers@xxxxxxxxxx>

commit 8488cd96ff88966ccb076e4f3654f59d84ba686d upstream.

As part of an effort to clean up fscrypt-related error codes, make
FS_IOC_SET_ENCRYPTION_POLICY fail with EEXIST when the file already uses
a different encryption policy. This is more descriptive than EINVAL,
which was ambiguous with some of the other error cases.

I am not aware of any users who might be relying on the previous error
code of EINVAL, which was never documented anywhere.

This failure case will be exercised by an xfstest.

Signed-off-by: Eric Biggers <ebiggers@xxxxxxxxxx>
Signed-off-by: Theodore Ts'o <tytso@xxxxxxx>
Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>


---
fs/crypto/policy.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

--- a/fs/crypto/policy.c
+++ b/fs/crypto/policy.c
@@ -131,7 +131,7 @@ int fscrypt_ioctl_set_policy(struct file
printk(KERN_WARNING
"%s: Policy inconsistent with encryption context\n",
__func__);
- ret = -EINVAL;
+ ret = -EEXIST;
}

inode_unlock(inode);