2 * eCryptfs: Linux filesystem encryption layer
4 * Copyright (C) 1997-2003 Erez Zadok
5 * Copyright (C) 2001-2003 Stony Brook University
6 * Copyright (C) 2004-2007 International Business Machines Corp.
7 * Author(s): Michael A. Halcrow <mahalcro@us.ibm.com>
8 * Michael C. Thompson <mcthomps@us.ibm.com>
9 * Tyler Hicks <tyhicks@ou.edu>
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License as
13 * published by the Free Software Foundation; either version 2 of the
14 * License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
27 #include <linux/dcache.h>
28 #include <linux/file.h>
29 #include <linux/module.h>
30 #include <linux/namei.h>
31 #include <linux/skbuff.h>
32 #include <linux/crypto.h>
33 #include <linux/netlink.h>
34 #include <linux/mount.h>
35 #include <linux/pagemap.h>
36 #include <linux/key.h>
37 #include <linux/parser.h>
38 #include <linux/fs_stack.h>
39 #include "ecryptfs_kernel.h"
42 * Module parameter that defines the ecryptfs_verbosity level.
44 int ecryptfs_verbosity = 0;
46 module_param(ecryptfs_verbosity, int, 0);
47 MODULE_PARM_DESC(ecryptfs_verbosity,
48 "Initial verbosity level (0 or 1; defaults to "
49 "0, which is Quiet)");
52 * Module parameter that defines the number of netlink message buffer
55 unsigned int ecryptfs_message_buf_len = ECRYPTFS_DEFAULT_MSG_CTX_ELEMS;
57 module_param(ecryptfs_message_buf_len, uint, 0);
58 MODULE_PARM_DESC(ecryptfs_message_buf_len,
59 "Number of message buffer elements");
62 * Module parameter that defines the maximum guaranteed amount of time to wait
63 * for a response through netlink. The actual sleep time will be, more than
64 * likely, a small amount greater than this specified value, but only less if
65 * the netlink message successfully arrives.
67 signed long ecryptfs_message_wait_timeout = ECRYPTFS_MAX_MSG_CTX_TTL / HZ;
69 module_param(ecryptfs_message_wait_timeout, long, 0);
70 MODULE_PARM_DESC(ecryptfs_message_wait_timeout,
71 "Maximum number of seconds that an operation will "
72 "sleep while waiting for a message response from "
76 * Module parameter that is an estimate of the maximum number of users
77 * that will be concurrently using eCryptfs. Set this to the right
78 * value to balance performance and memory use.
80 unsigned int ecryptfs_number_of_users = ECRYPTFS_DEFAULT_NUM_USERS;
82 module_param(ecryptfs_number_of_users, uint, 0);
83 MODULE_PARM_DESC(ecryptfs_number_of_users, "An estimate of the number of "
84 "concurrent users of eCryptfs");
86 unsigned int ecryptfs_transport = ECRYPTFS_DEFAULT_TRANSPORT;
88 void __ecryptfs_printk(const char *fmt, ...)
92 if (fmt[1] == '7') { /* KERN_DEBUG */
93 if (ecryptfs_verbosity >= 1)
101 * ecryptfs_init_persistent_file
102 * @ecryptfs_dentry: Fully initialized eCryptfs dentry object, with
103 * the lower dentry and the lower mount set
105 * eCryptfs only ever keeps a single open file for every lower
106 * inode. All I/O operations to the lower inode occur through that
107 * file. When the first eCryptfs dentry that interposes with the first
108 * lower dentry for that inode is created, this function creates the
109 * persistent file struct and associates it with the eCryptfs
110 * inode. When the eCryptfs inode is destroyed, the file is closed.
112 * The persistent file will be opened with read/write permissions, if
113 * possible. Otherwise, it is opened read-only.
115 * This function does nothing if a lower persistent file is already
116 * associated with the eCryptfs inode.
118 * Returns zero on success; non-zero otherwise
120 static int ecryptfs_init_persistent_file(struct dentry *ecryptfs_dentry)
122 struct ecryptfs_inode_info *inode_info =
123 ecryptfs_inode_to_private(ecryptfs_dentry->d_inode);
126 mutex_lock(&inode_info->lower_file_mutex);
127 if (!inode_info->lower_file) {
128 struct dentry *lower_dentry;
129 struct vfsmount *lower_mnt =
130 ecryptfs_dentry_to_lower_mnt(ecryptfs_dentry);
132 lower_dentry = ecryptfs_dentry_to_lower(ecryptfs_dentry);
133 rc = ecryptfs_privileged_open(&inode_info->lower_file,
134 lower_dentry, lower_mnt);
135 if (rc || IS_ERR(inode_info->lower_file)) {
136 printk(KERN_ERR "Error opening lower persistent file "
137 "for lower_dentry [0x%p] and lower_mnt [0x%p]; "
138 "rc = [%d]\n", lower_dentry, lower_mnt, rc);
139 rc = PTR_ERR(inode_info->lower_file);
140 inode_info->lower_file = NULL;
143 mutex_unlock(&inode_info->lower_file_mutex);
149 * @lower_dentry: Existing dentry in the lower filesystem
150 * @dentry: ecryptfs' dentry
151 * @sb: ecryptfs's super_block
152 * @flag: If set to true, then d_add is called, else d_instantiate is called
154 * Interposes upper and lower dentries.
156 * Returns zero on success; non-zero otherwise
158 int ecryptfs_interpose(struct dentry *lower_dentry, struct dentry *dentry,
159 struct super_block *sb, int flag)
161 struct inode *lower_inode;
165 lower_inode = lower_dentry->d_inode;
166 if (lower_inode->i_sb != ecryptfs_superblock_to_lower(sb)) {
170 if (!igrab(lower_inode)) {
174 inode = iget5_locked(sb, (unsigned long)lower_inode,
175 ecryptfs_inode_test, ecryptfs_inode_set,
182 if (inode->i_state & I_NEW)
183 unlock_new_inode(inode);
186 if (S_ISLNK(lower_inode->i_mode))
187 inode->i_op = &ecryptfs_symlink_iops;
188 else if (S_ISDIR(lower_inode->i_mode))
189 inode->i_op = &ecryptfs_dir_iops;
190 if (S_ISDIR(lower_inode->i_mode))
191 inode->i_fop = &ecryptfs_dir_fops;
192 if (special_file(lower_inode->i_mode))
193 init_special_inode(inode, lower_inode->i_mode,
194 lower_inode->i_rdev);
195 dentry->d_op = &ecryptfs_dops;
197 d_add(dentry, inode);
199 d_instantiate(dentry, inode);
200 fsstack_copy_attr_all(inode, lower_inode, NULL);
201 /* This size will be overwritten for real files w/ headers and
203 fsstack_copy_inode_size(inode, lower_inode);
204 rc = ecryptfs_init_persistent_file(dentry);
206 printk(KERN_ERR "%s: Error attempting to initialize the "
207 "persistent file for the dentry with name [%s]; "
208 "rc = [%d]\n", __func__, dentry->d_name.name, rc);
215 enum { ecryptfs_opt_sig, ecryptfs_opt_ecryptfs_sig,
216 ecryptfs_opt_cipher, ecryptfs_opt_ecryptfs_cipher,
217 ecryptfs_opt_ecryptfs_key_bytes,
218 ecryptfs_opt_passthrough, ecryptfs_opt_xattr_metadata,
219 ecryptfs_opt_encrypted_view, ecryptfs_opt_err };
221 static match_table_t tokens = {
222 {ecryptfs_opt_sig, "sig=%s"},
223 {ecryptfs_opt_ecryptfs_sig, "ecryptfs_sig=%s"},
224 {ecryptfs_opt_cipher, "cipher=%s"},
225 {ecryptfs_opt_ecryptfs_cipher, "ecryptfs_cipher=%s"},
226 {ecryptfs_opt_ecryptfs_key_bytes, "ecryptfs_key_bytes=%u"},
227 {ecryptfs_opt_passthrough, "ecryptfs_passthrough"},
228 {ecryptfs_opt_xattr_metadata, "ecryptfs_xattr_metadata"},
229 {ecryptfs_opt_encrypted_view, "ecryptfs_encrypted_view"},
230 {ecryptfs_opt_err, NULL}
233 static int ecryptfs_init_global_auth_toks(
234 struct ecryptfs_mount_crypt_stat *mount_crypt_stat)
236 struct ecryptfs_global_auth_tok *global_auth_tok;
239 list_for_each_entry(global_auth_tok,
240 &mount_crypt_stat->global_auth_tok_list,
241 mount_crypt_stat_list) {
242 rc = ecryptfs_keyring_auth_tok_for_sig(
243 &global_auth_tok->global_auth_tok_key,
244 &global_auth_tok->global_auth_tok,
245 global_auth_tok->sig);
247 printk(KERN_ERR "Could not find valid key in user "
248 "session keyring for sig specified in mount "
249 "option: [%s]\n", global_auth_tok->sig);
250 global_auth_tok->flags |= ECRYPTFS_AUTH_TOK_INVALID;
253 global_auth_tok->flags &= ~ECRYPTFS_AUTH_TOK_INVALID;
259 static void ecryptfs_init_mount_crypt_stat(
260 struct ecryptfs_mount_crypt_stat *mount_crypt_stat)
262 memset((void *)mount_crypt_stat, 0,
263 sizeof(struct ecryptfs_mount_crypt_stat));
264 INIT_LIST_HEAD(&mount_crypt_stat->global_auth_tok_list);
265 mutex_init(&mount_crypt_stat->global_auth_tok_list_mutex);
266 mount_crypt_stat->flags |= ECRYPTFS_MOUNT_CRYPT_STAT_INITIALIZED;
270 * ecryptfs_parse_options
271 * @sb: The ecryptfs super block
272 * @options: The options pased to the kernel
274 * Parse mount options:
275 * debug=N - ecryptfs_verbosity level for debug output
276 * sig=XXX - description(signature) of the key to use
278 * Returns the dentry object of the lower-level (lower/interposed)
279 * directory; We want to mount our stackable file system on top of
280 * that lower directory.
282 * The signature of the key to use must be the description of a key
283 * already in the keyring. Mounting will fail if the key can not be
286 * Returns zero on success; non-zero on error
288 static int ecryptfs_parse_options(struct super_block *sb, char *options)
293 int cipher_name_set = 0;
294 int cipher_key_bytes;
295 int cipher_key_bytes_set = 0;
296 struct ecryptfs_mount_crypt_stat *mount_crypt_stat =
297 &ecryptfs_superblock_to_private(sb)->mount_crypt_stat;
298 substring_t args[MAX_OPT_ARGS];
301 char *cipher_name_dst;
302 char *cipher_name_src;
303 char *cipher_key_bytes_src;
309 ecryptfs_init_mount_crypt_stat(mount_crypt_stat);
310 while ((p = strsep(&options, ",")) != NULL) {
313 token = match_token(p, tokens, args);
315 case ecryptfs_opt_sig:
316 case ecryptfs_opt_ecryptfs_sig:
317 sig_src = args[0].from;
318 rc = ecryptfs_add_global_auth_tok(mount_crypt_stat,
321 printk(KERN_ERR "Error attempting to register "
322 "global sig; rc = [%d]\n", rc);
327 case ecryptfs_opt_cipher:
328 case ecryptfs_opt_ecryptfs_cipher:
329 cipher_name_src = args[0].from;
332 global_default_cipher_name;
333 strncpy(cipher_name_dst, cipher_name_src,
334 ECRYPTFS_MAX_CIPHER_NAME_SIZE);
335 ecryptfs_printk(KERN_DEBUG,
336 "The mount_crypt_stat "
337 "global_default_cipher_name set to: "
338 "[%s]\n", cipher_name_dst);
341 case ecryptfs_opt_ecryptfs_key_bytes:
342 cipher_key_bytes_src = args[0].from;
344 (int)simple_strtol(cipher_key_bytes_src,
345 &cipher_key_bytes_src, 0);
346 mount_crypt_stat->global_default_cipher_key_size =
348 ecryptfs_printk(KERN_DEBUG,
349 "The mount_crypt_stat "
350 "global_default_cipher_key_size "
351 "set to: [%d]\n", mount_crypt_stat->
352 global_default_cipher_key_size);
353 cipher_key_bytes_set = 1;
355 case ecryptfs_opt_passthrough:
356 mount_crypt_stat->flags |=
357 ECRYPTFS_PLAINTEXT_PASSTHROUGH_ENABLED;
359 case ecryptfs_opt_xattr_metadata:
360 mount_crypt_stat->flags |=
361 ECRYPTFS_XATTR_METADATA_ENABLED;
363 case ecryptfs_opt_encrypted_view:
364 mount_crypt_stat->flags |=
365 ECRYPTFS_XATTR_METADATA_ENABLED;
366 mount_crypt_stat->flags |=
367 ECRYPTFS_ENCRYPTED_VIEW_ENABLED;
369 case ecryptfs_opt_err:
371 ecryptfs_printk(KERN_WARNING,
372 "eCryptfs: unrecognized option '%s'\n",
378 ecryptfs_printk(KERN_ERR, "You must supply at least one valid "
379 "auth tok signature as a mount "
380 "parameter; see the eCryptfs README\n");
383 if (!cipher_name_set) {
384 int cipher_name_len = strlen(ECRYPTFS_DEFAULT_CIPHER);
386 BUG_ON(cipher_name_len >= ECRYPTFS_MAX_CIPHER_NAME_SIZE);
388 strcpy(mount_crypt_stat->global_default_cipher_name,
389 ECRYPTFS_DEFAULT_CIPHER);
391 if (!cipher_key_bytes_set) {
392 mount_crypt_stat->global_default_cipher_key_size = 0;
394 mutex_lock(&key_tfm_list_mutex);
395 if (!ecryptfs_tfm_exists(mount_crypt_stat->global_default_cipher_name,
397 rc = ecryptfs_add_new_key_tfm(
398 NULL, mount_crypt_stat->global_default_cipher_name,
399 mount_crypt_stat->global_default_cipher_key_size);
400 mutex_unlock(&key_tfm_list_mutex);
402 printk(KERN_ERR "Error attempting to initialize cipher with "
403 "name = [%s] and key size = [%td]; rc = [%d]\n",
404 mount_crypt_stat->global_default_cipher_name,
405 mount_crypt_stat->global_default_cipher_key_size, rc);
409 rc = ecryptfs_init_global_auth_toks(mount_crypt_stat);
411 printk(KERN_WARNING "One or more global auth toks could not "
412 "properly register; rc = [%d]\n", rc);
418 struct kmem_cache *ecryptfs_sb_info_cache;
421 * ecryptfs_fill_super
422 * @sb: The ecryptfs super block
423 * @raw_data: The options passed to mount
424 * @silent: Not used but required by function prototype
426 * Sets up what we can of the sb, rest is done in ecryptfs_read_super
428 * Returns zero on success; non-zero otherwise
431 ecryptfs_fill_super(struct super_block *sb, void *raw_data, int silent)
435 /* Released in ecryptfs_put_super() */
436 ecryptfs_set_superblock_private(sb,
437 kmem_cache_zalloc(ecryptfs_sb_info_cache,
439 if (!ecryptfs_superblock_to_private(sb)) {
440 ecryptfs_printk(KERN_WARNING, "Out of memory\n");
444 sb->s_op = &ecryptfs_sops;
445 /* Released through deactivate_super(sb) from get_sb_nodev */
446 sb->s_root = d_alloc(NULL, &(const struct qstr) {
447 .hash = 0,.name = "/",.len = 1});
449 ecryptfs_printk(KERN_ERR, "d_alloc failed\n");
453 sb->s_root->d_op = &ecryptfs_dops;
454 sb->s_root->d_sb = sb;
455 sb->s_root->d_parent = sb->s_root;
456 /* Released in d_release when dput(sb->s_root) is called */
457 /* through deactivate_super(sb) from get_sb_nodev() */
458 ecryptfs_set_dentry_private(sb->s_root,
459 kmem_cache_zalloc(ecryptfs_dentry_info_cache,
461 if (!ecryptfs_dentry_to_private(sb->s_root)) {
462 ecryptfs_printk(KERN_ERR,
463 "dentry_info_cache alloc failed\n");
469 /* Should be able to rely on deactivate_super called from
475 * ecryptfs_read_super
476 * @sb: The ecryptfs super block
477 * @dev_name: The path to mount over
479 * Read the super block of the lower filesystem, and use
480 * ecryptfs_interpose to create our initial inode and super block
483 static int ecryptfs_read_super(struct super_block *sb, const char *dev_name)
487 struct dentry *lower_root;
488 struct vfsmount *lower_mnt;
490 memset(&nd, 0, sizeof(struct nameidata));
491 rc = path_lookup(dev_name, LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &nd);
493 ecryptfs_printk(KERN_WARNING, "path_lookup() failed\n");
496 lower_root = nd.path.dentry;
497 lower_mnt = nd.path.mnt;
498 ecryptfs_set_superblock_lower(sb, lower_root->d_sb);
499 sb->s_maxbytes = lower_root->d_sb->s_maxbytes;
500 sb->s_blocksize = lower_root->d_sb->s_blocksize;
501 ecryptfs_set_dentry_lower(sb->s_root, lower_root);
502 ecryptfs_set_dentry_lower_mnt(sb->s_root, lower_mnt);
503 rc = ecryptfs_interpose(lower_root, sb->s_root, sb, 0);
518 * @dev_name: The path to mount over
519 * @raw_data: The options passed into the kernel
521 * The whole ecryptfs_get_sb process is broken into 4 functions:
522 * ecryptfs_parse_options(): handle options passed to ecryptfs, if any
523 * ecryptfs_fill_super(): used by get_sb_nodev, fills out the super_block
524 * with as much information as it can before needing
525 * the lower filesystem.
526 * ecryptfs_read_super(): this accesses the lower filesystem and uses
527 * ecryptfs_interpolate to perform most of the linking
528 * ecryptfs_interpolate(): links the lower filesystem into ecryptfs
530 static int ecryptfs_get_sb(struct file_system_type *fs_type, int flags,
531 const char *dev_name, void *raw_data,
532 struct vfsmount *mnt)
535 struct super_block *sb;
537 rc = get_sb_nodev(fs_type, flags, raw_data, ecryptfs_fill_super, mnt);
539 printk(KERN_ERR "Getting sb failed; rc = [%d]\n", rc);
543 rc = ecryptfs_parse_options(sb, raw_data);
545 printk(KERN_ERR "Error parsing options; rc = [%d]\n", rc);
548 rc = ecryptfs_read_super(sb, dev_name);
550 printk(KERN_ERR "Reading sb failed; rc = [%d]\n", rc);
556 up_write(&sb->s_umount);
557 deactivate_super(sb);
563 * ecryptfs_kill_block_super
564 * @sb: The ecryptfs super block
566 * Used to bring the superblock down and free the private data.
567 * Private data is free'd in ecryptfs_put_super()
569 static void ecryptfs_kill_block_super(struct super_block *sb)
571 generic_shutdown_super(sb);
574 static struct file_system_type ecryptfs_fs_type = {
575 .owner = THIS_MODULE,
577 .get_sb = ecryptfs_get_sb,
578 .kill_sb = ecryptfs_kill_block_super,
583 * inode_info_init_once
585 * Initializes the ecryptfs_inode_info_cache when it is created
588 inode_info_init_once(struct kmem_cache *cachep, void *vptr)
590 struct ecryptfs_inode_info *ei = (struct ecryptfs_inode_info *)vptr;
592 inode_init_once(&ei->vfs_inode);
595 static struct ecryptfs_cache_info {
596 struct kmem_cache **cache;
599 void (*ctor)(struct kmem_cache *cache, void *obj);
600 } ecryptfs_cache_infos[] = {
602 .cache = &ecryptfs_auth_tok_list_item_cache,
603 .name = "ecryptfs_auth_tok_list_item",
604 .size = sizeof(struct ecryptfs_auth_tok_list_item),
607 .cache = &ecryptfs_file_info_cache,
608 .name = "ecryptfs_file_cache",
609 .size = sizeof(struct ecryptfs_file_info),
612 .cache = &ecryptfs_dentry_info_cache,
613 .name = "ecryptfs_dentry_info_cache",
614 .size = sizeof(struct ecryptfs_dentry_info),
617 .cache = &ecryptfs_inode_info_cache,
618 .name = "ecryptfs_inode_cache",
619 .size = sizeof(struct ecryptfs_inode_info),
620 .ctor = inode_info_init_once,
623 .cache = &ecryptfs_sb_info_cache,
624 .name = "ecryptfs_sb_cache",
625 .size = sizeof(struct ecryptfs_sb_info),
628 .cache = &ecryptfs_header_cache_1,
629 .name = "ecryptfs_headers_1",
630 .size = PAGE_CACHE_SIZE,
633 .cache = &ecryptfs_header_cache_2,
634 .name = "ecryptfs_headers_2",
635 .size = PAGE_CACHE_SIZE,
638 .cache = &ecryptfs_xattr_cache,
639 .name = "ecryptfs_xattr_cache",
640 .size = PAGE_CACHE_SIZE,
643 .cache = &ecryptfs_key_record_cache,
644 .name = "ecryptfs_key_record_cache",
645 .size = sizeof(struct ecryptfs_key_record),
648 .cache = &ecryptfs_key_sig_cache,
649 .name = "ecryptfs_key_sig_cache",
650 .size = sizeof(struct ecryptfs_key_sig),
653 .cache = &ecryptfs_global_auth_tok_cache,
654 .name = "ecryptfs_global_auth_tok_cache",
655 .size = sizeof(struct ecryptfs_global_auth_tok),
658 .cache = &ecryptfs_key_tfm_cache,
659 .name = "ecryptfs_key_tfm_cache",
660 .size = sizeof(struct ecryptfs_key_tfm),
663 .cache = &ecryptfs_open_req_cache,
664 .name = "ecryptfs_open_req_cache",
665 .size = sizeof(struct ecryptfs_open_req),
669 static void ecryptfs_free_kmem_caches(void)
673 for (i = 0; i < ARRAY_SIZE(ecryptfs_cache_infos); i++) {
674 struct ecryptfs_cache_info *info;
676 info = &ecryptfs_cache_infos[i];
678 kmem_cache_destroy(*(info->cache));
683 * ecryptfs_init_kmem_caches
685 * Returns zero on success; non-zero otherwise
687 static int ecryptfs_init_kmem_caches(void)
691 for (i = 0; i < ARRAY_SIZE(ecryptfs_cache_infos); i++) {
692 struct ecryptfs_cache_info *info;
694 info = &ecryptfs_cache_infos[i];
695 *(info->cache) = kmem_cache_create(info->name, info->size,
696 0, SLAB_HWCACHE_ALIGN, info->ctor);
697 if (!*(info->cache)) {
698 ecryptfs_free_kmem_caches();
699 ecryptfs_printk(KERN_WARNING, "%s: "
700 "kmem_cache_create failed\n",
708 static struct kobject *ecryptfs_kobj;
710 static ssize_t version_show(struct kobject *kobj,
711 struct kobj_attribute *attr, char *buff)
713 return snprintf(buff, PAGE_SIZE, "%d\n", ECRYPTFS_VERSIONING_MASK);
716 static struct kobj_attribute version_attr = __ATTR_RO(version);
718 static struct attribute *attributes[] = {
723 static struct attribute_group attr_group = {
727 static int do_sysfs_registration(void)
731 ecryptfs_kobj = kobject_create_and_add("ecryptfs", fs_kobj);
732 if (!ecryptfs_kobj) {
733 printk(KERN_ERR "Unable to create ecryptfs kset\n");
737 rc = sysfs_create_group(ecryptfs_kobj, &attr_group);
740 "Unable to create ecryptfs version attributes\n");
741 kobject_put(ecryptfs_kobj);
747 static void do_sysfs_unregistration(void)
749 sysfs_remove_group(ecryptfs_kobj, &attr_group);
750 kobject_put(ecryptfs_kobj);
753 static int __init ecryptfs_init(void)
757 if (ECRYPTFS_DEFAULT_EXTENT_SIZE > PAGE_CACHE_SIZE) {
759 ecryptfs_printk(KERN_ERR, "The eCryptfs extent size is "
760 "larger than the host's page size, and so "
761 "eCryptfs cannot run on this system. The "
762 "default eCryptfs extent size is [%d] bytes; "
763 "the page size is [%d] bytes.\n",
764 ECRYPTFS_DEFAULT_EXTENT_SIZE, PAGE_CACHE_SIZE);
767 rc = ecryptfs_init_kmem_caches();
770 "Failed to allocate one or more kmem_cache objects\n");
773 rc = register_filesystem(&ecryptfs_fs_type);
775 printk(KERN_ERR "Failed to register filesystem\n");
776 goto out_free_kmem_caches;
778 rc = do_sysfs_registration();
780 printk(KERN_ERR "sysfs registration failed\n");
781 goto out_unregister_filesystem;
783 rc = ecryptfs_init_kthread();
785 printk(KERN_ERR "%s: kthread initialization failed; "
786 "rc = [%d]\n", __func__, rc);
787 goto out_do_sysfs_unregistration;
789 rc = ecryptfs_init_messaging(ecryptfs_transport);
791 printk(KERN_ERR "Failure occured while attempting to "
792 "initialize the eCryptfs netlink socket\n");
793 goto out_destroy_kthread;
795 rc = ecryptfs_init_crypto();
797 printk(KERN_ERR "Failure whilst attempting to init crypto; "
799 goto out_release_messaging;
801 if (ecryptfs_verbosity > 0)
802 printk(KERN_CRIT "eCryptfs verbosity set to %d. Secret values "
803 "will be written to the syslog!\n", ecryptfs_verbosity);
806 out_release_messaging:
807 ecryptfs_release_messaging(ecryptfs_transport);
809 ecryptfs_destroy_kthread();
810 out_do_sysfs_unregistration:
811 do_sysfs_unregistration();
812 out_unregister_filesystem:
813 unregister_filesystem(&ecryptfs_fs_type);
814 out_free_kmem_caches:
815 ecryptfs_free_kmem_caches();
820 static void __exit ecryptfs_exit(void)
824 rc = ecryptfs_destroy_crypto();
826 printk(KERN_ERR "Failure whilst attempting to destroy crypto; "
828 ecryptfs_release_messaging(ecryptfs_transport);
829 ecryptfs_destroy_kthread();
830 do_sysfs_unregistration();
831 unregister_filesystem(&ecryptfs_fs_type);
832 ecryptfs_free_kmem_caches();
835 MODULE_AUTHOR("Michael A. Halcrow <mhalcrow@us.ibm.com>");
836 MODULE_DESCRIPTION("eCryptfs");
838 MODULE_LICENSE("GPL");
840 module_init(ecryptfs_init)
841 module_exit(ecryptfs_exit)