1 // SPDX-License-Identifier: GPL-2.0
3 * Encryption policy functions for per-file encryption support.
5 * Copyright (C) 2015, Google, Inc.
6 * Copyright (C) 2015, Motorola Mobility.
8 * Originally written by Michael Halcrow, 2015.
9 * Modified by Jaegeuk Kim, 2015.
10 * Modified by Eric Biggers, 2019 for v2 policy support.
13 #include <linux/random.h>
14 #include <linux/seq_file.h>
15 #include <linux/string.h>
16 #include <linux/mount.h>
17 #include "fscrypt_private.h"
20 * fscrypt_policies_equal() - check whether two encryption policies are the same
21 * @policy1: the first policy
22 * @policy2: the second policy
24 * Return: %true if equal, else %false
26 bool fscrypt_policies_equal(const union fscrypt_policy *policy1,
27 const union fscrypt_policy *policy2)
29 if (policy1->version != policy2->version)
32 return !memcmp(policy1, policy2, fscrypt_policy_size(policy1));
35 static const union fscrypt_policy *
36 fscrypt_get_dummy_policy(struct super_block *sb)
38 if (!sb->s_cop->get_dummy_policy)
40 return sb->s_cop->get_dummy_policy(sb);
43 static bool fscrypt_valid_enc_modes(u32 contents_mode, u32 filenames_mode)
45 if (contents_mode == FSCRYPT_MODE_AES_256_XTS &&
46 filenames_mode == FSCRYPT_MODE_AES_256_CTS)
49 if (contents_mode == FSCRYPT_MODE_AES_128_CBC &&
50 filenames_mode == FSCRYPT_MODE_AES_128_CTS)
53 if (contents_mode == FSCRYPT_MODE_ADIANTUM &&
54 filenames_mode == FSCRYPT_MODE_ADIANTUM)
60 static bool supported_direct_key_modes(const struct inode *inode,
61 u32 contents_mode, u32 filenames_mode)
63 const struct fscrypt_mode *mode;
65 if (contents_mode != filenames_mode) {
67 "Direct key flag not allowed with different contents and filenames modes");
70 mode = &fscrypt_modes[contents_mode];
72 if (mode->ivsize < offsetofend(union fscrypt_iv, nonce)) {
73 fscrypt_warn(inode, "Direct key flag not allowed with %s",
80 static bool supported_iv_ino_lblk_policy(const struct fscrypt_policy_v2 *policy,
81 const struct inode *inode,
83 int max_ino_bits, int max_lblk_bits)
85 struct super_block *sb = inode->i_sb;
86 int ino_bits = 64, lblk_bits = 64;
89 * IV_INO_LBLK_* exist only because of hardware limitations, and
90 * currently the only known use case for them involves AES-256-XTS.
91 * That's also all we test currently. For these reasons, for now only
92 * allow AES-256-XTS here. This can be relaxed later if a use case for
93 * IV_INO_LBLK_* with other encryption modes arises.
95 if (policy->contents_encryption_mode != FSCRYPT_MODE_AES_256_XTS) {
97 "Can't use %s policy with contents mode other than AES-256-XTS",
103 * It's unsafe to include inode numbers in the IVs if the filesystem can
104 * potentially renumber inodes, e.g. via filesystem shrinking.
106 if (!sb->s_cop->has_stable_inodes ||
107 !sb->s_cop->has_stable_inodes(sb)) {
109 "Can't use %s policy on filesystem '%s' because it doesn't have stable inode numbers",
113 if (sb->s_cop->get_ino_and_lblk_bits)
114 sb->s_cop->get_ino_and_lblk_bits(sb, &ino_bits, &lblk_bits);
115 if (ino_bits > max_ino_bits) {
117 "Can't use %s policy on filesystem '%s' because its inode numbers are too long",
121 if (lblk_bits > max_lblk_bits) {
123 "Can't use %s policy on filesystem '%s' because its block numbers are too long",
130 static bool fscrypt_supported_v1_policy(const struct fscrypt_policy_v1 *policy,
131 const struct inode *inode)
133 if (!fscrypt_valid_enc_modes(policy->contents_encryption_mode,
134 policy->filenames_encryption_mode)) {
136 "Unsupported encryption modes (contents %d, filenames %d)",
137 policy->contents_encryption_mode,
138 policy->filenames_encryption_mode);
142 if (policy->flags & ~(FSCRYPT_POLICY_FLAGS_PAD_MASK |
143 FSCRYPT_POLICY_FLAG_DIRECT_KEY)) {
144 fscrypt_warn(inode, "Unsupported encryption flags (0x%02x)",
149 if ((policy->flags & FSCRYPT_POLICY_FLAG_DIRECT_KEY) &&
150 !supported_direct_key_modes(inode, policy->contents_encryption_mode,
151 policy->filenames_encryption_mode))
154 if (IS_CASEFOLDED(inode)) {
155 /* With v1, there's no way to derive dirhash keys. */
157 "v1 policies can't be used on casefolded directories");
164 static bool fscrypt_supported_v2_policy(const struct fscrypt_policy_v2 *policy,
165 const struct inode *inode)
169 if (!fscrypt_valid_enc_modes(policy->contents_encryption_mode,
170 policy->filenames_encryption_mode)) {
172 "Unsupported encryption modes (contents %d, filenames %d)",
173 policy->contents_encryption_mode,
174 policy->filenames_encryption_mode);
178 if (policy->flags & ~(FSCRYPT_POLICY_FLAGS_PAD_MASK |
179 FSCRYPT_POLICY_FLAG_DIRECT_KEY |
180 FSCRYPT_POLICY_FLAG_IV_INO_LBLK_64 |
181 FSCRYPT_POLICY_FLAG_IV_INO_LBLK_32)) {
182 fscrypt_warn(inode, "Unsupported encryption flags (0x%02x)",
187 count += !!(policy->flags & FSCRYPT_POLICY_FLAG_DIRECT_KEY);
188 count += !!(policy->flags & FSCRYPT_POLICY_FLAG_IV_INO_LBLK_64);
189 count += !!(policy->flags & FSCRYPT_POLICY_FLAG_IV_INO_LBLK_32);
191 fscrypt_warn(inode, "Mutually exclusive encryption flags (0x%02x)",
196 if ((policy->flags & FSCRYPT_POLICY_FLAG_DIRECT_KEY) &&
197 !supported_direct_key_modes(inode, policy->contents_encryption_mode,
198 policy->filenames_encryption_mode))
201 if ((policy->flags & FSCRYPT_POLICY_FLAG_IV_INO_LBLK_64) &&
202 !supported_iv_ino_lblk_policy(policy, inode, "IV_INO_LBLK_64",
207 * IV_INO_LBLK_32 hashes the inode number, so in principle it can
208 * support any ino_bits. However, currently the inode number is gotten
209 * from inode::i_ino which is 'unsigned long'. So for now the
210 * implementation limit is 32 bits.
212 if ((policy->flags & FSCRYPT_POLICY_FLAG_IV_INO_LBLK_32) &&
213 !supported_iv_ino_lblk_policy(policy, inode, "IV_INO_LBLK_32",
217 if (memchr_inv(policy->__reserved, 0, sizeof(policy->__reserved))) {
218 fscrypt_warn(inode, "Reserved bits set in encryption policy");
226 * fscrypt_supported_policy() - check whether an encryption policy is supported
227 * @policy_u: the encryption policy
228 * @inode: the inode on which the policy will be used
230 * Given an encryption policy, check whether all its encryption modes and other
231 * settings are supported by this kernel on the given inode. (But we don't
232 * currently don't check for crypto API support here, so attempting to use an
233 * algorithm not configured into the crypto API will still fail later.)
235 * Return: %true if supported, else %false
237 bool fscrypt_supported_policy(const union fscrypt_policy *policy_u,
238 const struct inode *inode)
240 switch (policy_u->version) {
241 case FSCRYPT_POLICY_V1:
242 return fscrypt_supported_v1_policy(&policy_u->v1, inode);
243 case FSCRYPT_POLICY_V2:
244 return fscrypt_supported_v2_policy(&policy_u->v2, inode);
250 * fscrypt_new_context() - create a new fscrypt_context
251 * @ctx_u: output context
252 * @policy_u: input policy
253 * @nonce: nonce to use
255 * Create an fscrypt_context for an inode that is being assigned the given
256 * encryption policy. @nonce must be a new random nonce.
258 * Return: the size of the new context in bytes.
260 static int fscrypt_new_context(union fscrypt_context *ctx_u,
261 const union fscrypt_policy *policy_u,
262 const u8 nonce[FSCRYPT_FILE_NONCE_SIZE])
264 memset(ctx_u, 0, sizeof(*ctx_u));
266 switch (policy_u->version) {
267 case FSCRYPT_POLICY_V1: {
268 const struct fscrypt_policy_v1 *policy = &policy_u->v1;
269 struct fscrypt_context_v1 *ctx = &ctx_u->v1;
271 ctx->version = FSCRYPT_CONTEXT_V1;
272 ctx->contents_encryption_mode =
273 policy->contents_encryption_mode;
274 ctx->filenames_encryption_mode =
275 policy->filenames_encryption_mode;
276 ctx->flags = policy->flags;
277 memcpy(ctx->master_key_descriptor,
278 policy->master_key_descriptor,
279 sizeof(ctx->master_key_descriptor));
280 memcpy(ctx->nonce, nonce, FSCRYPT_FILE_NONCE_SIZE);
283 case FSCRYPT_POLICY_V2: {
284 const struct fscrypt_policy_v2 *policy = &policy_u->v2;
285 struct fscrypt_context_v2 *ctx = &ctx_u->v2;
287 ctx->version = FSCRYPT_CONTEXT_V2;
288 ctx->contents_encryption_mode =
289 policy->contents_encryption_mode;
290 ctx->filenames_encryption_mode =
291 policy->filenames_encryption_mode;
292 ctx->flags = policy->flags;
293 memcpy(ctx->master_key_identifier,
294 policy->master_key_identifier,
295 sizeof(ctx->master_key_identifier));
296 memcpy(ctx->nonce, nonce, FSCRYPT_FILE_NONCE_SIZE);
304 * fscrypt_policy_from_context() - convert an fscrypt_context to
306 * @policy_u: output policy
307 * @ctx_u: input context
308 * @ctx_size: size of input context in bytes
310 * Given an fscrypt_context, build the corresponding fscrypt_policy.
312 * Return: 0 on success, or -EINVAL if the fscrypt_context has an unrecognized
313 * version number or size.
315 * This does *not* validate the settings within the policy itself, e.g. the
316 * modes, flags, and reserved bits. Use fscrypt_supported_policy() for that.
318 int fscrypt_policy_from_context(union fscrypt_policy *policy_u,
319 const union fscrypt_context *ctx_u,
322 memset(policy_u, 0, sizeof(*policy_u));
324 if (!fscrypt_context_is_valid(ctx_u, ctx_size))
327 switch (ctx_u->version) {
328 case FSCRYPT_CONTEXT_V1: {
329 const struct fscrypt_context_v1 *ctx = &ctx_u->v1;
330 struct fscrypt_policy_v1 *policy = &policy_u->v1;
332 policy->version = FSCRYPT_POLICY_V1;
333 policy->contents_encryption_mode =
334 ctx->contents_encryption_mode;
335 policy->filenames_encryption_mode =
336 ctx->filenames_encryption_mode;
337 policy->flags = ctx->flags;
338 memcpy(policy->master_key_descriptor,
339 ctx->master_key_descriptor,
340 sizeof(policy->master_key_descriptor));
343 case FSCRYPT_CONTEXT_V2: {
344 const struct fscrypt_context_v2 *ctx = &ctx_u->v2;
345 struct fscrypt_policy_v2 *policy = &policy_u->v2;
347 policy->version = FSCRYPT_POLICY_V2;
348 policy->contents_encryption_mode =
349 ctx->contents_encryption_mode;
350 policy->filenames_encryption_mode =
351 ctx->filenames_encryption_mode;
352 policy->flags = ctx->flags;
353 memcpy(policy->__reserved, ctx->__reserved,
354 sizeof(policy->__reserved));
355 memcpy(policy->master_key_identifier,
356 ctx->master_key_identifier,
357 sizeof(policy->master_key_identifier));
365 /* Retrieve an inode's encryption policy */
366 static int fscrypt_get_policy(struct inode *inode, union fscrypt_policy *policy)
368 const struct fscrypt_info *ci;
369 union fscrypt_context ctx;
372 ci = fscrypt_get_info(inode);
374 /* key available, use the cached policy */
375 *policy = ci->ci_policy;
379 if (!IS_ENCRYPTED(inode))
382 ret = inode->i_sb->s_cop->get_context(inode, &ctx, sizeof(ctx));
384 return (ret == -ERANGE) ? -EINVAL : ret;
386 return fscrypt_policy_from_context(policy, &ctx, ret);
389 static int set_encryption_policy(struct inode *inode,
390 const union fscrypt_policy *policy)
392 u8 nonce[FSCRYPT_FILE_NONCE_SIZE];
393 union fscrypt_context ctx;
397 if (!fscrypt_supported_policy(policy, inode))
400 switch (policy->version) {
401 case FSCRYPT_POLICY_V1:
403 * The original encryption policy version provided no way of
404 * verifying that the correct master key was supplied, which was
405 * insecure in scenarios where multiple users have access to the
406 * same encrypted files (even just read-only access). The new
407 * encryption policy version fixes this and also implies use of
408 * an improved key derivation function and allows non-root users
409 * to securely remove keys. So as long as compatibility with
410 * old kernels isn't required, it is recommended to use the new
411 * policy version for all new encrypted directories.
413 pr_warn_once("%s (pid %d) is setting deprecated v1 encryption policy; recommend upgrading to v2.\n",
414 current->comm, current->pid);
416 case FSCRYPT_POLICY_V2:
417 err = fscrypt_verify_key_added(inode->i_sb,
418 policy->v2.master_key_identifier);
421 if (policy->v2.flags & FSCRYPT_POLICY_FLAG_IV_INO_LBLK_32)
422 pr_warn_once("%s (pid %d) is setting an IV_INO_LBLK_32 encryption policy. This should only be used if there are certain hardware limitations.\n",
423 current->comm, current->pid);
430 get_random_bytes(nonce, FSCRYPT_FILE_NONCE_SIZE);
431 ctxsize = fscrypt_new_context(&ctx, policy, nonce);
433 return inode->i_sb->s_cop->set_context(inode, &ctx, ctxsize, NULL);
436 int fscrypt_ioctl_set_policy(struct file *filp, const void __user *arg)
438 union fscrypt_policy policy;
439 union fscrypt_policy existing_policy;
440 struct inode *inode = file_inode(filp);
445 if (get_user(policy.version, (const u8 __user *)arg))
448 size = fscrypt_policy_size(&policy);
453 * We should just copy the remaining 'size - 1' bytes here, but a
454 * bizarre bug in gcc 7 and earlier (fixed by gcc r255731) causes gcc to
455 * think that size can be 0 here (despite the check above!) *and* that
456 * it's a compile-time constant. Thus it would think copy_from_user()
457 * is passed compile-time constant ULONG_MAX, causing the compile-time
458 * buffer overflow check to fail, breaking the build. This only occurred
459 * when building an i386 kernel with -Os and branch profiling enabled.
461 * Work around it by just copying the first byte again...
463 version = policy.version;
464 if (copy_from_user(&policy, arg, size))
466 policy.version = version;
468 if (!inode_owner_or_capable(&init_user_ns, inode))
471 ret = mnt_want_write_file(filp);
477 ret = fscrypt_get_policy(inode, &existing_policy);
478 if (ret == -ENODATA) {
479 if (!S_ISDIR(inode->i_mode))
481 else if (IS_DEADDIR(inode))
483 else if (!inode->i_sb->s_cop->empty_dir(inode))
486 ret = set_encryption_policy(inode, &policy);
487 } else if (ret == -EINVAL ||
488 (ret == 0 && !fscrypt_policies_equal(&policy,
489 &existing_policy))) {
490 /* The file already uses a different encryption policy. */
496 mnt_drop_write_file(filp);
499 EXPORT_SYMBOL(fscrypt_ioctl_set_policy);
501 /* Original ioctl version; can only get the original policy version */
502 int fscrypt_ioctl_get_policy(struct file *filp, void __user *arg)
504 union fscrypt_policy policy;
507 err = fscrypt_get_policy(file_inode(filp), &policy);
511 if (policy.version != FSCRYPT_POLICY_V1)
514 if (copy_to_user(arg, &policy, sizeof(policy.v1)))
518 EXPORT_SYMBOL(fscrypt_ioctl_get_policy);
520 /* Extended ioctl version; can get policies of any version */
521 int fscrypt_ioctl_get_policy_ex(struct file *filp, void __user *uarg)
523 struct fscrypt_get_policy_ex_arg arg;
524 union fscrypt_policy *policy = (union fscrypt_policy *)&arg.policy;
528 /* arg is policy_size, then policy */
529 BUILD_BUG_ON(offsetof(typeof(arg), policy_size) != 0);
530 BUILD_BUG_ON(offsetofend(typeof(arg), policy_size) !=
531 offsetof(typeof(arg), policy));
532 BUILD_BUG_ON(sizeof(arg.policy) != sizeof(*policy));
534 err = fscrypt_get_policy(file_inode(filp), policy);
537 policy_size = fscrypt_policy_size(policy);
539 if (copy_from_user(&arg, uarg, sizeof(arg.policy_size)))
542 if (policy_size > arg.policy_size)
544 arg.policy_size = policy_size;
546 if (copy_to_user(uarg, &arg, sizeof(arg.policy_size) + policy_size))
550 EXPORT_SYMBOL_GPL(fscrypt_ioctl_get_policy_ex);
552 /* FS_IOC_GET_ENCRYPTION_NONCE: retrieve file's encryption nonce for testing */
553 int fscrypt_ioctl_get_nonce(struct file *filp, void __user *arg)
555 struct inode *inode = file_inode(filp);
556 union fscrypt_context ctx;
559 ret = inode->i_sb->s_cop->get_context(inode, &ctx, sizeof(ctx));
562 if (!fscrypt_context_is_valid(&ctx, ret))
564 if (copy_to_user(arg, fscrypt_context_nonce(&ctx),
565 FSCRYPT_FILE_NONCE_SIZE))
569 EXPORT_SYMBOL_GPL(fscrypt_ioctl_get_nonce);
572 * fscrypt_has_permitted_context() - is a file's encryption policy permitted
573 * within its directory?
575 * @parent: inode for parent directory
576 * @child: inode for file being looked up, opened, or linked into @parent
578 * Filesystems must call this before permitting access to an inode in a
579 * situation where the parent directory is encrypted (either before allowing
580 * ->lookup() to succeed, or for a regular file before allowing it to be opened)
581 * and before any operation that involves linking an inode into an encrypted
582 * directory, including link, rename, and cross rename. It enforces the
583 * constraint that within a given encrypted directory tree, all files use the
584 * same encryption policy. The pre-access check is needed to detect potentially
585 * malicious offline violations of this constraint, while the link and rename
586 * checks are needed to prevent online violations of this constraint.
588 * Return: 1 if permitted, 0 if forbidden.
590 int fscrypt_has_permitted_context(struct inode *parent, struct inode *child)
592 union fscrypt_policy parent_policy, child_policy;
595 /* No restrictions on file types which are never encrypted */
596 if (!S_ISREG(child->i_mode) && !S_ISDIR(child->i_mode) &&
597 !S_ISLNK(child->i_mode))
600 /* No restrictions if the parent directory is unencrypted */
601 if (!IS_ENCRYPTED(parent))
604 /* Encrypted directories must not contain unencrypted files */
605 if (!IS_ENCRYPTED(child))
609 * Both parent and child are encrypted, so verify they use the same
610 * encryption policy. Compare the fscrypt_info structs if the keys are
611 * available, otherwise retrieve and compare the fscrypt_contexts.
613 * Note that the fscrypt_context retrieval will be required frequently
614 * when accessing an encrypted directory tree without the key.
615 * Performance-wise this is not a big deal because we already don't
616 * really optimize for file access without the key (to the extent that
617 * such access is even possible), given that any attempted access
618 * already causes a fscrypt_context retrieval and keyring search.
620 * In any case, if an unexpected error occurs, fall back to "forbidden".
623 err = fscrypt_get_encryption_info(parent, true);
626 err = fscrypt_get_encryption_info(child, true);
630 err1 = fscrypt_get_policy(parent, &parent_policy);
631 err2 = fscrypt_get_policy(child, &child_policy);
634 * Allow the case where the parent and child both have an unrecognized
635 * encryption policy, so that files with an unrecognized encryption
636 * policy can be deleted.
638 if (err1 == -EINVAL && err2 == -EINVAL)
644 return fscrypt_policies_equal(&parent_policy, &child_policy);
646 EXPORT_SYMBOL(fscrypt_has_permitted_context);
649 * Return the encryption policy that new files in the directory will inherit, or
650 * NULL if none, or an ERR_PTR() on error. If the directory is encrypted, also
651 * ensure that its key is set up, so that the new filename can be encrypted.
653 const union fscrypt_policy *fscrypt_policy_to_inherit(struct inode *dir)
657 if (IS_ENCRYPTED(dir)) {
658 err = fscrypt_require_key(dir);
661 return &dir->i_crypt_info->ci_policy;
664 return fscrypt_get_dummy_policy(dir->i_sb);
668 * fscrypt_set_context() - Set the fscrypt context of a new inode
669 * @inode: a new inode
670 * @fs_data: private data given by FS and passed to ->set_context()
672 * This should be called after fscrypt_prepare_new_inode(), generally during a
673 * filesystem transaction. Everything here must be %GFP_NOFS-safe.
675 * Return: 0 on success, -errno on failure
677 int fscrypt_set_context(struct inode *inode, void *fs_data)
679 struct fscrypt_info *ci = inode->i_crypt_info;
680 union fscrypt_context ctx;
683 /* fscrypt_prepare_new_inode() should have set up the key already. */
684 if (WARN_ON_ONCE(!ci))
687 BUILD_BUG_ON(sizeof(ctx) != FSCRYPT_SET_CONTEXT_MAX_SIZE);
688 ctxsize = fscrypt_new_context(&ctx, &ci->ci_policy, ci->ci_nonce);
691 * This may be the first time the inode number is available, so do any
692 * delayed key setup that requires the inode number.
694 if (ci->ci_policy.version == FSCRYPT_POLICY_V2 &&
695 (ci->ci_policy.v2.flags & FSCRYPT_POLICY_FLAG_IV_INO_LBLK_32)) {
696 const struct fscrypt_master_key *mk =
697 ci->ci_master_key->payload.data[0];
699 fscrypt_hash_inode_number(ci, mk);
702 return inode->i_sb->s_cop->set_context(inode, &ctx, ctxsize, fs_data);
704 EXPORT_SYMBOL_GPL(fscrypt_set_context);
707 * fscrypt_set_test_dummy_encryption() - handle '-o test_dummy_encryption'
708 * @sb: the filesystem on which test_dummy_encryption is being specified
709 * @arg: the argument to the test_dummy_encryption option. May be NULL.
710 * @dummy_policy: the filesystem's current dummy policy (input/output, see
713 * Handle the test_dummy_encryption mount option by creating a dummy encryption
714 * policy, saving it in @dummy_policy, and adding the corresponding dummy
715 * encryption key to the filesystem. If the @dummy_policy is already set, then
716 * instead validate that it matches @arg. Don't support changing it via
717 * remount, as that is difficult to do safely.
719 * Return: 0 on success (dummy policy set, or the same policy is already set);
720 * -EEXIST if a different dummy policy is already set;
721 * or another -errno value.
723 int fscrypt_set_test_dummy_encryption(struct super_block *sb, const char *arg,
724 struct fscrypt_dummy_policy *dummy_policy)
726 struct fscrypt_key_specifier key_spec = { 0 };
728 union fscrypt_policy *policy = NULL;
734 if (!strcmp(arg, "v1")) {
735 version = FSCRYPT_POLICY_V1;
736 key_spec.type = FSCRYPT_KEY_SPEC_TYPE_DESCRIPTOR;
737 memset(key_spec.u.descriptor, 0x42,
738 FSCRYPT_KEY_DESCRIPTOR_SIZE);
739 } else if (!strcmp(arg, "v2")) {
740 version = FSCRYPT_POLICY_V2;
741 key_spec.type = FSCRYPT_KEY_SPEC_TYPE_IDENTIFIER;
742 /* key_spec.u.identifier gets filled in when adding the key */
748 policy = kzalloc(sizeof(*policy), GFP_KERNEL);
754 err = fscrypt_add_test_dummy_key(sb, &key_spec);
758 policy->version = version;
759 switch (policy->version) {
760 case FSCRYPT_POLICY_V1:
761 policy->v1.contents_encryption_mode = FSCRYPT_MODE_AES_256_XTS;
762 policy->v1.filenames_encryption_mode = FSCRYPT_MODE_AES_256_CTS;
763 memcpy(policy->v1.master_key_descriptor, key_spec.u.descriptor,
764 FSCRYPT_KEY_DESCRIPTOR_SIZE);
766 case FSCRYPT_POLICY_V2:
767 policy->v2.contents_encryption_mode = FSCRYPT_MODE_AES_256_XTS;
768 policy->v2.filenames_encryption_mode = FSCRYPT_MODE_AES_256_CTS;
769 memcpy(policy->v2.master_key_identifier, key_spec.u.identifier,
770 FSCRYPT_KEY_IDENTIFIER_SIZE);
778 if (dummy_policy->policy) {
779 if (fscrypt_policies_equal(policy, dummy_policy->policy))
785 dummy_policy->policy = policy;
792 EXPORT_SYMBOL_GPL(fscrypt_set_test_dummy_encryption);
795 * fscrypt_show_test_dummy_encryption() - show '-o test_dummy_encryption'
796 * @seq: the seq_file to print the option to
797 * @sep: the separator character to use
798 * @sb: the filesystem whose options are being shown
800 * Show the test_dummy_encryption mount option, if it was specified.
801 * This is mainly used for /proc/mounts.
803 void fscrypt_show_test_dummy_encryption(struct seq_file *seq, char sep,
804 struct super_block *sb)
806 const union fscrypt_policy *policy = fscrypt_get_dummy_policy(sb);
812 vers = policy->version;
813 if (vers == FSCRYPT_POLICY_V1) /* Handle numbering quirk */
816 seq_printf(seq, "%ctest_dummy_encryption=v%d", sep, vers);
818 EXPORT_SYMBOL_GPL(fscrypt_show_test_dummy_encryption);