Lines Matching refs: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()
172 fscrypt_policy_v2_du_bits(policy, inode)) > 32) { 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()
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()
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()
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()
433 static int fscrypt_get_policy(struct inode *inode, union fscrypt_policy *policy) in fscrypt_get_policy() argument
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()
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()
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()
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
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()
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()
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()