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
);
208 enum { ecryptfs_opt_sig
, ecryptfs_opt_ecryptfs_sig
,
209 ecryptfs_opt_cipher
, ecryptfs_opt_ecryptfs_cipher
,
210 ecryptfs_opt_ecryptfs_key_bytes
,
211 ecryptfs_opt_passthrough
, ecryptfs_opt_xattr_metadata
,
212 ecryptfs_opt_encrypted_view
, ecryptfs_opt_err
};
214 static match_table_t tokens
= {
215 {ecryptfs_opt_sig
, "sig=%s"},
216 {ecryptfs_opt_ecryptfs_sig
, "ecryptfs_sig=%s"},
217 {ecryptfs_opt_cipher
, "cipher=%s"},
218 {ecryptfs_opt_ecryptfs_cipher
, "ecryptfs_cipher=%s"},
219 {ecryptfs_opt_ecryptfs_key_bytes
, "ecryptfs_key_bytes=%u"},
220 {ecryptfs_opt_passthrough
, "ecryptfs_passthrough"},
221 {ecryptfs_opt_xattr_metadata
, "ecryptfs_xattr_metadata"},
222 {ecryptfs_opt_encrypted_view
, "ecryptfs_encrypted_view"},
223 {ecryptfs_opt_err
, NULL
}
226 static int ecryptfs_init_global_auth_toks(
227 struct ecryptfs_mount_crypt_stat
*mount_crypt_stat
)
229 struct ecryptfs_global_auth_tok
*global_auth_tok
;
232 list_for_each_entry(global_auth_tok
,
233 &mount_crypt_stat
->global_auth_tok_list
,
234 mount_crypt_stat_list
) {
235 rc
= ecryptfs_keyring_auth_tok_for_sig(
236 &global_auth_tok
->global_auth_tok_key
,
237 &global_auth_tok
->global_auth_tok
,
238 global_auth_tok
->sig
);
240 printk(KERN_ERR
"Could not find valid key in user "
241 "session keyring for sig specified in mount "
242 "option: [%s]\n", global_auth_tok
->sig
);
243 global_auth_tok
->flags
|= ECRYPTFS_AUTH_TOK_INVALID
;
246 global_auth_tok
->flags
&= ~ECRYPTFS_AUTH_TOK_INVALID
;
252 static void ecryptfs_init_mount_crypt_stat(
253 struct ecryptfs_mount_crypt_stat
*mount_crypt_stat
)
255 memset((void *)mount_crypt_stat
, 0,
256 sizeof(struct ecryptfs_mount_crypt_stat
));
257 INIT_LIST_HEAD(&mount_crypt_stat
->global_auth_tok_list
);
258 mutex_init(&mount_crypt_stat
->global_auth_tok_list_mutex
);
259 mount_crypt_stat
->flags
|= ECRYPTFS_MOUNT_CRYPT_STAT_INITIALIZED
;
263 * ecryptfs_parse_options
264 * @sb: The ecryptfs super block
265 * @options: The options pased to the kernel
267 * Parse mount options:
268 * debug=N - ecryptfs_verbosity level for debug output
269 * sig=XXX - description(signature) of the key to use
271 * Returns the dentry object of the lower-level (lower/interposed)
272 * directory; We want to mount our stackable file system on top of
273 * that lower directory.
275 * The signature of the key to use must be the description of a key
276 * already in the keyring. Mounting will fail if the key can not be
279 * Returns zero on success; non-zero on error
281 static int ecryptfs_parse_options(struct super_block
*sb
, char *options
)
286 int cipher_name_set
= 0;
287 int cipher_key_bytes
;
288 int cipher_key_bytes_set
= 0;
289 struct ecryptfs_mount_crypt_stat
*mount_crypt_stat
=
290 &ecryptfs_superblock_to_private(sb
)->mount_crypt_stat
;
291 substring_t args
[MAX_OPT_ARGS
];
294 char *cipher_name_dst
;
295 char *cipher_name_src
;
296 char *cipher_key_bytes_src
;
302 ecryptfs_init_mount_crypt_stat(mount_crypt_stat
);
303 while ((p
= strsep(&options
, ",")) != NULL
) {
306 token
= match_token(p
, tokens
, args
);
308 case ecryptfs_opt_sig
:
309 case ecryptfs_opt_ecryptfs_sig
:
310 sig_src
= args
[0].from
;
311 rc
= ecryptfs_add_global_auth_tok(mount_crypt_stat
,
314 printk(KERN_ERR
"Error attempting to register "
315 "global sig; rc = [%d]\n", rc
);
320 case ecryptfs_opt_cipher
:
321 case ecryptfs_opt_ecryptfs_cipher
:
322 cipher_name_src
= args
[0].from
;
325 global_default_cipher_name
;
326 strncpy(cipher_name_dst
, cipher_name_src
,
327 ECRYPTFS_MAX_CIPHER_NAME_SIZE
);
328 ecryptfs_printk(KERN_DEBUG
,
329 "The mount_crypt_stat "
330 "global_default_cipher_name set to: "
331 "[%s]\n", cipher_name_dst
);
334 case ecryptfs_opt_ecryptfs_key_bytes
:
335 cipher_key_bytes_src
= args
[0].from
;
337 (int)simple_strtol(cipher_key_bytes_src
,
338 &cipher_key_bytes_src
, 0);
339 mount_crypt_stat
->global_default_cipher_key_size
=
341 ecryptfs_printk(KERN_DEBUG
,
342 "The mount_crypt_stat "
343 "global_default_cipher_key_size "
344 "set to: [%d]\n", mount_crypt_stat
->
345 global_default_cipher_key_size
);
346 cipher_key_bytes_set
= 1;
348 case ecryptfs_opt_passthrough
:
349 mount_crypt_stat
->flags
|=
350 ECRYPTFS_PLAINTEXT_PASSTHROUGH_ENABLED
;
352 case ecryptfs_opt_xattr_metadata
:
353 mount_crypt_stat
->flags
|=
354 ECRYPTFS_XATTR_METADATA_ENABLED
;
356 case ecryptfs_opt_encrypted_view
:
357 mount_crypt_stat
->flags
|=
358 ECRYPTFS_XATTR_METADATA_ENABLED
;
359 mount_crypt_stat
->flags
|=
360 ECRYPTFS_ENCRYPTED_VIEW_ENABLED
;
362 case ecryptfs_opt_err
:
364 ecryptfs_printk(KERN_WARNING
,
365 "eCryptfs: unrecognized option '%s'\n",
371 ecryptfs_printk(KERN_ERR
, "You must supply at least one valid "
372 "auth tok signature as a mount "
373 "parameter; see the eCryptfs README\n");
376 if (!cipher_name_set
) {
377 int cipher_name_len
= strlen(ECRYPTFS_DEFAULT_CIPHER
);
379 BUG_ON(cipher_name_len
>= ECRYPTFS_MAX_CIPHER_NAME_SIZE
);
381 strcpy(mount_crypt_stat
->global_default_cipher_name
,
382 ECRYPTFS_DEFAULT_CIPHER
);
384 if (!cipher_key_bytes_set
) {
385 mount_crypt_stat
->global_default_cipher_key_size
= 0;
387 mutex_lock(&key_tfm_list_mutex
);
388 if (!ecryptfs_tfm_exists(mount_crypt_stat
->global_default_cipher_name
,
390 rc
= ecryptfs_add_new_key_tfm(
391 NULL
, mount_crypt_stat
->global_default_cipher_name
,
392 mount_crypt_stat
->global_default_cipher_key_size
);
393 mutex_unlock(&key_tfm_list_mutex
);
395 printk(KERN_ERR
"Error attempting to initialize cipher with "
396 "name = [%s] and key size = [%td]; rc = [%d]\n",
397 mount_crypt_stat
->global_default_cipher_name
,
398 mount_crypt_stat
->global_default_cipher_key_size
, rc
);
402 rc
= ecryptfs_init_global_auth_toks(mount_crypt_stat
);
404 printk(KERN_WARNING
"One or more global auth toks could not "
405 "properly register; rc = [%d]\n", rc
);
411 struct kmem_cache
*ecryptfs_sb_info_cache
;
414 * ecryptfs_fill_super
415 * @sb: The ecryptfs super block
416 * @raw_data: The options passed to mount
417 * @silent: Not used but required by function prototype
419 * Sets up what we can of the sb, rest is done in ecryptfs_read_super
421 * Returns zero on success; non-zero otherwise
424 ecryptfs_fill_super(struct super_block
*sb
, void *raw_data
, int silent
)
428 /* Released in ecryptfs_put_super() */
429 ecryptfs_set_superblock_private(sb
,
430 kmem_cache_zalloc(ecryptfs_sb_info_cache
,
432 if (!ecryptfs_superblock_to_private(sb
)) {
433 ecryptfs_printk(KERN_WARNING
, "Out of memory\n");
437 sb
->s_op
= &ecryptfs_sops
;
438 /* Released through deactivate_super(sb) from get_sb_nodev */
439 sb
->s_root
= d_alloc(NULL
, &(const struct qstr
) {
440 .hash
= 0,.name
= "/",.len
= 1});
442 ecryptfs_printk(KERN_ERR
, "d_alloc failed\n");
446 sb
->s_root
->d_op
= &ecryptfs_dops
;
447 sb
->s_root
->d_sb
= sb
;
448 sb
->s_root
->d_parent
= sb
->s_root
;
449 /* Released in d_release when dput(sb->s_root) is called */
450 /* through deactivate_super(sb) from get_sb_nodev() */
451 ecryptfs_set_dentry_private(sb
->s_root
,
452 kmem_cache_zalloc(ecryptfs_dentry_info_cache
,
454 if (!ecryptfs_dentry_to_private(sb
->s_root
)) {
455 ecryptfs_printk(KERN_ERR
,
456 "dentry_info_cache alloc failed\n");
462 /* Should be able to rely on deactivate_super called from
468 * ecryptfs_read_super
469 * @sb: The ecryptfs super block
470 * @dev_name: The path to mount over
472 * Read the super block of the lower filesystem, and use
473 * ecryptfs_interpose to create our initial inode and super block
476 static int ecryptfs_read_super(struct super_block
*sb
, const char *dev_name
)
480 struct dentry
*lower_root
;
481 struct vfsmount
*lower_mnt
;
483 memset(&nd
, 0, sizeof(struct nameidata
));
484 rc
= path_lookup(dev_name
, LOOKUP_FOLLOW
| LOOKUP_DIRECTORY
, &nd
);
486 ecryptfs_printk(KERN_WARNING
, "path_lookup() failed\n");
489 lower_root
= nd
.path
.dentry
;
490 lower_mnt
= nd
.path
.mnt
;
491 ecryptfs_set_superblock_lower(sb
, lower_root
->d_sb
);
492 sb
->s_maxbytes
= lower_root
->d_sb
->s_maxbytes
;
493 sb
->s_blocksize
= lower_root
->d_sb
->s_blocksize
;
494 ecryptfs_set_dentry_lower(sb
->s_root
, lower_root
);
495 ecryptfs_set_dentry_lower_mnt(sb
->s_root
, lower_mnt
);
496 rc
= ecryptfs_interpose(lower_root
, sb
->s_root
, sb
, 0);
511 * @dev_name: The path to mount over
512 * @raw_data: The options passed into the kernel
514 * The whole ecryptfs_get_sb process is broken into 4 functions:
515 * ecryptfs_parse_options(): handle options passed to ecryptfs, if any
516 * ecryptfs_fill_super(): used by get_sb_nodev, fills out the super_block
517 * with as much information as it can before needing
518 * the lower filesystem.
519 * ecryptfs_read_super(): this accesses the lower filesystem and uses
520 * ecryptfs_interpolate to perform most of the linking
521 * ecryptfs_interpolate(): links the lower filesystem into ecryptfs
523 static int ecryptfs_get_sb(struct file_system_type
*fs_type
, int flags
,
524 const char *dev_name
, void *raw_data
,
525 struct vfsmount
*mnt
)
528 struct super_block
*sb
;
530 rc
= get_sb_nodev(fs_type
, flags
, raw_data
, ecryptfs_fill_super
, mnt
);
532 printk(KERN_ERR
"Getting sb failed; rc = [%d]\n", rc
);
536 rc
= ecryptfs_parse_options(sb
, raw_data
);
538 printk(KERN_ERR
"Error parsing options; rc = [%d]\n", rc
);
541 rc
= ecryptfs_read_super(sb
, dev_name
);
543 printk(KERN_ERR
"Reading sb failed; rc = [%d]\n", rc
);
549 up_write(&sb
->s_umount
);
550 deactivate_super(sb
);
556 * ecryptfs_kill_block_super
557 * @sb: The ecryptfs super block
559 * Used to bring the superblock down and free the private data.
560 * Private data is free'd in ecryptfs_put_super()
562 static void ecryptfs_kill_block_super(struct super_block
*sb
)
564 generic_shutdown_super(sb
);
567 static struct file_system_type ecryptfs_fs_type
= {
568 .owner
= THIS_MODULE
,
570 .get_sb
= ecryptfs_get_sb
,
571 .kill_sb
= ecryptfs_kill_block_super
,
576 * inode_info_init_once
578 * Initializes the ecryptfs_inode_info_cache when it is created
581 inode_info_init_once(void *vptr
)
583 struct ecryptfs_inode_info
*ei
= (struct ecryptfs_inode_info
*)vptr
;
585 inode_init_once(&ei
->vfs_inode
);
588 static struct ecryptfs_cache_info
{
589 struct kmem_cache
**cache
;
592 void (*ctor
)(void *obj
);
593 } ecryptfs_cache_infos
[] = {
595 .cache
= &ecryptfs_auth_tok_list_item_cache
,
596 .name
= "ecryptfs_auth_tok_list_item",
597 .size
= sizeof(struct ecryptfs_auth_tok_list_item
),
600 .cache
= &ecryptfs_file_info_cache
,
601 .name
= "ecryptfs_file_cache",
602 .size
= sizeof(struct ecryptfs_file_info
),
605 .cache
= &ecryptfs_dentry_info_cache
,
606 .name
= "ecryptfs_dentry_info_cache",
607 .size
= sizeof(struct ecryptfs_dentry_info
),
610 .cache
= &ecryptfs_inode_info_cache
,
611 .name
= "ecryptfs_inode_cache",
612 .size
= sizeof(struct ecryptfs_inode_info
),
613 .ctor
= inode_info_init_once
,
616 .cache
= &ecryptfs_sb_info_cache
,
617 .name
= "ecryptfs_sb_cache",
618 .size
= sizeof(struct ecryptfs_sb_info
),
621 .cache
= &ecryptfs_header_cache_1
,
622 .name
= "ecryptfs_headers_1",
623 .size
= PAGE_CACHE_SIZE
,
626 .cache
= &ecryptfs_header_cache_2
,
627 .name
= "ecryptfs_headers_2",
628 .size
= PAGE_CACHE_SIZE
,
631 .cache
= &ecryptfs_xattr_cache
,
632 .name
= "ecryptfs_xattr_cache",
633 .size
= PAGE_CACHE_SIZE
,
636 .cache
= &ecryptfs_key_record_cache
,
637 .name
= "ecryptfs_key_record_cache",
638 .size
= sizeof(struct ecryptfs_key_record
),
641 .cache
= &ecryptfs_key_sig_cache
,
642 .name
= "ecryptfs_key_sig_cache",
643 .size
= sizeof(struct ecryptfs_key_sig
),
646 .cache
= &ecryptfs_global_auth_tok_cache
,
647 .name
= "ecryptfs_global_auth_tok_cache",
648 .size
= sizeof(struct ecryptfs_global_auth_tok
),
651 .cache
= &ecryptfs_key_tfm_cache
,
652 .name
= "ecryptfs_key_tfm_cache",
653 .size
= sizeof(struct ecryptfs_key_tfm
),
656 .cache
= &ecryptfs_open_req_cache
,
657 .name
= "ecryptfs_open_req_cache",
658 .size
= sizeof(struct ecryptfs_open_req
),
662 static void ecryptfs_free_kmem_caches(void)
666 for (i
= 0; i
< ARRAY_SIZE(ecryptfs_cache_infos
); i
++) {
667 struct ecryptfs_cache_info
*info
;
669 info
= &ecryptfs_cache_infos
[i
];
671 kmem_cache_destroy(*(info
->cache
));
676 * ecryptfs_init_kmem_caches
678 * Returns zero on success; non-zero otherwise
680 static int ecryptfs_init_kmem_caches(void)
684 for (i
= 0; i
< ARRAY_SIZE(ecryptfs_cache_infos
); i
++) {
685 struct ecryptfs_cache_info
*info
;
687 info
= &ecryptfs_cache_infos
[i
];
688 *(info
->cache
) = kmem_cache_create(info
->name
, info
->size
,
689 0, SLAB_HWCACHE_ALIGN
, info
->ctor
);
690 if (!*(info
->cache
)) {
691 ecryptfs_free_kmem_caches();
692 ecryptfs_printk(KERN_WARNING
, "%s: "
693 "kmem_cache_create failed\n",
701 static struct kobject
*ecryptfs_kobj
;
703 static ssize_t
version_show(struct kobject
*kobj
,
704 struct kobj_attribute
*attr
, char *buff
)
706 return snprintf(buff
, PAGE_SIZE
, "%d\n", ECRYPTFS_VERSIONING_MASK
);
709 static struct kobj_attribute version_attr
= __ATTR_RO(version
);
711 static struct attribute
*attributes
[] = {
716 static struct attribute_group attr_group
= {
720 static int do_sysfs_registration(void)
724 ecryptfs_kobj
= kobject_create_and_add("ecryptfs", fs_kobj
);
725 if (!ecryptfs_kobj
) {
726 printk(KERN_ERR
"Unable to create ecryptfs kset\n");
730 rc
= sysfs_create_group(ecryptfs_kobj
, &attr_group
);
733 "Unable to create ecryptfs version attributes\n");
734 kobject_put(ecryptfs_kobj
);
740 static void do_sysfs_unregistration(void)
742 sysfs_remove_group(ecryptfs_kobj
, &attr_group
);
743 kobject_put(ecryptfs_kobj
);
746 static int __init
ecryptfs_init(void)
750 if (ECRYPTFS_DEFAULT_EXTENT_SIZE
> PAGE_CACHE_SIZE
) {
752 ecryptfs_printk(KERN_ERR
, "The eCryptfs extent size is "
753 "larger than the host's page size, and so "
754 "eCryptfs cannot run on this system. The "
755 "default eCryptfs extent size is [%d] bytes; "
756 "the page size is [%d] bytes.\n",
757 ECRYPTFS_DEFAULT_EXTENT_SIZE
, PAGE_CACHE_SIZE
);
760 rc
= ecryptfs_init_kmem_caches();
763 "Failed to allocate one or more kmem_cache objects\n");
766 rc
= register_filesystem(&ecryptfs_fs_type
);
768 printk(KERN_ERR
"Failed to register filesystem\n");
769 goto out_free_kmem_caches
;
771 rc
= do_sysfs_registration();
773 printk(KERN_ERR
"sysfs registration failed\n");
774 goto out_unregister_filesystem
;
776 rc
= ecryptfs_init_kthread();
778 printk(KERN_ERR
"%s: kthread initialization failed; "
779 "rc = [%d]\n", __func__
, rc
);
780 goto out_do_sysfs_unregistration
;
782 rc
= ecryptfs_init_messaging(ecryptfs_transport
);
784 printk(KERN_ERR
"Failure occured while attempting to "
785 "initialize the eCryptfs netlink socket\n");
786 goto out_destroy_kthread
;
788 rc
= ecryptfs_init_crypto();
790 printk(KERN_ERR
"Failure whilst attempting to init crypto; "
792 goto out_release_messaging
;
794 if (ecryptfs_verbosity
> 0)
795 printk(KERN_CRIT
"eCryptfs verbosity set to %d. Secret values "
796 "will be written to the syslog!\n", ecryptfs_verbosity
);
799 out_release_messaging
:
800 ecryptfs_release_messaging(ecryptfs_transport
);
802 ecryptfs_destroy_kthread();
803 out_do_sysfs_unregistration
:
804 do_sysfs_unregistration();
805 out_unregister_filesystem
:
806 unregister_filesystem(&ecryptfs_fs_type
);
807 out_free_kmem_caches
:
808 ecryptfs_free_kmem_caches();
813 static void __exit
ecryptfs_exit(void)
817 rc
= ecryptfs_destroy_crypto();
819 printk(KERN_ERR
"Failure whilst attempting to destroy crypto; "
821 ecryptfs_release_messaging(ecryptfs_transport
);
822 ecryptfs_destroy_kthread();
823 do_sysfs_unregistration();
824 unregister_filesystem(&ecryptfs_fs_type
);
825 ecryptfs_free_kmem_caches();
828 MODULE_AUTHOR("Michael A. Halcrow <mhalcrow@us.ibm.com>");
829 MODULE_DESCRIPTION("eCryptfs");
831 MODULE_LICENSE("GPL");
833 module_init(ecryptfs_init
)
834 module_exit(ecryptfs_exit
)