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
135 if (policy->contents_encryption_mode != FSCRYPT_MODE_AES_256_XTS) { 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()
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()
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()
406 static int fscrypt_get_policy(struct inode *inode, union fscrypt_policy *policy) in fscrypt_get_policy() argument
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()
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()
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()
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
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()
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()
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()