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/mount.h>
34 #include <linux/pagemap.h>
35 #include <linux/key.h>
36 #include <linux/parser.h>
37 #include <linux/fs_stack.h>
38 #include "ecryptfs_kernel.h"
41 * Module parameter that defines the ecryptfs_verbosity level.
43 int ecryptfs_verbosity
= 0;
45 module_param(ecryptfs_verbosity
, int, 0);
46 MODULE_PARM_DESC(ecryptfs_verbosity
,
47 "Initial verbosity level (0 or 1; defaults to "
48 "0, which is Quiet)");
51 * Module parameter that defines the number of message buffer elements
53 unsigned int ecryptfs_message_buf_len
= ECRYPTFS_DEFAULT_MSG_CTX_ELEMS
;
55 module_param(ecryptfs_message_buf_len
, uint
, 0);
56 MODULE_PARM_DESC(ecryptfs_message_buf_len
,
57 "Number of message buffer elements");
60 * Module parameter that defines the maximum guaranteed amount of time to wait
61 * for a response from ecryptfsd. The actual sleep time will be, more than
62 * likely, a small amount greater than this specified value, but only less if
63 * the message successfully arrives.
65 signed long ecryptfs_message_wait_timeout
= ECRYPTFS_MAX_MSG_CTX_TTL
/ HZ
;
67 module_param(ecryptfs_message_wait_timeout
, long, 0);
68 MODULE_PARM_DESC(ecryptfs_message_wait_timeout
,
69 "Maximum number of seconds that an operation will "
70 "sleep while waiting for a message response from "
74 * Module parameter that is an estimate of the maximum number of users
75 * that will be concurrently using eCryptfs. Set this to the right
76 * value to balance performance and memory use.
78 unsigned int ecryptfs_number_of_users
= ECRYPTFS_DEFAULT_NUM_USERS
;
80 module_param(ecryptfs_number_of_users
, uint
, 0);
81 MODULE_PARM_DESC(ecryptfs_number_of_users
, "An estimate of the number of "
82 "concurrent users of eCryptfs");
84 void __ecryptfs_printk(const char *fmt
, ...)
88 if (fmt
[1] == '7') { /* KERN_DEBUG */
89 if (ecryptfs_verbosity
>= 1)
97 * ecryptfs_init_persistent_file
98 * @ecryptfs_dentry: Fully initialized eCryptfs dentry object, with
99 * the lower dentry and the lower mount set
101 * eCryptfs only ever keeps a single open file for every lower
102 * inode. All I/O operations to the lower inode occur through that
103 * file. When the first eCryptfs dentry that interposes with the first
104 * lower dentry for that inode is created, this function creates the
105 * persistent file struct and associates it with the eCryptfs
106 * inode. When the eCryptfs inode is destroyed, the file is closed.
108 * The persistent file will be opened with read/write permissions, if
109 * possible. Otherwise, it is opened read-only.
111 * This function does nothing if a lower persistent file is already
112 * associated with the eCryptfs inode.
114 * Returns zero on success; non-zero otherwise
116 int ecryptfs_init_persistent_file(struct dentry
*ecryptfs_dentry
)
118 const struct cred
*cred
= current_cred();
119 struct ecryptfs_inode_info
*inode_info
=
120 ecryptfs_inode_to_private(ecryptfs_dentry
->d_inode
);
123 mutex_lock(&inode_info
->lower_file_mutex
);
124 if (!inode_info
->lower_file
) {
125 struct dentry
*lower_dentry
;
126 struct vfsmount
*lower_mnt
=
127 ecryptfs_dentry_to_lower_mnt(ecryptfs_dentry
);
129 lower_dentry
= ecryptfs_dentry_to_lower(ecryptfs_dentry
);
130 rc
= ecryptfs_privileged_open(&inode_info
->lower_file
,
131 lower_dentry
, lower_mnt
, cred
);
132 if (rc
|| IS_ERR(inode_info
->lower_file
)) {
133 printk(KERN_ERR
"Error opening lower persistent file "
134 "for lower_dentry [0x%p] and lower_mnt [0x%p]; "
135 "rc = [%d]\n", lower_dentry
, lower_mnt
, rc
);
136 rc
= PTR_ERR(inode_info
->lower_file
);
137 inode_info
->lower_file
= NULL
;
140 mutex_unlock(&inode_info
->lower_file_mutex
);
146 * @lower_dentry: Existing dentry in the lower filesystem
147 * @dentry: ecryptfs' dentry
148 * @sb: ecryptfs's super_block
149 * @flags: flags to govern behavior of interpose procedure
151 * Interposes upper and lower dentries.
153 * Returns zero on success; non-zero otherwise
155 int ecryptfs_interpose(struct dentry
*lower_dentry
, struct dentry
*dentry
,
156 struct super_block
*sb
, u32 flags
)
158 struct inode
*lower_inode
;
162 lower_inode
= lower_dentry
->d_inode
;
163 if (lower_inode
->i_sb
!= ecryptfs_superblock_to_lower(sb
)) {
167 if (!igrab(lower_inode
)) {
171 inode
= iget5_locked(sb
, (unsigned long)lower_inode
,
172 ecryptfs_inode_test
, ecryptfs_inode_set
,
179 if (inode
->i_state
& I_NEW
)
180 unlock_new_inode(inode
);
183 if (S_ISLNK(lower_inode
->i_mode
))
184 inode
->i_op
= &ecryptfs_symlink_iops
;
185 else if (S_ISDIR(lower_inode
->i_mode
))
186 inode
->i_op
= &ecryptfs_dir_iops
;
187 if (S_ISDIR(lower_inode
->i_mode
))
188 inode
->i_fop
= &ecryptfs_dir_fops
;
189 if (special_file(lower_inode
->i_mode
))
190 init_special_inode(inode
, lower_inode
->i_mode
,
191 lower_inode
->i_rdev
);
192 dentry
->d_op
= &ecryptfs_dops
;
193 if (flags
& ECRYPTFS_INTERPOSE_FLAG_D_ADD
)
194 d_add(dentry
, inode
);
196 d_instantiate(dentry
, inode
);
197 fsstack_copy_attr_all(inode
, lower_inode
, NULL
);
198 /* This size will be overwritten for real files w/ headers and
200 fsstack_copy_inode_size(inode
, lower_inode
);
205 enum { ecryptfs_opt_sig
, ecryptfs_opt_ecryptfs_sig
,
206 ecryptfs_opt_cipher
, ecryptfs_opt_ecryptfs_cipher
,
207 ecryptfs_opt_ecryptfs_key_bytes
,
208 ecryptfs_opt_passthrough
, ecryptfs_opt_xattr_metadata
,
209 ecryptfs_opt_encrypted_view
, ecryptfs_opt_err
};
211 static const match_table_t tokens
= {
212 {ecryptfs_opt_sig
, "sig=%s"},
213 {ecryptfs_opt_ecryptfs_sig
, "ecryptfs_sig=%s"},
214 {ecryptfs_opt_cipher
, "cipher=%s"},
215 {ecryptfs_opt_ecryptfs_cipher
, "ecryptfs_cipher=%s"},
216 {ecryptfs_opt_ecryptfs_key_bytes
, "ecryptfs_key_bytes=%u"},
217 {ecryptfs_opt_passthrough
, "ecryptfs_passthrough"},
218 {ecryptfs_opt_xattr_metadata
, "ecryptfs_xattr_metadata"},
219 {ecryptfs_opt_encrypted_view
, "ecryptfs_encrypted_view"},
220 {ecryptfs_opt_err
, NULL
}
223 static int ecryptfs_init_global_auth_toks(
224 struct ecryptfs_mount_crypt_stat
*mount_crypt_stat
)
226 struct ecryptfs_global_auth_tok
*global_auth_tok
;
229 list_for_each_entry(global_auth_tok
,
230 &mount_crypt_stat
->global_auth_tok_list
,
231 mount_crypt_stat_list
) {
232 rc
= ecryptfs_keyring_auth_tok_for_sig(
233 &global_auth_tok
->global_auth_tok_key
,
234 &global_auth_tok
->global_auth_tok
,
235 global_auth_tok
->sig
);
237 printk(KERN_ERR
"Could not find valid key in user "
238 "session keyring for sig specified in mount "
239 "option: [%s]\n", global_auth_tok
->sig
);
240 global_auth_tok
->flags
|= ECRYPTFS_AUTH_TOK_INVALID
;
243 global_auth_tok
->flags
&= ~ECRYPTFS_AUTH_TOK_INVALID
;
249 static void ecryptfs_init_mount_crypt_stat(
250 struct ecryptfs_mount_crypt_stat
*mount_crypt_stat
)
252 memset((void *)mount_crypt_stat
, 0,
253 sizeof(struct ecryptfs_mount_crypt_stat
));
254 INIT_LIST_HEAD(&mount_crypt_stat
->global_auth_tok_list
);
255 mutex_init(&mount_crypt_stat
->global_auth_tok_list_mutex
);
256 mount_crypt_stat
->flags
|= ECRYPTFS_MOUNT_CRYPT_STAT_INITIALIZED
;
260 * ecryptfs_parse_options
261 * @sb: The ecryptfs super block
262 * @options: The options pased to the kernel
264 * Parse mount options:
265 * debug=N - ecryptfs_verbosity level for debug output
266 * sig=XXX - description(signature) of the key to use
268 * Returns the dentry object of the lower-level (lower/interposed)
269 * directory; We want to mount our stackable file system on top of
270 * that lower directory.
272 * The signature of the key to use must be the description of a key
273 * already in the keyring. Mounting will fail if the key can not be
276 * Returns zero on success; non-zero on error
278 static int ecryptfs_parse_options(struct super_block
*sb
, char *options
)
283 int cipher_name_set
= 0;
284 int cipher_key_bytes
;
285 int cipher_key_bytes_set
= 0;
286 struct ecryptfs_mount_crypt_stat
*mount_crypt_stat
=
287 &ecryptfs_superblock_to_private(sb
)->mount_crypt_stat
;
288 substring_t args
[MAX_OPT_ARGS
];
291 char *cipher_name_dst
;
292 char *cipher_name_src
;
293 char *cipher_key_bytes_src
;
299 ecryptfs_init_mount_crypt_stat(mount_crypt_stat
);
300 while ((p
= strsep(&options
, ",")) != NULL
) {
303 token
= match_token(p
, tokens
, args
);
305 case ecryptfs_opt_sig
:
306 case ecryptfs_opt_ecryptfs_sig
:
307 sig_src
= args
[0].from
;
308 rc
= ecryptfs_add_global_auth_tok(mount_crypt_stat
,
311 printk(KERN_ERR
"Error attempting to register "
312 "global sig; rc = [%d]\n", rc
);
317 case ecryptfs_opt_cipher
:
318 case ecryptfs_opt_ecryptfs_cipher
:
319 cipher_name_src
= args
[0].from
;
322 global_default_cipher_name
;
323 strncpy(cipher_name_dst
, cipher_name_src
,
324 ECRYPTFS_MAX_CIPHER_NAME_SIZE
);
325 ecryptfs_printk(KERN_DEBUG
,
326 "The mount_crypt_stat "
327 "global_default_cipher_name set to: "
328 "[%s]\n", cipher_name_dst
);
331 case ecryptfs_opt_ecryptfs_key_bytes
:
332 cipher_key_bytes_src
= args
[0].from
;
334 (int)simple_strtol(cipher_key_bytes_src
,
335 &cipher_key_bytes_src
, 0);
336 mount_crypt_stat
->global_default_cipher_key_size
=
338 ecryptfs_printk(KERN_DEBUG
,
339 "The mount_crypt_stat "
340 "global_default_cipher_key_size "
341 "set to: [%d]\n", mount_crypt_stat
->
342 global_default_cipher_key_size
);
343 cipher_key_bytes_set
= 1;
345 case ecryptfs_opt_passthrough
:
346 mount_crypt_stat
->flags
|=
347 ECRYPTFS_PLAINTEXT_PASSTHROUGH_ENABLED
;
349 case ecryptfs_opt_xattr_metadata
:
350 mount_crypt_stat
->flags
|=
351 ECRYPTFS_XATTR_METADATA_ENABLED
;
353 case ecryptfs_opt_encrypted_view
:
354 mount_crypt_stat
->flags
|=
355 ECRYPTFS_XATTR_METADATA_ENABLED
;
356 mount_crypt_stat
->flags
|=
357 ECRYPTFS_ENCRYPTED_VIEW_ENABLED
;
359 case ecryptfs_opt_err
:
361 ecryptfs_printk(KERN_WARNING
,
362 "eCryptfs: unrecognized option '%s'\n",
368 ecryptfs_printk(KERN_ERR
, "You must supply at least one valid "
369 "auth tok signature as a mount "
370 "parameter; see the eCryptfs README\n");
373 if (!cipher_name_set
) {
374 int cipher_name_len
= strlen(ECRYPTFS_DEFAULT_CIPHER
);
376 BUG_ON(cipher_name_len
>= ECRYPTFS_MAX_CIPHER_NAME_SIZE
);
378 strcpy(mount_crypt_stat
->global_default_cipher_name
,
379 ECRYPTFS_DEFAULT_CIPHER
);
381 if (!cipher_key_bytes_set
) {
382 mount_crypt_stat
->global_default_cipher_key_size
= 0;
384 mutex_lock(&key_tfm_list_mutex
);
385 if (!ecryptfs_tfm_exists(mount_crypt_stat
->global_default_cipher_name
,
387 rc
= ecryptfs_add_new_key_tfm(
388 NULL
, mount_crypt_stat
->global_default_cipher_name
,
389 mount_crypt_stat
->global_default_cipher_key_size
);
390 mutex_unlock(&key_tfm_list_mutex
);
392 printk(KERN_ERR
"Error attempting to initialize cipher with "
393 "name = [%s] and key size = [%td]; rc = [%d]\n",
394 mount_crypt_stat
->global_default_cipher_name
,
395 mount_crypt_stat
->global_default_cipher_key_size
, rc
);
399 rc
= ecryptfs_init_global_auth_toks(mount_crypt_stat
);
401 printk(KERN_WARNING
"One or more global auth toks could not "
402 "properly register; rc = [%d]\n", rc
);
408 struct kmem_cache
*ecryptfs_sb_info_cache
;
411 * ecryptfs_fill_super
412 * @sb: The ecryptfs super block
413 * @raw_data: The options passed to mount
414 * @silent: Not used but required by function prototype
416 * Sets up what we can of the sb, rest is done in ecryptfs_read_super
418 * Returns zero on success; non-zero otherwise
421 ecryptfs_fill_super(struct super_block
*sb
, void *raw_data
, int silent
)
425 /* Released in ecryptfs_put_super() */
426 ecryptfs_set_superblock_private(sb
,
427 kmem_cache_zalloc(ecryptfs_sb_info_cache
,
429 if (!ecryptfs_superblock_to_private(sb
)) {
430 ecryptfs_printk(KERN_WARNING
, "Out of memory\n");
434 sb
->s_op
= &ecryptfs_sops
;
435 /* Released through deactivate_super(sb) from get_sb_nodev */
436 sb
->s_root
= d_alloc(NULL
, &(const struct qstr
) {
437 .hash
= 0,.name
= "/",.len
= 1});
439 ecryptfs_printk(KERN_ERR
, "d_alloc failed\n");
443 sb
->s_root
->d_op
= &ecryptfs_dops
;
444 sb
->s_root
->d_sb
= sb
;
445 sb
->s_root
->d_parent
= sb
->s_root
;
446 /* Released in d_release when dput(sb->s_root) is called */
447 /* through deactivate_super(sb) from get_sb_nodev() */
448 ecryptfs_set_dentry_private(sb
->s_root
,
449 kmem_cache_zalloc(ecryptfs_dentry_info_cache
,
451 if (!ecryptfs_dentry_to_private(sb
->s_root
)) {
452 ecryptfs_printk(KERN_ERR
,
453 "dentry_info_cache alloc failed\n");
459 /* Should be able to rely on deactivate_super called from
465 * ecryptfs_read_super
466 * @sb: The ecryptfs super block
467 * @dev_name: The path to mount over
469 * Read the super block of the lower filesystem, and use
470 * ecryptfs_interpose to create our initial inode and super block
473 static int ecryptfs_read_super(struct super_block
*sb
, const char *dev_name
)
478 rc
= kern_path(dev_name
, LOOKUP_FOLLOW
| LOOKUP_DIRECTORY
, &path
);
480 ecryptfs_printk(KERN_WARNING
, "path_lookup() failed\n");
483 ecryptfs_set_superblock_lower(sb
, path
.dentry
->d_sb
);
484 sb
->s_maxbytes
= path
.dentry
->d_sb
->s_maxbytes
;
485 sb
->s_blocksize
= path
.dentry
->d_sb
->s_blocksize
;
486 ecryptfs_set_dentry_lower(sb
->s_root
, path
.dentry
);
487 ecryptfs_set_dentry_lower_mnt(sb
->s_root
, path
.mnt
);
488 rc
= ecryptfs_interpose(path
.dentry
, sb
->s_root
, sb
, 0);
503 * @dev_name: The path to mount over
504 * @raw_data: The options passed into the kernel
506 * The whole ecryptfs_get_sb process is broken into 4 functions:
507 * ecryptfs_parse_options(): handle options passed to ecryptfs, if any
508 * ecryptfs_fill_super(): used by get_sb_nodev, fills out the super_block
509 * with as much information as it can before needing
510 * the lower filesystem.
511 * ecryptfs_read_super(): this accesses the lower filesystem and uses
512 * ecryptfs_interpolate to perform most of the linking
513 * ecryptfs_interpolate(): links the lower filesystem into ecryptfs
515 static int ecryptfs_get_sb(struct file_system_type
*fs_type
, int flags
,
516 const char *dev_name
, void *raw_data
,
517 struct vfsmount
*mnt
)
520 struct super_block
*sb
;
522 rc
= get_sb_nodev(fs_type
, flags
, raw_data
, ecryptfs_fill_super
, mnt
);
524 printk(KERN_ERR
"Getting sb failed; rc = [%d]\n", rc
);
528 rc
= ecryptfs_parse_options(sb
, raw_data
);
530 printk(KERN_ERR
"Error parsing options; rc = [%d]\n", rc
);
533 rc
= ecryptfs_read_super(sb
, dev_name
);
535 printk(KERN_ERR
"Reading sb failed; rc = [%d]\n", rc
);
541 up_write(&sb
->s_umount
);
542 deactivate_super(sb
);
548 * ecryptfs_kill_block_super
549 * @sb: The ecryptfs super block
551 * Used to bring the superblock down and free the private data.
552 * Private data is free'd in ecryptfs_put_super()
554 static void ecryptfs_kill_block_super(struct super_block
*sb
)
556 generic_shutdown_super(sb
);
559 static struct file_system_type ecryptfs_fs_type
= {
560 .owner
= THIS_MODULE
,
562 .get_sb
= ecryptfs_get_sb
,
563 .kill_sb
= ecryptfs_kill_block_super
,
568 * inode_info_init_once
570 * Initializes the ecryptfs_inode_info_cache when it is created
573 inode_info_init_once(void *vptr
)
575 struct ecryptfs_inode_info
*ei
= (struct ecryptfs_inode_info
*)vptr
;
577 inode_init_once(&ei
->vfs_inode
);
580 static struct ecryptfs_cache_info
{
581 struct kmem_cache
**cache
;
584 void (*ctor
)(void *obj
);
585 } ecryptfs_cache_infos
[] = {
587 .cache
= &ecryptfs_auth_tok_list_item_cache
,
588 .name
= "ecryptfs_auth_tok_list_item",
589 .size
= sizeof(struct ecryptfs_auth_tok_list_item
),
592 .cache
= &ecryptfs_file_info_cache
,
593 .name
= "ecryptfs_file_cache",
594 .size
= sizeof(struct ecryptfs_file_info
),
597 .cache
= &ecryptfs_dentry_info_cache
,
598 .name
= "ecryptfs_dentry_info_cache",
599 .size
= sizeof(struct ecryptfs_dentry_info
),
602 .cache
= &ecryptfs_inode_info_cache
,
603 .name
= "ecryptfs_inode_cache",
604 .size
= sizeof(struct ecryptfs_inode_info
),
605 .ctor
= inode_info_init_once
,
608 .cache
= &ecryptfs_sb_info_cache
,
609 .name
= "ecryptfs_sb_cache",
610 .size
= sizeof(struct ecryptfs_sb_info
),
613 .cache
= &ecryptfs_header_cache_1
,
614 .name
= "ecryptfs_headers_1",
615 .size
= PAGE_CACHE_SIZE
,
618 .cache
= &ecryptfs_header_cache_2
,
619 .name
= "ecryptfs_headers_2",
620 .size
= PAGE_CACHE_SIZE
,
623 .cache
= &ecryptfs_xattr_cache
,
624 .name
= "ecryptfs_xattr_cache",
625 .size
= PAGE_CACHE_SIZE
,
628 .cache
= &ecryptfs_key_record_cache
,
629 .name
= "ecryptfs_key_record_cache",
630 .size
= sizeof(struct ecryptfs_key_record
),
633 .cache
= &ecryptfs_key_sig_cache
,
634 .name
= "ecryptfs_key_sig_cache",
635 .size
= sizeof(struct ecryptfs_key_sig
),
638 .cache
= &ecryptfs_global_auth_tok_cache
,
639 .name
= "ecryptfs_global_auth_tok_cache",
640 .size
= sizeof(struct ecryptfs_global_auth_tok
),
643 .cache
= &ecryptfs_key_tfm_cache
,
644 .name
= "ecryptfs_key_tfm_cache",
645 .size
= sizeof(struct ecryptfs_key_tfm
),
648 .cache
= &ecryptfs_open_req_cache
,
649 .name
= "ecryptfs_open_req_cache",
650 .size
= sizeof(struct ecryptfs_open_req
),
654 static void ecryptfs_free_kmem_caches(void)
658 for (i
= 0; i
< ARRAY_SIZE(ecryptfs_cache_infos
); i
++) {
659 struct ecryptfs_cache_info
*info
;
661 info
= &ecryptfs_cache_infos
[i
];
663 kmem_cache_destroy(*(info
->cache
));
668 * ecryptfs_init_kmem_caches
670 * Returns zero on success; non-zero otherwise
672 static int ecryptfs_init_kmem_caches(void)
676 for (i
= 0; i
< ARRAY_SIZE(ecryptfs_cache_infos
); i
++) {
677 struct ecryptfs_cache_info
*info
;
679 info
= &ecryptfs_cache_infos
[i
];
680 *(info
->cache
) = kmem_cache_create(info
->name
, info
->size
,
681 0, SLAB_HWCACHE_ALIGN
, info
->ctor
);
682 if (!*(info
->cache
)) {
683 ecryptfs_free_kmem_caches();
684 ecryptfs_printk(KERN_WARNING
, "%s: "
685 "kmem_cache_create failed\n",
693 static struct kobject
*ecryptfs_kobj
;
695 static ssize_t
version_show(struct kobject
*kobj
,
696 struct kobj_attribute
*attr
, char *buff
)
698 return snprintf(buff
, PAGE_SIZE
, "%d\n", ECRYPTFS_VERSIONING_MASK
);
701 static struct kobj_attribute version_attr
= __ATTR_RO(version
);
703 static struct attribute
*attributes
[] = {
708 static struct attribute_group attr_group
= {
712 static int do_sysfs_registration(void)
716 ecryptfs_kobj
= kobject_create_and_add("ecryptfs", fs_kobj
);
717 if (!ecryptfs_kobj
) {
718 printk(KERN_ERR
"Unable to create ecryptfs kset\n");
722 rc
= sysfs_create_group(ecryptfs_kobj
, &attr_group
);
725 "Unable to create ecryptfs version attributes\n");
726 kobject_put(ecryptfs_kobj
);
732 static void do_sysfs_unregistration(void)
734 sysfs_remove_group(ecryptfs_kobj
, &attr_group
);
735 kobject_put(ecryptfs_kobj
);
738 static int __init
ecryptfs_init(void)
742 if (ECRYPTFS_DEFAULT_EXTENT_SIZE
> PAGE_CACHE_SIZE
) {
744 ecryptfs_printk(KERN_ERR
, "The eCryptfs extent size is "
745 "larger than the host's page size, and so "
746 "eCryptfs cannot run on this system. The "
747 "default eCryptfs extent size is [%d] bytes; "
748 "the page size is [%d] bytes.\n",
749 ECRYPTFS_DEFAULT_EXTENT_SIZE
, PAGE_CACHE_SIZE
);
752 rc
= ecryptfs_init_kmem_caches();
755 "Failed to allocate one or more kmem_cache objects\n");
758 rc
= register_filesystem(&ecryptfs_fs_type
);
760 printk(KERN_ERR
"Failed to register filesystem\n");
761 goto out_free_kmem_caches
;
763 rc
= do_sysfs_registration();
765 printk(KERN_ERR
"sysfs registration failed\n");
766 goto out_unregister_filesystem
;
768 rc
= ecryptfs_init_kthread();
770 printk(KERN_ERR
"%s: kthread initialization failed; "
771 "rc = [%d]\n", __func__
, rc
);
772 goto out_do_sysfs_unregistration
;
774 rc
= ecryptfs_init_messaging();
776 printk(KERN_ERR
"Failure occured while attempting to "
777 "initialize the communications channel to "
779 goto out_destroy_kthread
;
781 rc
= ecryptfs_init_crypto();
783 printk(KERN_ERR
"Failure whilst attempting to init crypto; "
785 goto out_release_messaging
;
787 if (ecryptfs_verbosity
> 0)
788 printk(KERN_CRIT
"eCryptfs verbosity set to %d. Secret values "
789 "will be written to the syslog!\n", ecryptfs_verbosity
);
792 out_release_messaging
:
793 ecryptfs_release_messaging();
795 ecryptfs_destroy_kthread();
796 out_do_sysfs_unregistration
:
797 do_sysfs_unregistration();
798 out_unregister_filesystem
:
799 unregister_filesystem(&ecryptfs_fs_type
);
800 out_free_kmem_caches
:
801 ecryptfs_free_kmem_caches();
806 static void __exit
ecryptfs_exit(void)
810 rc
= ecryptfs_destroy_crypto();
812 printk(KERN_ERR
"Failure whilst attempting to destroy crypto; "
814 ecryptfs_release_messaging();
815 ecryptfs_destroy_kthread();
816 do_sysfs_unregistration();
817 unregister_filesystem(&ecryptfs_fs_type
);
818 ecryptfs_free_kmem_caches();
821 MODULE_AUTHOR("Michael A. Halcrow <mhalcrow@us.ibm.com>");
822 MODULE_DESCRIPTION("eCryptfs");
824 MODULE_LICENSE("GPL");
826 module_init(ecryptfs_init
)
827 module_exit(ecryptfs_exit
)