29 #include <linux/module.h>
38 #include <linux/slab.h>
39 #include <linux/magic.h>
49 "Initial verbosity level (0 or 1; defaults to "
50 "0, which is Quiet)");
59 "Number of message buffer elements");
71 "Maximum number of seconds that an operation will "
72 "sleep while waiting for a message response from "
84 "concurrent users of eCryptfs");
119 static int ecryptfs_init_lower_file(
struct dentry *
dentry,
120 struct file **lower_file)
123 struct dentry *lower_dentry = ecryptfs_dentry_to_lower(dentry);
124 struct vfsmount *lower_mnt = ecryptfs_dentry_to_lower_mnt(dentry);
131 "for lower_dentry [0x%p] and lower_mnt [0x%p]; "
132 "rc = [%d]\n", lower_dentry, lower_mnt, rc);
133 (*lower_file) =
NULL;
143 inode_info = ecryptfs_inode_to_private(inode);
148 else if (count == 1) {
149 rc = ecryptfs_init_lower_file(dentry,
162 inode_info = ecryptfs_inode_to_private(inode);
200 static int ecryptfs_init_global_auth_toks(
209 mount_crypt_stat_list) {
212 global_auth_tok->
sig);
215 "session keyring for sig specified in mount "
216 "option: [%s]\n", global_auth_tok->
sig);
228 static void ecryptfs_init_mount_crypt_stat(
231 memset((
void *)mount_crypt_stat, 0,
264 int cipher_name_set = 0;
265 int fn_cipher_name_set = 0;
266 int cipher_key_bytes;
267 int cipher_key_bytes_set = 0;
268 int fn_cipher_key_bytes;
269 int fn_cipher_key_bytes_set = 0;
275 char *cipher_name_dst;
276 char *cipher_name_src;
277 char *fn_cipher_name_dst;
278 char *fn_cipher_name_src;
281 char *cipher_key_bytes_src;
282 char *fn_cipher_key_bytes_src;
291 ecryptfs_init_mount_crypt_stat(mount_crypt_stat);
299 sig_src = args[0].
from;
304 "global sig; rc = [%d]\n", rc);
311 cipher_name_src = args[0].
from;
315 strncpy(cipher_name_dst, cipher_name_src,
321 cipher_key_bytes_src = args[0].
from;
324 &cipher_key_bytes_src, 0);
327 cipher_key_bytes_set = 1;
330 mount_crypt_stat->
flags |=
334 mount_crypt_stat->
flags |=
338 mount_crypt_stat->
flags |=
340 mount_crypt_stat->
flags |=
344 fnek_src = args[0].
from;
356 "global fnek sig [%s]; rc = [%d]\n",
361 mount_crypt_stat->
flags |=
366 fn_cipher_name_src = args[0].
from;
369 strncpy(fn_cipher_name_dst, fn_cipher_name_src,
373 fn_cipher_name_set = 1;
376 fn_cipher_key_bytes_src = args[0].
from;
377 fn_cipher_key_bytes =
379 &fn_cipher_key_bytes_src, 0);
382 fn_cipher_key_bytes_set = 1;
388 mount_crypt_stat->
flags |=
397 "%s: eCryptfs: unrecognized option [%s]\n",
404 "auth tok signature as a mount "
405 "parameter; see the eCryptfs README\n");
408 if (!cipher_name_set) {
416 && !fn_cipher_name_set)
419 if (!cipher_key_bytes_set)
422 && !fn_cipher_key_bytes_set)
431 "eCryptfs doesn't support cipher: %s",
445 "cipher with name = [%s] and key size = [%td]; "
463 "cipher with name = [%s] and key size = [%td]; "
474 rc = ecryptfs_init_global_auth_toks(mount_crypt_stat);
477 "properly register; rc = [%d]\n", rc);
493 const char *dev_name,
void *raw_data)
498 const char *
err =
"Getting sb failed";
504 sbi = kmem_cache_zalloc(ecryptfs_sb_info_cache,
GFP_KERNEL);
510 rc = ecryptfs_parse_options(sbi, raw_data, &check_ruid);
512 err =
"Error parsing options";
526 ecryptfs_set_superblock_private(s, sbi);
534 err =
"Reading sb failed";
540 if (
path.
dentry->d_sb->s_type == &ecryptfs_fs_type) {
543 "eCryptfs explicitly disallowed due to "
544 "known incompatibilities\n");
551 "requested user (uid: %d)\n",
557 ecryptfs_set_superblock_lower(s,
path.
dentry->d_sb);
588 ecryptfs_set_dentry_private(s->
s_root, root_info);
614 static void ecryptfs_kill_block_super(
struct super_block *
sb)
628 .mount = ecryptfs_mount,
629 .kill_sb = ecryptfs_kill_block_super,
639 inode_info_init_once(
void *vptr)
646 static struct ecryptfs_cache_info {
651 } ecryptfs_cache_infos[] = {
654 .name =
"ecryptfs_auth_tok_list_item",
659 .name =
"ecryptfs_file_cache",
664 .name =
"ecryptfs_dentry_info_cache",
669 .name =
"ecryptfs_inode_cache",
671 .ctor = inode_info_init_once,
675 .name =
"ecryptfs_sb_cache",
680 .name =
"ecryptfs_headers",
685 .name =
"ecryptfs_xattr_cache",
690 .name =
"ecryptfs_key_record_cache",
695 .name =
"ecryptfs_key_sig_cache",
700 .name =
"ecryptfs_global_auth_tok_cache",
705 .name =
"ecryptfs_key_tfm_cache",
710 static void ecryptfs_free_kmem_caches(
void)
720 for (i = 0; i <
ARRAY_SIZE(ecryptfs_cache_infos); i++) {
721 struct ecryptfs_cache_info *
info;
723 info = &ecryptfs_cache_infos[
i];
734 static int ecryptfs_init_kmem_caches(
void)
738 for (i = 0; i <
ARRAY_SIZE(ecryptfs_cache_infos); i++) {
739 struct ecryptfs_cache_info *
info;
741 info = &ecryptfs_cache_infos[
i];
744 if (!*(info->cache)) {
745 ecryptfs_free_kmem_caches();
747 "kmem_cache_create failed\n",
755 static struct kobject *ecryptfs_kobj;
774 static int do_sysfs_registration(
void)
779 if (!ecryptfs_kobj) {
787 "Unable to create ecryptfs version attributes\n");
794 static void do_sysfs_unregistration(
void)
800 static int __init ecryptfs_init(
void)
807 "larger than the host's page size, and so "
808 "eCryptfs cannot run on this system. The "
809 "default eCryptfs extent size is [%u] bytes; "
810 "the page size is [%lu] bytes.\n",
815 rc = ecryptfs_init_kmem_caches();
818 "Failed to allocate one or more kmem_cache objects\n");
821 rc = do_sysfs_registration();
824 goto out_free_kmem_caches;
829 "rc = [%d]\n", __func__, rc);
830 goto out_do_sysfs_unregistration;
835 "initialize the communications channel to "
837 goto out_destroy_kthread;
843 goto out_release_messaging;
848 goto out_destroy_crypto;
857 out_release_messaging:
861 out_do_sysfs_unregistration:
862 do_sysfs_unregistration();
863 out_free_kmem_caches:
864 ecryptfs_free_kmem_caches();
869 static void __exit ecryptfs_exit(
void)
879 do_sysfs_unregistration();
881 ecryptfs_free_kmem_caches();