From 5ab7189a31bad40e4b44020cae6e56c8074721a1 Mon Sep 17 00:00:00 2001 From: Eric Biggers Date: Sun, 4 Aug 2019 19:35:48 -0700 Subject: fscrypt: require that key be added when setting a v2 encryption policy By looking up the master keys in a filesystem-level keyring rather than in the calling processes' key hierarchy, it becomes possible for a user to set an encryption policy which refers to some key they don't actually know, then encrypt their files using that key. Cryptographically this isn't much of a problem, but the semantics of this would be a bit weird. Thus, enforce that a v2 encryption policy can only be set if the user has previously added the key, or has capable(CAP_FOWNER). We tolerate that this problem will continue to exist for v1 encryption policies, however; there is no way around that. Reviewed-by: Theodore Ts'o Signed-off-by: Eric Biggers --- fs/crypto/policy.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'fs/crypto/policy.c') diff --git a/fs/crypto/policy.c b/fs/crypto/policy.c index 0141d338c1fd..4072ba644595 100644 --- a/fs/crypto/policy.c +++ b/fs/crypto/policy.c @@ -233,11 +233,13 @@ static int set_encryption_policy(struct inode *inode, { union fscrypt_context ctx; int ctxsize; + int err; if (!fscrypt_supported_policy(policy, inode)) return -EINVAL; - if (policy->version == FSCRYPT_POLICY_V1) { + switch (policy->version) { + case FSCRYPT_POLICY_V1: /* * The original encryption policy version provided no way of * verifying that the correct master key was supplied, which was @@ -251,6 +253,16 @@ static int set_encryption_policy(struct inode *inode, */ pr_warn_once("%s (pid %d) is setting deprecated v1 encryption policy; recommend upgrading to v2.\n", current->comm, current->pid); + break; + case FSCRYPT_POLICY_V2: + err = fscrypt_verify_key_added(inode->i_sb, + policy->v2.master_key_identifier); + if (err) + return err; + break; + default: + WARN_ON(1); + return -EINVAL; } ctxsize = fscrypt_new_context_from_policy(&ctx, policy); -- cgit v1.2.3-59-g8ed1b