Lines Matching full:policy
3 * Encryption policy functions for per-file encryption support.
10 * Modified by Eric Biggers, 2019 for v2 policy support.
22 * @policy1: the first policy
23 * @policy2: the second policy
36 int fscrypt_policy_to_key_spec(const union fscrypt_policy *policy, in fscrypt_policy_to_key_spec() argument
39 switch (policy->version) { in fscrypt_policy_to_key_spec()
42 memcpy(key_spec->u.descriptor, policy->v1.master_key_descriptor, in fscrypt_policy_to_key_spec()
47 memcpy(key_spec->u.identifier, policy->v2.master_key_identifier, in fscrypt_policy_to_key_spec()
120 static bool supported_iv_ino_lblk_policy(const struct fscrypt_policy_v2 *policy, in supported_iv_ino_lblk_policy() argument
135 if (policy->contents_encryption_mode != FSCRYPT_MODE_AES_256_XTS) { in supported_iv_ino_lblk_policy()
137 "Can't use %s policy with contents mode other than AES-256-XTS", in supported_iv_ino_lblk_policy()
149 "Can't use %s policy on filesystem '%s' because it doesn't have stable inode numbers", in supported_iv_ino_lblk_policy()
157 "Can't use %s policy on filesystem '%s' because its inode numbers are too long", in supported_iv_ino_lblk_policy()
163 "Can't use %s policy on filesystem '%s' because its block numbers are too long", in supported_iv_ino_lblk_policy()
170 static bool fscrypt_supported_v1_policy(const struct fscrypt_policy_v1 *policy, in fscrypt_supported_v1_policy() argument
173 if (!fscrypt_valid_enc_modes_v1(policy->contents_encryption_mode, in fscrypt_supported_v1_policy()
174 policy->filenames_encryption_mode)) { in fscrypt_supported_v1_policy()
177 policy->contents_encryption_mode, in fscrypt_supported_v1_policy()
178 policy->filenames_encryption_mode); in fscrypt_supported_v1_policy()
182 if (policy->flags & ~(FSCRYPT_POLICY_FLAGS_PAD_MASK | in fscrypt_supported_v1_policy()
185 policy->flags); in fscrypt_supported_v1_policy()
189 if ((policy->flags & FSCRYPT_POLICY_FLAG_DIRECT_KEY) && in fscrypt_supported_v1_policy()
190 !supported_direct_key_modes(inode, policy->contents_encryption_mode, in fscrypt_supported_v1_policy()
191 policy->filenames_encryption_mode)) in fscrypt_supported_v1_policy()
204 static bool fscrypt_supported_v2_policy(const struct fscrypt_policy_v2 *policy, in fscrypt_supported_v2_policy() argument
209 if (!fscrypt_valid_enc_modes_v2(policy->contents_encryption_mode, in fscrypt_supported_v2_policy()
210 policy->filenames_encryption_mode)) { in fscrypt_supported_v2_policy()
213 policy->contents_encryption_mode, in fscrypt_supported_v2_policy()
214 policy->filenames_encryption_mode); in fscrypt_supported_v2_policy()
218 if (policy->flags & ~(FSCRYPT_POLICY_FLAGS_PAD_MASK | in fscrypt_supported_v2_policy()
223 policy->flags); in fscrypt_supported_v2_policy()
227 count += !!(policy->flags & FSCRYPT_POLICY_FLAG_DIRECT_KEY); in fscrypt_supported_v2_policy()
228 count += !!(policy->flags & FSCRYPT_POLICY_FLAG_IV_INO_LBLK_64); in fscrypt_supported_v2_policy()
229 count += !!(policy->flags & FSCRYPT_POLICY_FLAG_IV_INO_LBLK_32); in fscrypt_supported_v2_policy()
232 policy->flags); in fscrypt_supported_v2_policy()
236 if ((policy->flags & FSCRYPT_POLICY_FLAG_DIRECT_KEY) && in fscrypt_supported_v2_policy()
237 !supported_direct_key_modes(inode, policy->contents_encryption_mode, in fscrypt_supported_v2_policy()
238 policy->filenames_encryption_mode)) in fscrypt_supported_v2_policy()
241 if ((policy->flags & FSCRYPT_POLICY_FLAG_IV_INO_LBLK_64) && in fscrypt_supported_v2_policy()
242 !supported_iv_ino_lblk_policy(policy, inode, "IV_INO_LBLK_64", in fscrypt_supported_v2_policy()
252 if ((policy->flags & FSCRYPT_POLICY_FLAG_IV_INO_LBLK_32) && in fscrypt_supported_v2_policy()
253 !supported_iv_ino_lblk_policy(policy, inode, "IV_INO_LBLK_32", in fscrypt_supported_v2_policy()
257 if (memchr_inv(policy->__reserved, 0, sizeof(policy->__reserved))) { in fscrypt_supported_v2_policy()
258 fscrypt_warn(inode, "Reserved bits set in encryption policy"); in fscrypt_supported_v2_policy()
266 * fscrypt_supported_policy() - check whether an encryption policy is supported
267 * @policy_u: the encryption policy
268 * @inode: the inode on which the policy will be used
270 * Given an encryption policy, check whether all its encryption modes and other
292 * @policy_u: input policy
296 * encryption policy. @nonce must be a new random nonce.
308 const struct fscrypt_policy_v1 *policy = &policy_u->v1; in fscrypt_new_context() local
313 policy->contents_encryption_mode; in fscrypt_new_context()
315 policy->filenames_encryption_mode; in fscrypt_new_context()
316 ctx->flags = policy->flags; in fscrypt_new_context()
318 policy->master_key_descriptor, in fscrypt_new_context()
324 const struct fscrypt_policy_v2 *policy = &policy_u->v2; in fscrypt_new_context() local
329 policy->contents_encryption_mode; in fscrypt_new_context()
331 policy->filenames_encryption_mode; in fscrypt_new_context()
332 ctx->flags = policy->flags; in fscrypt_new_context()
334 policy->master_key_identifier, in fscrypt_new_context()
346 * @policy_u: output policy
355 * This does *not* validate the settings within the policy itself, e.g. the
370 struct fscrypt_policy_v1 *policy = &policy_u->v1; in fscrypt_policy_from_context() local
372 policy->version = FSCRYPT_POLICY_V1; in fscrypt_policy_from_context()
373 policy->contents_encryption_mode = in fscrypt_policy_from_context()
375 policy->filenames_encryption_mode = in fscrypt_policy_from_context()
377 policy->flags = ctx->flags; in fscrypt_policy_from_context()
378 memcpy(policy->master_key_descriptor, in fscrypt_policy_from_context()
380 sizeof(policy->master_key_descriptor)); in fscrypt_policy_from_context()
385 struct fscrypt_policy_v2 *policy = &policy_u->v2; in fscrypt_policy_from_context() local
387 policy->version = FSCRYPT_POLICY_V2; in fscrypt_policy_from_context()
388 policy->contents_encryption_mode = in fscrypt_policy_from_context()
390 policy->filenames_encryption_mode = in fscrypt_policy_from_context()
392 policy->flags = ctx->flags; in fscrypt_policy_from_context()
393 memcpy(policy->__reserved, ctx->__reserved, in fscrypt_policy_from_context()
394 sizeof(policy->__reserved)); in fscrypt_policy_from_context()
395 memcpy(policy->master_key_identifier, in fscrypt_policy_from_context()
397 sizeof(policy->master_key_identifier)); in fscrypt_policy_from_context()
405 /* Retrieve an inode's encryption policy */
406 static int fscrypt_get_policy(struct inode *inode, union fscrypt_policy *policy) in fscrypt_get_policy() argument
414 /* key available, use the cached policy */ in fscrypt_get_policy()
415 *policy = ci->ci_policy; in fscrypt_get_policy()
426 return fscrypt_policy_from_context(policy, &ctx, ret); in fscrypt_get_policy()
430 const union fscrypt_policy *policy) in set_encryption_policy() argument
437 if (!fscrypt_supported_policy(policy, inode)) in set_encryption_policy()
440 switch (policy->version) { in set_encryption_policy()
443 * The original encryption policy version provided no way of in set_encryption_policy()
447 * encryption policy version fixes this and also implies use of in set_encryption_policy()
451 * policy version for all new encrypted directories. in set_encryption_policy()
453 …pr_warn_once("%s (pid %d) is setting deprecated v1 encryption policy; recommend upgrading to v2.\n… in set_encryption_policy()
458 policy->v2.master_key_identifier); in set_encryption_policy()
461 if (policy->v2.flags & FSCRYPT_POLICY_FLAG_IV_INO_LBLK_32) in set_encryption_policy()
462 …pr_warn_once("%s (pid %d) is setting an IV_INO_LBLK_32 encryption policy. This should only be use… in set_encryption_policy()
471 ctxsize = fscrypt_new_context(&ctx, policy, nonce); in set_encryption_policy()
478 union fscrypt_policy policy; in fscrypt_ioctl_set_policy() local
485 if (get_user(policy.version, (const u8 __user *)arg)) in fscrypt_ioctl_set_policy()
488 size = fscrypt_policy_size(&policy); in fscrypt_ioctl_set_policy()
503 version = policy.version; in fscrypt_ioctl_set_policy()
504 if (copy_from_user(&policy, arg, size)) in fscrypt_ioctl_set_policy()
506 policy.version = version; in fscrypt_ioctl_set_policy()
526 ret = set_encryption_policy(inode, &policy); in fscrypt_ioctl_set_policy()
528 (ret == 0 && !fscrypt_policies_equal(&policy, in fscrypt_ioctl_set_policy()
530 /* The file already uses a different encryption policy. */ in fscrypt_ioctl_set_policy()
541 /* Original ioctl version; can only get the original policy version */
544 union fscrypt_policy policy; in fscrypt_ioctl_get_policy() local
547 err = fscrypt_get_policy(file_inode(filp), &policy); in fscrypt_ioctl_get_policy()
551 if (policy.version != FSCRYPT_POLICY_V1) in fscrypt_ioctl_get_policy()
554 if (copy_to_user(arg, &policy, sizeof(policy.v1))) in fscrypt_ioctl_get_policy()
564 union fscrypt_policy *policy = (union fscrypt_policy *)&arg.policy; in fscrypt_ioctl_get_policy_ex() local
568 /* arg is policy_size, then policy */ in fscrypt_ioctl_get_policy_ex()
571 offsetof(typeof(arg), policy)); in fscrypt_ioctl_get_policy_ex()
572 BUILD_BUG_ON(sizeof(arg.policy) != sizeof(*policy)); in fscrypt_ioctl_get_policy_ex()
574 err = fscrypt_get_policy(file_inode(filp), policy); in fscrypt_ioctl_get_policy_ex()
577 policy_size = fscrypt_policy_size(policy); in fscrypt_ioctl_get_policy_ex()
612 * fscrypt_has_permitted_context() - is a file's encryption policy permitted
624 * same encryption policy. The pre-access check is needed to detect potentially
650 * encryption policy. Compare the fscrypt_info structs if the keys are in fscrypt_has_permitted_context()
675 * encryption policy, so that files with an unrecognized encryption in fscrypt_has_permitted_context()
676 * policy can be deleted. in fscrypt_has_permitted_context()
689 * Return the encryption policy that new files in the directory will inherit, or
710 * @inode: inode from which to fetch policy and nonce
768 * @dummy_policy: (input/output) the place to write the dummy policy that will
769 * result from parsing the option. Zero-initialize this. If a policy is
780 union fscrypt_policy *policy; in fscrypt_parse_test_dummy_encryption() local
786 policy = kzalloc(sizeof(*policy), GFP_KERNEL); in fscrypt_parse_test_dummy_encryption()
787 if (!policy) in fscrypt_parse_test_dummy_encryption()
791 policy->version = FSCRYPT_POLICY_V1; in fscrypt_parse_test_dummy_encryption()
792 policy->v1.contents_encryption_mode = FSCRYPT_MODE_AES_256_XTS; in fscrypt_parse_test_dummy_encryption()
793 policy->v1.filenames_encryption_mode = FSCRYPT_MODE_AES_256_CTS; in fscrypt_parse_test_dummy_encryption()
794 memset(policy->v1.master_key_descriptor, 0x42, in fscrypt_parse_test_dummy_encryption()
797 policy->version = FSCRYPT_POLICY_V2; in fscrypt_parse_test_dummy_encryption()
798 policy->v2.contents_encryption_mode = FSCRYPT_MODE_AES_256_XTS; in fscrypt_parse_test_dummy_encryption()
799 policy->v2.filenames_encryption_mode = FSCRYPT_MODE_AES_256_CTS; in fscrypt_parse_test_dummy_encryption()
801 policy->v2.master_key_identifier); in fscrypt_parse_test_dummy_encryption()
809 if (dummy_policy->policy) { in fscrypt_parse_test_dummy_encryption()
810 if (fscrypt_policies_equal(policy, dummy_policy->policy)) in fscrypt_parse_test_dummy_encryption()
816 dummy_policy->policy = policy; in fscrypt_parse_test_dummy_encryption()
817 policy = NULL; in fscrypt_parse_test_dummy_encryption()
820 kfree(policy); in fscrypt_parse_test_dummy_encryption()
827 * @p1: the first test dummy policy (may be unset)
828 * @p2: the second test dummy policy (may be unset)
835 if (!p1->policy && !p2->policy) in fscrypt_dummy_policies_equal()
837 if (!p1->policy || !p2->policy) in fscrypt_dummy_policies_equal()
839 return fscrypt_policies_equal(p1->policy, p2->policy); in fscrypt_dummy_policies_equal()
855 const union fscrypt_policy *policy = fscrypt_get_dummy_policy(sb); in fscrypt_show_test_dummy_encryption() local
858 if (!policy) in fscrypt_show_test_dummy_encryption()
861 vers = policy->version; in fscrypt_show_test_dummy_encryption()