keysetup.c (d2fe97545a1e2d01c0ca0105bdc59002a0d0b130) keysetup.c (ed318a6cc0b620440e65f48eb527dc3df7269ce4)
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * Key setup facility for FS encryption support.
4 *
5 * Copyright (C) 2015, Google, Inc.
6 *
7 * Originally written by Michael Halcrow, Ildar Muslukhov, and Uday Savagaonkar.
8 * Heavily modified since then.

--- 381 unchanged lines hidden (view full) ---

390 return 0;
391
392 res = fscrypt_initialize(inode->i_sb->s_cop->flags);
393 if (res)
394 return res;
395
396 res = inode->i_sb->s_cop->get_context(inode, &ctx, sizeof(ctx));
397 if (res < 0) {
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * Key setup facility for FS encryption support.
4 *
5 * Copyright (C) 2015, Google, Inc.
6 *
7 * Originally written by Michael Halcrow, Ildar Muslukhov, and Uday Savagaonkar.
8 * Heavily modified since then.

--- 381 unchanged lines hidden (view full) ---

390 return 0;
391
392 res = fscrypt_initialize(inode->i_sb->s_cop->flags);
393 if (res)
394 return res;
395
396 res = inode->i_sb->s_cop->get_context(inode, &ctx, sizeof(ctx));
397 if (res < 0) {
398 if (!fscrypt_dummy_context_enabled(inode) ||
399 IS_ENCRYPTED(inode)) {
398 const union fscrypt_context *dummy_ctx =
399 fscrypt_get_dummy_context(inode->i_sb);
400
401 if (IS_ENCRYPTED(inode) || !dummy_ctx) {
400 fscrypt_warn(inode,
401 "Error %d getting encryption context",
402 res);
403 return res;
404 }
405 /* Fake up a context for an unencrypted directory */
402 fscrypt_warn(inode,
403 "Error %d getting encryption context",
404 res);
405 return res;
406 }
407 /* Fake up a context for an unencrypted directory */
406 memset(&ctx, 0, sizeof(ctx));
407 ctx.version = FSCRYPT_CONTEXT_V1;
408 ctx.v1.contents_encryption_mode = FSCRYPT_MODE_AES_256_XTS;
409 ctx.v1.filenames_encryption_mode = FSCRYPT_MODE_AES_256_CTS;
410 memset(ctx.v1.master_key_descriptor, 0x42,
411 FSCRYPT_KEY_DESCRIPTOR_SIZE);
412 res = sizeof(ctx.v1);
408 res = fscrypt_context_size(dummy_ctx);
409 memcpy(&ctx, dummy_ctx, res);
413 }
414
415 crypt_info = kmem_cache_zalloc(fscrypt_info_cachep, GFP_NOFS);
416 if (!crypt_info)
417 return -ENOMEM;
418
419 crypt_info->ci_inode = inode;
420

--- 131 unchanged lines hidden ---
410 }
411
412 crypt_info = kmem_cache_zalloc(fscrypt_info_cachep, GFP_NOFS);
413 if (!crypt_info)
414 return -ENOMEM;
415
416 crypt_info->ci_inode = inode;
417

--- 131 unchanged lines hidden ---