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
123 const char *type = (policy->flags & FSCRYPT_POLICY_FLAG_IV_INO_LBLK_64) in supported_iv_ino_lblk_policy()
134 if (policy->contents_encryption_mode != FSCRYPT_MODE_AES_256_XTS) { in supported_iv_ino_lblk_policy()
136 "Can't use %s policy with contents mode other than AES-256-XTS", in supported_iv_ino_lblk_policy()
148 "Can't use %s policy on filesystem '%s' because it doesn't have stable inode numbers", in supported_iv_ino_lblk_policy()
162 "Can't use %s policy on filesystem '%s' because its inode numbers are too long", in supported_iv_ino_lblk_policy()
172 fscrypt_policy_v2_du_bits(policy, inode)) > 32) { in supported_iv_ino_lblk_policy()
174 "Can't use %s policy on filesystem '%s' because its maximum file size is too large", in supported_iv_ino_lblk_policy()
181 static bool fscrypt_supported_v1_policy(const struct fscrypt_policy_v1 *policy, in fscrypt_supported_v1_policy() argument
184 if (!fscrypt_valid_enc_modes_v1(policy->contents_encryption_mode, in fscrypt_supported_v1_policy()
185 policy->filenames_encryption_mode)) { in fscrypt_supported_v1_policy()
188 policy->contents_encryption_mode, in fscrypt_supported_v1_policy()
189 policy->filenames_encryption_mode); in fscrypt_supported_v1_policy()
193 if (policy->flags & ~(FSCRYPT_POLICY_FLAGS_PAD_MASK | in fscrypt_supported_v1_policy()
196 policy->flags); in fscrypt_supported_v1_policy()
200 if ((policy->flags & FSCRYPT_POLICY_FLAG_DIRECT_KEY) && in fscrypt_supported_v1_policy()
201 !supported_direct_key_modes(inode, policy->contents_encryption_mode, in fscrypt_supported_v1_policy()
202 policy->filenames_encryption_mode)) in fscrypt_supported_v1_policy()
215 static bool fscrypt_supported_v2_policy(const struct fscrypt_policy_v2 *policy, in fscrypt_supported_v2_policy() argument
220 if (!fscrypt_valid_enc_modes_v2(policy->contents_encryption_mode, in fscrypt_supported_v2_policy()
221 policy->filenames_encryption_mode)) { in fscrypt_supported_v2_policy()
224 policy->contents_encryption_mode, in fscrypt_supported_v2_policy()
225 policy->filenames_encryption_mode); in fscrypt_supported_v2_policy()
229 if (policy->flags & ~(FSCRYPT_POLICY_FLAGS_PAD_MASK | in fscrypt_supported_v2_policy()
234 policy->flags); in fscrypt_supported_v2_policy()
238 count += !!(policy->flags & FSCRYPT_POLICY_FLAG_DIRECT_KEY); in fscrypt_supported_v2_policy()
239 count += !!(policy->flags & FSCRYPT_POLICY_FLAG_IV_INO_LBLK_64); in fscrypt_supported_v2_policy()
240 count += !!(policy->flags & FSCRYPT_POLICY_FLAG_IV_INO_LBLK_32); in fscrypt_supported_v2_policy()
243 policy->flags); in fscrypt_supported_v2_policy()
247 if (policy->log2_data_unit_size) { in fscrypt_supported_v2_policy()
253 if (policy->log2_data_unit_size > inode->i_blkbits || in fscrypt_supported_v2_policy()
254 policy->log2_data_unit_size < SECTOR_SHIFT /* 9 */) { in fscrypt_supported_v2_policy()
256 "Unsupported log2_data_unit_size in encryption policy: %d", in fscrypt_supported_v2_policy()
257 policy->log2_data_unit_size); in fscrypt_supported_v2_policy()
260 if (policy->log2_data_unit_size != inode->i_blkbits && in fscrypt_supported_v2_policy()
261 (policy->flags & FSCRYPT_POLICY_FLAG_IV_INO_LBLK_32)) { in fscrypt_supported_v2_policy()
272 if ((policy->flags & FSCRYPT_POLICY_FLAG_DIRECT_KEY) && in fscrypt_supported_v2_policy()
273 !supported_direct_key_modes(inode, policy->contents_encryption_mode, in fscrypt_supported_v2_policy()
274 policy->filenames_encryption_mode)) in fscrypt_supported_v2_policy()
277 if ((policy->flags & (FSCRYPT_POLICY_FLAG_IV_INO_LBLK_64 | in fscrypt_supported_v2_policy()
279 !supported_iv_ino_lblk_policy(policy, inode)) in fscrypt_supported_v2_policy()
282 if (memchr_inv(policy->__reserved, 0, sizeof(policy->__reserved))) { in fscrypt_supported_v2_policy()
283 fscrypt_warn(inode, "Reserved bits set in encryption policy"); in fscrypt_supported_v2_policy()
291 * fscrypt_supported_policy() - check whether an encryption policy is supported
292 * @policy_u: the encryption policy
293 * @inode: the inode on which the policy will be used
295 * Given an encryption policy, check whether all its encryption modes and other
317 * @policy_u: input policy
321 * encryption policy. @nonce must be a new random nonce.
333 const struct fscrypt_policy_v1 *policy = &policy_u->v1; in fscrypt_new_context() local
338 policy->contents_encryption_mode; in fscrypt_new_context()
340 policy->filenames_encryption_mode; in fscrypt_new_context()
341 ctx->flags = policy->flags; in fscrypt_new_context()
343 policy->master_key_descriptor, in fscrypt_new_context()
349 const struct fscrypt_policy_v2 *policy = &policy_u->v2; in fscrypt_new_context() local
354 policy->contents_encryption_mode; in fscrypt_new_context()
356 policy->filenames_encryption_mode; in fscrypt_new_context()
357 ctx->flags = policy->flags; in fscrypt_new_context()
358 ctx->log2_data_unit_size = policy->log2_data_unit_size; in fscrypt_new_context()
360 policy->master_key_identifier, in fscrypt_new_context()
372 * @policy_u: output policy
381 * This does *not* validate the settings within the policy itself, e.g. the
396 struct fscrypt_policy_v1 *policy = &policy_u->v1; in fscrypt_policy_from_context() local
398 policy->version = FSCRYPT_POLICY_V1; in fscrypt_policy_from_context()
399 policy->contents_encryption_mode = in fscrypt_policy_from_context()
401 policy->filenames_encryption_mode = in fscrypt_policy_from_context()
403 policy->flags = ctx->flags; in fscrypt_policy_from_context()
404 memcpy(policy->master_key_descriptor, in fscrypt_policy_from_context()
406 sizeof(policy->master_key_descriptor)); in fscrypt_policy_from_context()
411 struct fscrypt_policy_v2 *policy = &policy_u->v2; in fscrypt_policy_from_context() local
413 policy->version = FSCRYPT_POLICY_V2; in fscrypt_policy_from_context()
414 policy->contents_encryption_mode = in fscrypt_policy_from_context()
416 policy->filenames_encryption_mode = in fscrypt_policy_from_context()
418 policy->flags = ctx->flags; in fscrypt_policy_from_context()
419 policy->log2_data_unit_size = ctx->log2_data_unit_size; in fscrypt_policy_from_context()
420 memcpy(policy->__reserved, ctx->__reserved, in fscrypt_policy_from_context()
421 sizeof(policy->__reserved)); in fscrypt_policy_from_context()
422 memcpy(policy->master_key_identifier, in fscrypt_policy_from_context()
424 sizeof(policy->master_key_identifier)); in fscrypt_policy_from_context()
432 /* Retrieve an inode's encryption policy */
433 static int fscrypt_get_policy(struct inode *inode, union fscrypt_policy *policy) in fscrypt_get_policy() argument
441 /* key available, use the cached policy */ in fscrypt_get_policy()
442 *policy = ci->ci_policy; in fscrypt_get_policy()
453 return fscrypt_policy_from_context(policy, &ctx, ret); in fscrypt_get_policy()
457 const union fscrypt_policy *policy) in set_encryption_policy() argument
464 if (!fscrypt_supported_policy(policy, inode)) in set_encryption_policy()
467 switch (policy->version) { in set_encryption_policy()
470 * The original encryption policy version provided no way of in set_encryption_policy()
474 * encryption policy version fixes this and also implies use of in set_encryption_policy()
478 * policy version for all new encrypted directories. in set_encryption_policy()
480 …pr_warn_once("%s (pid %d) is setting deprecated v1 encryption policy; recommend upgrading to v2.\n… in set_encryption_policy()
485 policy->v2.master_key_identifier); in set_encryption_policy()
488 if (policy->v2.flags & FSCRYPT_POLICY_FLAG_IV_INO_LBLK_32) in set_encryption_policy()
489 …pr_warn_once("%s (pid %d) is setting an IV_INO_LBLK_32 encryption policy. This should only be use… in set_encryption_policy()
498 ctxsize = fscrypt_new_context(&ctx, policy, nonce); in set_encryption_policy()
505 union fscrypt_policy policy; in fscrypt_ioctl_set_policy() local
512 if (get_user(policy.version, (const u8 __user *)arg)) in fscrypt_ioctl_set_policy()
515 size = fscrypt_policy_size(&policy); in fscrypt_ioctl_set_policy()
530 version = policy.version; in fscrypt_ioctl_set_policy()
531 if (copy_from_user(&policy, arg, size)) in fscrypt_ioctl_set_policy()
533 policy.version = version; in fscrypt_ioctl_set_policy()
553 ret = set_encryption_policy(inode, &policy); in fscrypt_ioctl_set_policy()
555 (ret == 0 && !fscrypt_policies_equal(&policy, in fscrypt_ioctl_set_policy()
557 /* The file already uses a different encryption policy. */ in fscrypt_ioctl_set_policy()
568 /* Original ioctl version; can only get the original policy version */
571 union fscrypt_policy policy; in fscrypt_ioctl_get_policy() local
574 err = fscrypt_get_policy(file_inode(filp), &policy); in fscrypt_ioctl_get_policy()
578 if (policy.version != FSCRYPT_POLICY_V1) in fscrypt_ioctl_get_policy()
581 if (copy_to_user(arg, &policy, sizeof(policy.v1))) in fscrypt_ioctl_get_policy()
591 union fscrypt_policy *policy = (union fscrypt_policy *)&arg.policy; in fscrypt_ioctl_get_policy_ex() local
595 /* arg is policy_size, then policy */ in fscrypt_ioctl_get_policy_ex()
598 offsetof(typeof(arg), policy)); in fscrypt_ioctl_get_policy_ex()
599 BUILD_BUG_ON(sizeof(arg.policy) != sizeof(*policy)); in fscrypt_ioctl_get_policy_ex()
601 err = fscrypt_get_policy(file_inode(filp), policy); in fscrypt_ioctl_get_policy_ex()
604 policy_size = fscrypt_policy_size(policy); in fscrypt_ioctl_get_policy_ex()
639 * fscrypt_has_permitted_context() - is a file's encryption policy permitted
651 * same encryption policy. The pre-access check is needed to detect potentially
677 * encryption policy. Compare the cached policies if the keys are in fscrypt_has_permitted_context()
702 * encryption policy, so that files with an unrecognized encryption in fscrypt_has_permitted_context()
703 * policy can be deleted. in fscrypt_has_permitted_context()
716 * Return the encryption policy that new files in the directory will inherit, or
737 * @inode: inode from which to fetch policy and nonce
795 * @dummy_policy: (input/output) the place to write the dummy policy that will
796 * result from parsing the option. Zero-initialize this. If a policy is
807 union fscrypt_policy *policy; in fscrypt_parse_test_dummy_encryption() local
813 policy = kzalloc(sizeof(*policy), GFP_KERNEL); in fscrypt_parse_test_dummy_encryption()
814 if (!policy) in fscrypt_parse_test_dummy_encryption()
818 policy->version = FSCRYPT_POLICY_V1; in fscrypt_parse_test_dummy_encryption()
819 policy->v1.contents_encryption_mode = FSCRYPT_MODE_AES_256_XTS; in fscrypt_parse_test_dummy_encryption()
820 policy->v1.filenames_encryption_mode = FSCRYPT_MODE_AES_256_CTS; in fscrypt_parse_test_dummy_encryption()
821 memset(policy->v1.master_key_descriptor, 0x42, in fscrypt_parse_test_dummy_encryption()
824 policy->version = FSCRYPT_POLICY_V2; in fscrypt_parse_test_dummy_encryption()
825 policy->v2.contents_encryption_mode = FSCRYPT_MODE_AES_256_XTS; in fscrypt_parse_test_dummy_encryption()
826 policy->v2.filenames_encryption_mode = FSCRYPT_MODE_AES_256_CTS; in fscrypt_parse_test_dummy_encryption()
828 policy->v2.master_key_identifier); in fscrypt_parse_test_dummy_encryption()
836 if (dummy_policy->policy) { in fscrypt_parse_test_dummy_encryption()
837 if (fscrypt_policies_equal(policy, dummy_policy->policy)) in fscrypt_parse_test_dummy_encryption()
843 dummy_policy->policy = policy; in fscrypt_parse_test_dummy_encryption()
844 policy = NULL; in fscrypt_parse_test_dummy_encryption()
847 kfree(policy); in fscrypt_parse_test_dummy_encryption()
854 * @p1: the first test dummy policy (may be unset)
855 * @p2: the second test dummy policy (may be unset)
862 if (!p1->policy && !p2->policy) in fscrypt_dummy_policies_equal()
864 if (!p1->policy || !p2->policy) in fscrypt_dummy_policies_equal()
866 return fscrypt_policies_equal(p1->policy, p2->policy); in fscrypt_dummy_policies_equal()
882 const union fscrypt_policy *policy = fscrypt_get_dummy_policy(sb); in fscrypt_show_test_dummy_encryption() local
885 if (!policy) in fscrypt_show_test_dummy_encryption()
888 vers = policy->version; in fscrypt_show_test_dummy_encryption()