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 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 * @flags: flags to govern behavior of interpose procedure
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, u32 flags)
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;
196 if (flags & ECRYPTFS_INTERPOSE_FLAG_D_ADD)
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 if (!(flags & ECRYPTFS_INTERPOSE_FLAG_DELAY_PERSISTENT_FILE)) {
205 rc = ecryptfs_init_persistent_file(dentry);
207 printk(KERN_ERR "%s: Error attempting to initialize "
208 "the persistent file for the dentry with name "
209 "[%s]; rc = [%d]\n", __func__,
210 dentry->d_name.name, rc);
214 struct ecryptfs_inode_info *inode_info =
215 ecryptfs_inode_to_private(dentry->d_inode);
217 inode_info->lower_file = NULL;
218 inode_info->crypt_stat.flags |= ECRYPTFS_DELAY_PERSISTENT;
224 enum { ecryptfs_opt_sig, ecryptfs_opt_ecryptfs_sig,
225 ecryptfs_opt_cipher, ecryptfs_opt_ecryptfs_cipher,
226 ecryptfs_opt_ecryptfs_key_bytes,
227 ecryptfs_opt_passthrough, ecryptfs_opt_xattr_metadata,
228 ecryptfs_opt_encrypted_view, ecryptfs_opt_err };
230 static match_table_t tokens = {
231 {ecryptfs_opt_sig, "sig=%s"},
232 {ecryptfs_opt_ecryptfs_sig, "ecryptfs_sig=%s"},
233 {ecryptfs_opt_cipher, "cipher=%s"},
234 {ecryptfs_opt_ecryptfs_cipher, "ecryptfs_cipher=%s"},
235 {ecryptfs_opt_ecryptfs_key_bytes, "ecryptfs_key_bytes=%u"},
236 {ecryptfs_opt_passthrough, "ecryptfs_passthrough"},
237 {ecryptfs_opt_xattr_metadata, "ecryptfs_xattr_metadata"},
238 {ecryptfs_opt_encrypted_view, "ecryptfs_encrypted_view"},
239 {ecryptfs_opt_err, NULL}
242 static int ecryptfs_init_global_auth_toks(
243 struct ecryptfs_mount_crypt_stat *mount_crypt_stat)
245 struct ecryptfs_global_auth_tok *global_auth_tok;
248 list_for_each_entry(global_auth_tok,
249 &mount_crypt_stat->global_auth_tok_list,
250 mount_crypt_stat_list) {
251 rc = ecryptfs_keyring_auth_tok_for_sig(
252 &global_auth_tok->global_auth_tok_key,
253 &global_auth_tok->global_auth_tok,
254 global_auth_tok->sig);
256 printk(KERN_ERR "Could not find valid key in user "
257 "session keyring for sig specified in mount "
258 "option: [%s]\n", global_auth_tok->sig);
259 global_auth_tok->flags |= ECRYPTFS_AUTH_TOK_INVALID;
262 global_auth_tok->flags &= ~ECRYPTFS_AUTH_TOK_INVALID;
268 static void ecryptfs_init_mount_crypt_stat(
269 struct ecryptfs_mount_crypt_stat *mount_crypt_stat)
271 memset((void *)mount_crypt_stat, 0,
272 sizeof(struct ecryptfs_mount_crypt_stat));
273 INIT_LIST_HEAD(&mount_crypt_stat->global_auth_tok_list);
274 mutex_init(&mount_crypt_stat->global_auth_tok_list_mutex);
275 mount_crypt_stat->flags |= ECRYPTFS_MOUNT_CRYPT_STAT_INITIALIZED;
279 * ecryptfs_parse_options
280 * @sb: The ecryptfs super block
281 * @options: The options pased to the kernel
283 * Parse mount options:
284 * debug=N - ecryptfs_verbosity level for debug output
285 * sig=XXX - description(signature) of the key to use
287 * Returns the dentry object of the lower-level (lower/interposed)
288 * directory; We want to mount our stackable file system on top of
289 * that lower directory.
291 * The signature of the key to use must be the description of a key
292 * already in the keyring. Mounting will fail if the key can not be
295 * Returns zero on success; non-zero on error
297 static int ecryptfs_parse_options(struct super_block *sb, char *options)
302 int cipher_name_set = 0;
303 int cipher_key_bytes;
304 int cipher_key_bytes_set = 0;
305 struct ecryptfs_mount_crypt_stat *mount_crypt_stat =
306 &ecryptfs_superblock_to_private(sb)->mount_crypt_stat;
307 substring_t args[MAX_OPT_ARGS];
310 char *cipher_name_dst;
311 char *cipher_name_src;
312 char *cipher_key_bytes_src;
318 ecryptfs_init_mount_crypt_stat(mount_crypt_stat);
319 while ((p = strsep(&options, ",")) != NULL) {
322 token = match_token(p, tokens, args);
324 case ecryptfs_opt_sig:
325 case ecryptfs_opt_ecryptfs_sig:
326 sig_src = args[0].from;
327 rc = ecryptfs_add_global_auth_tok(mount_crypt_stat,
330 printk(KERN_ERR "Error attempting to register "
331 "global sig; rc = [%d]\n", rc);
336 case ecryptfs_opt_cipher:
337 case ecryptfs_opt_ecryptfs_cipher:
338 cipher_name_src = args[0].from;
341 global_default_cipher_name;
342 strncpy(cipher_name_dst, cipher_name_src,
343 ECRYPTFS_MAX_CIPHER_NAME_SIZE);
344 ecryptfs_printk(KERN_DEBUG,
345 "The mount_crypt_stat "
346 "global_default_cipher_name set to: "
347 "[%s]\n", cipher_name_dst);
350 case ecryptfs_opt_ecryptfs_key_bytes:
351 cipher_key_bytes_src = args[0].from;
353 (int)simple_strtol(cipher_key_bytes_src,
354 &cipher_key_bytes_src, 0);
355 mount_crypt_stat->global_default_cipher_key_size =
357 ecryptfs_printk(KERN_DEBUG,
358 "The mount_crypt_stat "
359 "global_default_cipher_key_size "
360 "set to: [%d]\n", mount_crypt_stat->
361 global_default_cipher_key_size);
362 cipher_key_bytes_set = 1;
364 case ecryptfs_opt_passthrough:
365 mount_crypt_stat->flags |=
366 ECRYPTFS_PLAINTEXT_PASSTHROUGH_ENABLED;
368 case ecryptfs_opt_xattr_metadata:
369 mount_crypt_stat->flags |=
370 ECRYPTFS_XATTR_METADATA_ENABLED;
372 case ecryptfs_opt_encrypted_view:
373 mount_crypt_stat->flags |=
374 ECRYPTFS_XATTR_METADATA_ENABLED;
375 mount_crypt_stat->flags |=
376 ECRYPTFS_ENCRYPTED_VIEW_ENABLED;
378 case ecryptfs_opt_err:
380 ecryptfs_printk(KERN_WARNING,
381 "eCryptfs: unrecognized option '%s'\n",
387 ecryptfs_printk(KERN_ERR, "You must supply at least one valid "
388 "auth tok signature as a mount "
389 "parameter; see the eCryptfs README\n");
392 if (!cipher_name_set) {
393 int cipher_name_len = strlen(ECRYPTFS_DEFAULT_CIPHER);
395 BUG_ON(cipher_name_len >= ECRYPTFS_MAX_CIPHER_NAME_SIZE);
397 strcpy(mount_crypt_stat->global_default_cipher_name,
398 ECRYPTFS_DEFAULT_CIPHER);
400 if (!cipher_key_bytes_set) {
401 mount_crypt_stat->global_default_cipher_key_size = 0;
403 mutex_lock(&key_tfm_list_mutex);
404 if (!ecryptfs_tfm_exists(mount_crypt_stat->global_default_cipher_name,
406 rc = ecryptfs_add_new_key_tfm(
407 NULL, mount_crypt_stat->global_default_cipher_name,
408 mount_crypt_stat->global_default_cipher_key_size);
409 mutex_unlock(&key_tfm_list_mutex);
411 printk(KERN_ERR "Error attempting to initialize cipher with "
412 "name = [%s] and key size = [%td]; rc = [%d]\n",
413 mount_crypt_stat->global_default_cipher_name,
414 mount_crypt_stat->global_default_cipher_key_size, rc);
418 rc = ecryptfs_init_global_auth_toks(mount_crypt_stat);
420 printk(KERN_WARNING "One or more global auth toks could not "
421 "properly register; rc = [%d]\n", rc);
427 struct kmem_cache *ecryptfs_sb_info_cache;
430 * ecryptfs_fill_super
431 * @sb: The ecryptfs super block
432 * @raw_data: The options passed to mount
433 * @silent: Not used but required by function prototype
435 * Sets up what we can of the sb, rest is done in ecryptfs_read_super
437 * Returns zero on success; non-zero otherwise
440 ecryptfs_fill_super(struct super_block *sb, void *raw_data, int silent)
444 /* Released in ecryptfs_put_super() */
445 ecryptfs_set_superblock_private(sb,
446 kmem_cache_zalloc(ecryptfs_sb_info_cache,
448 if (!ecryptfs_superblock_to_private(sb)) {
449 ecryptfs_printk(KERN_WARNING, "Out of memory\n");
453 sb->s_op = &ecryptfs_sops;
454 /* Released through deactivate_super(sb) from get_sb_nodev */
455 sb->s_root = d_alloc(NULL, &(const struct qstr) {
456 .hash = 0,.name = "/",.len = 1});
458 ecryptfs_printk(KERN_ERR, "d_alloc failed\n");
462 sb->s_root->d_op = &ecryptfs_dops;
463 sb->s_root->d_sb = sb;
464 sb->s_root->d_parent = sb->s_root;
465 /* Released in d_release when dput(sb->s_root) is called */
466 /* through deactivate_super(sb) from get_sb_nodev() */
467 ecryptfs_set_dentry_private(sb->s_root,
468 kmem_cache_zalloc(ecryptfs_dentry_info_cache,
470 if (!ecryptfs_dentry_to_private(sb->s_root)) {
471 ecryptfs_printk(KERN_ERR,
472 "dentry_info_cache alloc failed\n");
478 /* Should be able to rely on deactivate_super called from
484 * ecryptfs_read_super
485 * @sb: The ecryptfs super block
486 * @dev_name: The path to mount over
488 * Read the super block of the lower filesystem, and use
489 * ecryptfs_interpose to create our initial inode and super block
492 static int ecryptfs_read_super(struct super_block *sb, const char *dev_name)
496 struct dentry *lower_root;
497 struct vfsmount *lower_mnt;
499 memset(&nd, 0, sizeof(struct nameidata));
500 rc = path_lookup(dev_name, LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &nd);
502 ecryptfs_printk(KERN_WARNING, "path_lookup() failed\n");
505 lower_root = nd.path.dentry;
506 lower_mnt = nd.path.mnt;
507 ecryptfs_set_superblock_lower(sb, lower_root->d_sb);
508 sb->s_maxbytes = lower_root->d_sb->s_maxbytes;
509 sb->s_blocksize = lower_root->d_sb->s_blocksize;
510 ecryptfs_set_dentry_lower(sb->s_root, lower_root);
511 ecryptfs_set_dentry_lower_mnt(sb->s_root, lower_mnt);
512 rc = ecryptfs_interpose(lower_root, sb->s_root, sb, 0);
527 * @dev_name: The path to mount over
528 * @raw_data: The options passed into the kernel
530 * The whole ecryptfs_get_sb process is broken into 4 functions:
531 * ecryptfs_parse_options(): handle options passed to ecryptfs, if any
532 * ecryptfs_fill_super(): used by get_sb_nodev, fills out the super_block
533 * with as much information as it can before needing
534 * the lower filesystem.
535 * ecryptfs_read_super(): this accesses the lower filesystem and uses
536 * ecryptfs_interpolate to perform most of the linking
537 * ecryptfs_interpolate(): links the lower filesystem into ecryptfs
539 static int ecryptfs_get_sb(struct file_system_type *fs_type, int flags,
540 const char *dev_name, void *raw_data,
541 struct vfsmount *mnt)
544 struct super_block *sb;
546 rc = get_sb_nodev(fs_type, flags, raw_data, ecryptfs_fill_super, mnt);
548 printk(KERN_ERR "Getting sb failed; rc = [%d]\n", rc);
552 rc = ecryptfs_parse_options(sb, raw_data);
554 printk(KERN_ERR "Error parsing options; rc = [%d]\n", rc);
557 rc = ecryptfs_read_super(sb, dev_name);
559 printk(KERN_ERR "Reading sb failed; rc = [%d]\n", rc);
565 up_write(&sb->s_umount);
566 deactivate_super(sb);
572 * ecryptfs_kill_block_super
573 * @sb: The ecryptfs super block
575 * Used to bring the superblock down and free the private data.
576 * Private data is free'd in ecryptfs_put_super()
578 static void ecryptfs_kill_block_super(struct super_block *sb)
580 generic_shutdown_super(sb);
583 static struct file_system_type ecryptfs_fs_type = {
584 .owner = THIS_MODULE,
586 .get_sb = ecryptfs_get_sb,
587 .kill_sb = ecryptfs_kill_block_super,
592 * inode_info_init_once
594 * Initializes the ecryptfs_inode_info_cache when it is created
597 inode_info_init_once(struct kmem_cache *cachep, void *vptr)
599 struct ecryptfs_inode_info *ei = (struct ecryptfs_inode_info *)vptr;
601 inode_init_once(&ei->vfs_inode);
604 static struct ecryptfs_cache_info {
605 struct kmem_cache **cache;
608 void (*ctor)(struct kmem_cache *cache, void *obj);
609 } ecryptfs_cache_infos[] = {
611 .cache = &ecryptfs_auth_tok_list_item_cache,
612 .name = "ecryptfs_auth_tok_list_item",
613 .size = sizeof(struct ecryptfs_auth_tok_list_item),
616 .cache = &ecryptfs_file_info_cache,
617 .name = "ecryptfs_file_cache",
618 .size = sizeof(struct ecryptfs_file_info),
621 .cache = &ecryptfs_dentry_info_cache,
622 .name = "ecryptfs_dentry_info_cache",
623 .size = sizeof(struct ecryptfs_dentry_info),
626 .cache = &ecryptfs_inode_info_cache,
627 .name = "ecryptfs_inode_cache",
628 .size = sizeof(struct ecryptfs_inode_info),
629 .ctor = inode_info_init_once,
632 .cache = &ecryptfs_sb_info_cache,
633 .name = "ecryptfs_sb_cache",
634 .size = sizeof(struct ecryptfs_sb_info),
637 .cache = &ecryptfs_header_cache_1,
638 .name = "ecryptfs_headers_1",
639 .size = PAGE_CACHE_SIZE,
642 .cache = &ecryptfs_header_cache_2,
643 .name = "ecryptfs_headers_2",
644 .size = PAGE_CACHE_SIZE,
647 .cache = &ecryptfs_xattr_cache,
648 .name = "ecryptfs_xattr_cache",
649 .size = PAGE_CACHE_SIZE,
652 .cache = &ecryptfs_key_record_cache,
653 .name = "ecryptfs_key_record_cache",
654 .size = sizeof(struct ecryptfs_key_record),
657 .cache = &ecryptfs_key_sig_cache,
658 .name = "ecryptfs_key_sig_cache",
659 .size = sizeof(struct ecryptfs_key_sig),
662 .cache = &ecryptfs_global_auth_tok_cache,
663 .name = "ecryptfs_global_auth_tok_cache",
664 .size = sizeof(struct ecryptfs_global_auth_tok),
667 .cache = &ecryptfs_key_tfm_cache,
668 .name = "ecryptfs_key_tfm_cache",
669 .size = sizeof(struct ecryptfs_key_tfm),
672 .cache = &ecryptfs_open_req_cache,
673 .name = "ecryptfs_open_req_cache",
674 .size = sizeof(struct ecryptfs_open_req),
678 static void ecryptfs_free_kmem_caches(void)
682 for (i = 0; i < ARRAY_SIZE(ecryptfs_cache_infos); i++) {
683 struct ecryptfs_cache_info *info;
685 info = &ecryptfs_cache_infos[i];
687 kmem_cache_destroy(*(info->cache));
692 * ecryptfs_init_kmem_caches
694 * Returns zero on success; non-zero otherwise
696 static int ecryptfs_init_kmem_caches(void)
700 for (i = 0; i < ARRAY_SIZE(ecryptfs_cache_infos); i++) {
701 struct ecryptfs_cache_info *info;
703 info = &ecryptfs_cache_infos[i];
704 *(info->cache) = kmem_cache_create(info->name, info->size,
705 0, SLAB_HWCACHE_ALIGN, info->ctor);
706 if (!*(info->cache)) {
707 ecryptfs_free_kmem_caches();
708 ecryptfs_printk(KERN_WARNING, "%s: "
709 "kmem_cache_create failed\n",
717 static struct kobject *ecryptfs_kobj;
719 static ssize_t version_show(struct kobject *kobj,
720 struct kobj_attribute *attr, char *buff)
722 return snprintf(buff, PAGE_SIZE, "%d\n", ECRYPTFS_VERSIONING_MASK);
725 static struct kobj_attribute version_attr = __ATTR_RO(version);
727 static struct attribute *attributes[] = {
732 static struct attribute_group attr_group = {
736 static int do_sysfs_registration(void)
740 ecryptfs_kobj = kobject_create_and_add("ecryptfs", fs_kobj);
741 if (!ecryptfs_kobj) {
742 printk(KERN_ERR "Unable to create ecryptfs kset\n");
746 rc = sysfs_create_group(ecryptfs_kobj, &attr_group);
749 "Unable to create ecryptfs version attributes\n");
750 kobject_put(ecryptfs_kobj);
756 static void do_sysfs_unregistration(void)
758 sysfs_remove_group(ecryptfs_kobj, &attr_group);
759 kobject_put(ecryptfs_kobj);
762 static int __init ecryptfs_init(void)
766 if (ECRYPTFS_DEFAULT_EXTENT_SIZE > PAGE_CACHE_SIZE) {
768 ecryptfs_printk(KERN_ERR, "The eCryptfs extent size is "
769 "larger than the host's page size, and so "
770 "eCryptfs cannot run on this system. The "
771 "default eCryptfs extent size is [%d] bytes; "
772 "the page size is [%d] bytes.\n",
773 ECRYPTFS_DEFAULT_EXTENT_SIZE, PAGE_CACHE_SIZE);
776 rc = ecryptfs_init_kmem_caches();
779 "Failed to allocate one or more kmem_cache objects\n");
782 rc = register_filesystem(&ecryptfs_fs_type);
784 printk(KERN_ERR "Failed to register filesystem\n");
785 goto out_free_kmem_caches;
787 rc = do_sysfs_registration();
789 printk(KERN_ERR "sysfs registration failed\n");
790 goto out_unregister_filesystem;
792 rc = ecryptfs_init_kthread();
794 printk(KERN_ERR "%s: kthread initialization failed; "
795 "rc = [%d]\n", __func__, rc);
796 goto out_do_sysfs_unregistration;
798 rc = ecryptfs_init_messaging(ecryptfs_transport);
800 printk(KERN_ERR "Failure occured while attempting to "
801 "initialize the eCryptfs netlink socket\n");
802 goto out_destroy_kthread;
804 rc = ecryptfs_init_crypto();
806 printk(KERN_ERR "Failure whilst attempting to init crypto; "
808 goto out_release_messaging;
810 if (ecryptfs_verbosity > 0)
811 printk(KERN_CRIT "eCryptfs verbosity set to %d. Secret values "
812 "will be written to the syslog!\n", ecryptfs_verbosity);
815 out_release_messaging:
816 ecryptfs_release_messaging(ecryptfs_transport);
818 ecryptfs_destroy_kthread();
819 out_do_sysfs_unregistration:
820 do_sysfs_unregistration();
821 out_unregister_filesystem:
822 unregister_filesystem(&ecryptfs_fs_type);
823 out_free_kmem_caches:
824 ecryptfs_free_kmem_caches();
829 static void __exit ecryptfs_exit(void)
833 rc = ecryptfs_destroy_crypto();
835 printk(KERN_ERR "Failure whilst attempting to destroy crypto; "
837 ecryptfs_release_messaging(ecryptfs_transport);
838 ecryptfs_destroy_kthread();
839 do_sysfs_unregistration();
840 unregister_filesystem(&ecryptfs_fs_type);
841 ecryptfs_free_kmem_caches();
844 MODULE_AUTHOR("Michael A. Halcrow <mhalcrow@us.ibm.com>");
845 MODULE_DESCRIPTION("eCryptfs");
847 MODULE_LICENSE("GPL");
849 module_init(ecryptfs_init)
850 module_exit(ecryptfs_exit)