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-2006 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/dcache.h>
36 #include <linux/pagemap.h>
37 #include <linux/key.h>
38 #include <linux/parser.h>
39 #include <linux/fs_stack.h>
40 #include "ecryptfs_kernel.h"
43 * Module parameter that defines the ecryptfs_verbosity level.
45 int ecryptfs_verbosity
= 0;
47 module_param(ecryptfs_verbosity
, int, 0);
48 MODULE_PARM_DESC(ecryptfs_verbosity
,
49 "Initial verbosity level (0 or 1; defaults to "
50 "0, which is Quiet)");
53 * Module parameter that defines the number of netlink message buffer
56 unsigned int ecryptfs_message_buf_len
= ECRYPTFS_DEFAULT_MSG_CTX_ELEMS
;
58 module_param(ecryptfs_message_buf_len
, uint
, 0);
59 MODULE_PARM_DESC(ecryptfs_message_buf_len
,
60 "Number of message buffer elements");
63 * Module parameter that defines the maximum guaranteed amount of time to wait
64 * for a response through netlink. The actual sleep time will be, more than
65 * likely, a small amount greater than this specified value, but only less if
66 * the netlink message successfully arrives.
68 signed long ecryptfs_message_wait_timeout
= ECRYPTFS_MAX_MSG_CTX_TTL
/ HZ
;
70 module_param(ecryptfs_message_wait_timeout
, long, 0);
71 MODULE_PARM_DESC(ecryptfs_message_wait_timeout
,
72 "Maximum number of seconds that an operation will "
73 "sleep while waiting for a message response from "
77 * Module parameter that is an estimate of the maximum number of users
78 * that will be concurrently using eCryptfs. Set this to the right
79 * value to balance performance and memory use.
81 unsigned int ecryptfs_number_of_users
= ECRYPTFS_DEFAULT_NUM_USERS
;
83 module_param(ecryptfs_number_of_users
, uint
, 0);
84 MODULE_PARM_DESC(ecryptfs_number_of_users
, "An estimate of the number of "
85 "concurrent users of eCryptfs");
87 unsigned int ecryptfs_transport
= ECRYPTFS_DEFAULT_TRANSPORT
;
89 void __ecryptfs_printk(const char *fmt
, ...)
93 if (fmt
[1] == '7') { /* KERN_DEBUG */
94 if (ecryptfs_verbosity
>= 1)
103 * @lower_dentry: Existing dentry in the lower filesystem
104 * @dentry: ecryptfs' dentry
105 * @sb: ecryptfs's super_block
106 * @flag: If set to true, then d_add is called, else d_instantiate is called
108 * Interposes upper and lower dentries.
110 * Returns zero on success; non-zero otherwise
112 int ecryptfs_interpose(struct dentry
*lower_dentry
, struct dentry
*dentry
,
113 struct super_block
*sb
, int flag
)
115 struct inode
*lower_inode
;
119 lower_inode
= lower_dentry
->d_inode
;
120 if (lower_inode
->i_sb
!= ecryptfs_superblock_to_lower(sb
)) {
124 if (!igrab(lower_inode
)) {
128 inode
= iget5_locked(sb
, (unsigned long)lower_inode
,
129 ecryptfs_inode_test
, ecryptfs_inode_set
,
136 if (inode
->i_state
& I_NEW
)
137 unlock_new_inode(inode
);
140 if (S_ISLNK(lower_inode
->i_mode
))
141 inode
->i_op
= &ecryptfs_symlink_iops
;
142 else if (S_ISDIR(lower_inode
->i_mode
))
143 inode
->i_op
= &ecryptfs_dir_iops
;
144 if (S_ISDIR(lower_inode
->i_mode
))
145 inode
->i_fop
= &ecryptfs_dir_fops
;
146 if (special_file(lower_inode
->i_mode
))
147 init_special_inode(inode
, lower_inode
->i_mode
,
148 lower_inode
->i_rdev
);
149 dentry
->d_op
= &ecryptfs_dops
;
151 d_add(dentry
, inode
);
153 d_instantiate(dentry
, inode
);
154 fsstack_copy_attr_all(inode
, lower_inode
, NULL
);
155 /* This size will be overwritten for real files w/ headers and
157 fsstack_copy_inode_size(inode
, lower_inode
);
162 enum { ecryptfs_opt_sig
, ecryptfs_opt_ecryptfs_sig
, ecryptfs_opt_debug
,
163 ecryptfs_opt_ecryptfs_debug
, ecryptfs_opt_cipher
,
164 ecryptfs_opt_ecryptfs_cipher
, ecryptfs_opt_ecryptfs_key_bytes
,
165 ecryptfs_opt_passthrough
, ecryptfs_opt_err
};
167 static match_table_t tokens
= {
168 {ecryptfs_opt_sig
, "sig=%s"},
169 {ecryptfs_opt_ecryptfs_sig
, "ecryptfs_sig=%s"},
170 {ecryptfs_opt_debug
, "debug=%u"},
171 {ecryptfs_opt_ecryptfs_debug
, "ecryptfs_debug=%u"},
172 {ecryptfs_opt_cipher
, "cipher=%s"},
173 {ecryptfs_opt_ecryptfs_cipher
, "ecryptfs_cipher=%s"},
174 {ecryptfs_opt_ecryptfs_key_bytes
, "ecryptfs_key_bytes=%u"},
175 {ecryptfs_opt_passthrough
, "ecryptfs_passthrough"},
176 {ecryptfs_opt_err
, NULL
}
180 * ecryptfs_verify_version
181 * @version: The version number to confirm
183 * Returns zero on good version; non-zero otherwise
185 static int ecryptfs_verify_version(u16 version
)
191 major
= ((version
>> 8) & 0xFF);
192 minor
= (version
& 0xFF);
193 if (major
!= ECRYPTFS_VERSION_MAJOR
) {
194 ecryptfs_printk(KERN_ERR
, "Major version number mismatch. "
195 "Expected [%d]; got [%d]\n",
196 ECRYPTFS_VERSION_MAJOR
, major
);
200 if (minor
!= ECRYPTFS_VERSION_MINOR
) {
201 ecryptfs_printk(KERN_ERR
, "Minor version number mismatch. "
202 "Expected [%d]; got [%d]\n",
203 ECRYPTFS_VERSION_MINOR
, minor
);
212 * ecryptfs_parse_options
213 * @sb: The ecryptfs super block
214 * @options: The options pased to the kernel
216 * Parse mount options:
217 * debug=N - ecryptfs_verbosity level for debug output
218 * sig=XXX - description(signature) of the key to use
220 * Returns the dentry object of the lower-level (lower/interposed)
221 * directory; We want to mount our stackable file system on top of
222 * that lower directory.
224 * The signature of the key to use must be the description of a key
225 * already in the keyring. Mounting will fail if the key can not be
228 * Returns zero on success; non-zero on error
230 static int ecryptfs_parse_options(struct super_block
*sb
, char *options
)
235 int cipher_name_set
= 0;
236 int cipher_key_bytes
;
237 int cipher_key_bytes_set
= 0;
238 struct key
*auth_tok_key
= NULL
;
239 struct ecryptfs_auth_tok
*auth_tok
= NULL
;
240 struct ecryptfs_mount_crypt_stat
*mount_crypt_stat
=
241 &ecryptfs_superblock_to_private(sb
)->mount_crypt_stat
;
242 substring_t args
[MAX_OPT_ARGS
];
247 char *cipher_name_dst
;
248 char *cipher_name_src
;
249 char *cipher_key_bytes_src
;
256 while ((p
= strsep(&options
, ",")) != NULL
) {
259 token
= match_token(p
, tokens
, args
);
261 case ecryptfs_opt_sig
:
262 case ecryptfs_opt_ecryptfs_sig
:
263 sig_src
= args
[0].from
;
265 mount_crypt_stat
->global_auth_tok_sig
;
266 memcpy(sig_dst
, sig_src
, ECRYPTFS_SIG_SIZE_HEX
);
267 sig_dst
[ECRYPTFS_SIG_SIZE_HEX
] = '\0';
268 ecryptfs_printk(KERN_DEBUG
,
269 "The mount_crypt_stat "
270 "global_auth_tok_sig set to: "
274 case ecryptfs_opt_debug
:
275 case ecryptfs_opt_ecryptfs_debug
:
276 debug_src
= args
[0].from
;
278 (int)simple_strtol(debug_src
, &debug_src
,
280 ecryptfs_printk(KERN_DEBUG
,
281 "Verbosity set to [%d]" "\n",
284 case ecryptfs_opt_cipher
:
285 case ecryptfs_opt_ecryptfs_cipher
:
286 cipher_name_src
= args
[0].from
;
289 global_default_cipher_name
;
290 strncpy(cipher_name_dst
, cipher_name_src
,
291 ECRYPTFS_MAX_CIPHER_NAME_SIZE
);
292 ecryptfs_printk(KERN_DEBUG
,
293 "The mount_crypt_stat "
294 "global_default_cipher_name set to: "
295 "[%s]\n", cipher_name_dst
);
298 case ecryptfs_opt_ecryptfs_key_bytes
:
299 cipher_key_bytes_src
= args
[0].from
;
301 (int)simple_strtol(cipher_key_bytes_src
,
302 &cipher_key_bytes_src
, 0);
303 mount_crypt_stat
->global_default_cipher_key_size
=
305 ecryptfs_printk(KERN_DEBUG
,
306 "The mount_crypt_stat "
307 "global_default_cipher_key_size "
308 "set to: [%d]\n", mount_crypt_stat
->
309 global_default_cipher_key_size
);
310 cipher_key_bytes_set
= 1;
312 case ecryptfs_opt_passthrough
:
313 mount_crypt_stat
->flags
|=
314 ECRYPTFS_PLAINTEXT_PASSTHROUGH_ENABLED
;
316 case ecryptfs_opt_err
:
318 ecryptfs_printk(KERN_WARNING
,
319 "eCryptfs: unrecognized option '%s'\n",
323 /* Do not support lack of mount-wide signature in 0.1
327 ecryptfs_printk(KERN_ERR
, "You must supply a valid "
328 "passphrase auth tok signature as a mount "
329 "parameter; see the eCryptfs README\n");
332 if (!cipher_name_set
) {
333 cipher_name_len
= strlen(ECRYPTFS_DEFAULT_CIPHER
);
334 if (unlikely(cipher_name_len
335 >= ECRYPTFS_MAX_CIPHER_NAME_SIZE
)) {
340 memcpy(mount_crypt_stat
->global_default_cipher_name
,
341 ECRYPTFS_DEFAULT_CIPHER
, cipher_name_len
);
342 mount_crypt_stat
->global_default_cipher_name
[cipher_name_len
]
345 if (!cipher_key_bytes_set
) {
346 mount_crypt_stat
->global_default_cipher_key_size
= 0;
348 rc
= ecryptfs_process_cipher(
349 &mount_crypt_stat
->global_key_tfm
,
350 mount_crypt_stat
->global_default_cipher_name
,
351 &mount_crypt_stat
->global_default_cipher_key_size
);
353 printk(KERN_ERR
"Error attempting to initialize cipher [%s] "
354 "with key size [%Zd] bytes; rc = [%d]\n",
355 mount_crypt_stat
->global_default_cipher_name
,
356 mount_crypt_stat
->global_default_cipher_key_size
, rc
);
357 mount_crypt_stat
->global_key_tfm
= NULL
;
358 mount_crypt_stat
->global_auth_tok_key
= NULL
;
362 mutex_init(&mount_crypt_stat
->global_key_tfm_mutex
);
363 ecryptfs_printk(KERN_DEBUG
, "Requesting the key with description: "
364 "[%s]\n", mount_crypt_stat
->global_auth_tok_sig
);
365 /* The reference to this key is held until umount is done The
366 * call to key_put is done in ecryptfs_put_super() */
367 auth_tok_key
= request_key(&key_type_user
,
368 mount_crypt_stat
->global_auth_tok_sig
,
370 if (!auth_tok_key
|| IS_ERR(auth_tok_key
)) {
371 ecryptfs_printk(KERN_ERR
, "Could not find key with "
372 "description: [%s]\n",
373 mount_crypt_stat
->global_auth_tok_sig
);
374 process_request_key_err(PTR_ERR(auth_tok_key
));
378 auth_tok
= ecryptfs_get_key_payload_data(auth_tok_key
);
379 if (ecryptfs_verify_version(auth_tok
->version
)) {
380 ecryptfs_printk(KERN_ERR
, "Data structure version mismatch. "
381 "Userspace tools must match eCryptfs kernel "
382 "module with major version [%d] and minor "
383 "version [%d]\n", ECRYPTFS_VERSION_MAJOR
,
384 ECRYPTFS_VERSION_MINOR
);
388 if (auth_tok
->token_type
!= ECRYPTFS_PASSWORD
389 && auth_tok
->token_type
!= ECRYPTFS_PRIVATE_KEY
) {
390 ecryptfs_printk(KERN_ERR
, "Invalid auth_tok structure "
391 "returned from key query\n");
395 mount_crypt_stat
->global_auth_tok_key
= auth_tok_key
;
396 mount_crypt_stat
->global_auth_tok
= auth_tok
;
401 struct kmem_cache
*ecryptfs_sb_info_cache
;
404 * ecryptfs_fill_super
405 * @sb: The ecryptfs super block
406 * @raw_data: The options passed to mount
407 * @silent: Not used but required by function prototype
409 * Sets up what we can of the sb, rest is done in ecryptfs_read_super
411 * Returns zero on success; non-zero otherwise
414 ecryptfs_fill_super(struct super_block
*sb
, void *raw_data
, int silent
)
418 /* Released in ecryptfs_put_super() */
419 ecryptfs_set_superblock_private(sb
,
420 kmem_cache_zalloc(ecryptfs_sb_info_cache
,
422 if (!ecryptfs_superblock_to_private(sb
)) {
423 ecryptfs_printk(KERN_WARNING
, "Out of memory\n");
427 sb
->s_op
= &ecryptfs_sops
;
428 /* Released through deactivate_super(sb) from get_sb_nodev */
429 sb
->s_root
= d_alloc(NULL
, &(const struct qstr
) {
430 .hash
= 0,.name
= "/",.len
= 1});
432 ecryptfs_printk(KERN_ERR
, "d_alloc failed\n");
436 sb
->s_root
->d_op
= &ecryptfs_dops
;
437 sb
->s_root
->d_sb
= sb
;
438 sb
->s_root
->d_parent
= sb
->s_root
;
439 /* Released in d_release when dput(sb->s_root) is called */
440 /* through deactivate_super(sb) from get_sb_nodev() */
441 ecryptfs_set_dentry_private(sb
->s_root
,
442 kmem_cache_zalloc(ecryptfs_dentry_info_cache
,
444 if (!ecryptfs_dentry_to_private(sb
->s_root
)) {
445 ecryptfs_printk(KERN_ERR
,
446 "dentry_info_cache alloc failed\n");
452 /* Should be able to rely on deactivate_super called from
458 * ecryptfs_read_super
459 * @sb: The ecryptfs super block
460 * @dev_name: The path to mount over
462 * Read the super block of the lower filesystem, and use
463 * ecryptfs_interpose to create our initial inode and super block
466 static int ecryptfs_read_super(struct super_block
*sb
, const char *dev_name
)
470 struct dentry
*lower_root
;
471 struct vfsmount
*lower_mnt
;
473 memset(&nd
, 0, sizeof(struct nameidata
));
474 rc
= path_lookup(dev_name
, LOOKUP_FOLLOW
, &nd
);
476 ecryptfs_printk(KERN_WARNING
, "path_lookup() failed\n");
479 lower_root
= nd
.dentry
;
480 if (!lower_root
->d_inode
) {
481 ecryptfs_printk(KERN_WARNING
,
482 "No directory to interpose on\n");
487 ecryptfs_set_superblock_lower(sb
, lower_root
->d_sb
);
488 sb
->s_maxbytes
= lower_root
->d_sb
->s_maxbytes
;
489 ecryptfs_set_dentry_lower(sb
->s_root
, lower_root
);
490 ecryptfs_set_dentry_lower_mnt(sb
->s_root
, lower_mnt
);
491 if ((rc
= ecryptfs_interpose(lower_root
, sb
->s_root
, sb
, 0)))
505 * @dev_name: The path to mount over
506 * @raw_data: The options passed into the kernel
508 * The whole ecryptfs_get_sb process is broken into 4 functions:
509 * ecryptfs_parse_options(): handle options passed to ecryptfs, if any
510 * ecryptfs_fill_super(): used by get_sb_nodev, fills out the super_block
511 * with as much information as it can before needing
512 * the lower filesystem.
513 * ecryptfs_read_super(): this accesses the lower filesystem and uses
514 * ecryptfs_interpolate to perform most of the linking
515 * ecryptfs_interpolate(): links the lower filesystem into ecryptfs
517 static int ecryptfs_get_sb(struct file_system_type
*fs_type
, int flags
,
518 const char *dev_name
, void *raw_data
,
519 struct vfsmount
*mnt
)
522 struct super_block
*sb
;
524 rc
= get_sb_nodev(fs_type
, flags
, raw_data
, ecryptfs_fill_super
, mnt
);
526 printk(KERN_ERR
"Getting sb failed; rc = [%d]\n", rc
);
530 rc
= ecryptfs_parse_options(sb
, raw_data
);
532 printk(KERN_ERR
"Error parsing options; rc = [%d]\n", rc
);
535 rc
= ecryptfs_read_super(sb
, dev_name
);
537 printk(KERN_ERR
"Reading sb failed; rc = [%d]\n", rc
);
543 up_write(&sb
->s_umount
);
544 deactivate_super(sb
);
550 * ecryptfs_kill_block_super
551 * @sb: The ecryptfs super block
553 * Used to bring the superblock down and free the private data.
554 * Private data is free'd in ecryptfs_put_super()
556 static void ecryptfs_kill_block_super(struct super_block
*sb
)
558 generic_shutdown_super(sb
);
561 static struct file_system_type ecryptfs_fs_type
= {
562 .owner
= THIS_MODULE
,
564 .get_sb
= ecryptfs_get_sb
,
565 .kill_sb
= ecryptfs_kill_block_super
,
570 * inode_info_init_once
572 * Initializes the ecryptfs_inode_info_cache when it is created
575 inode_info_init_once(void *vptr
, struct kmem_cache
*cachep
, unsigned long flags
)
577 struct ecryptfs_inode_info
*ei
= (struct ecryptfs_inode_info
*)vptr
;
579 if ((flags
& (SLAB_CTOR_VERIFY
| SLAB_CTOR_CONSTRUCTOR
)) ==
580 SLAB_CTOR_CONSTRUCTOR
)
581 inode_init_once(&ei
->vfs_inode
);
584 static struct ecryptfs_cache_info
{
585 struct kmem_cache
**cache
;
588 void (*ctor
)(void*, struct kmem_cache
*, unsigned long);
589 } ecryptfs_cache_infos
[] = {
591 .cache
= &ecryptfs_auth_tok_list_item_cache
,
592 .name
= "ecryptfs_auth_tok_list_item",
593 .size
= sizeof(struct ecryptfs_auth_tok_list_item
),
596 .cache
= &ecryptfs_file_info_cache
,
597 .name
= "ecryptfs_file_cache",
598 .size
= sizeof(struct ecryptfs_file_info
),
601 .cache
= &ecryptfs_dentry_info_cache
,
602 .name
= "ecryptfs_dentry_info_cache",
603 .size
= sizeof(struct ecryptfs_dentry_info
),
606 .cache
= &ecryptfs_inode_info_cache
,
607 .name
= "ecryptfs_inode_cache",
608 .size
= sizeof(struct ecryptfs_inode_info
),
609 .ctor
= inode_info_init_once
,
612 .cache
= &ecryptfs_sb_info_cache
,
613 .name
= "ecryptfs_sb_cache",
614 .size
= sizeof(struct ecryptfs_sb_info
),
617 .cache
= &ecryptfs_header_cache_0
,
618 .name
= "ecryptfs_headers_0",
619 .size
= PAGE_CACHE_SIZE
,
622 .cache
= &ecryptfs_header_cache_1
,
623 .name
= "ecryptfs_headers_1",
624 .size
= PAGE_CACHE_SIZE
,
627 .cache
= &ecryptfs_header_cache_2
,
628 .name
= "ecryptfs_headers_2",
629 .size
= PAGE_CACHE_SIZE
,
632 .cache
= &ecryptfs_lower_page_cache
,
633 .name
= "ecryptfs_lower_page_cache",
634 .size
= PAGE_CACHE_SIZE
,
638 static void ecryptfs_free_kmem_caches(void)
642 for (i
= 0; i
< ARRAY_SIZE(ecryptfs_cache_infos
); i
++) {
643 struct ecryptfs_cache_info
*info
;
645 info
= &ecryptfs_cache_infos
[i
];
647 kmem_cache_destroy(*(info
->cache
));
652 * ecryptfs_init_kmem_caches
654 * Returns zero on success; non-zero otherwise
656 static int ecryptfs_init_kmem_caches(void)
660 for (i
= 0; i
< ARRAY_SIZE(ecryptfs_cache_infos
); i
++) {
661 struct ecryptfs_cache_info
*info
;
663 info
= &ecryptfs_cache_infos
[i
];
664 *(info
->cache
) = kmem_cache_create(info
->name
, info
->size
,
665 0, SLAB_HWCACHE_ALIGN
, info
->ctor
, NULL
);
666 if (!*(info
->cache
)) {
667 ecryptfs_free_kmem_caches();
668 ecryptfs_printk(KERN_WARNING
, "%s: "
669 "kmem_cache_create failed\n",
677 struct ecryptfs_obj
{
679 struct list_head slot_list
;
683 struct ecryptfs_attribute
{
684 struct attribute attr
;
685 ssize_t(*show
) (struct ecryptfs_obj
*, char *);
686 ssize_t(*store
) (struct ecryptfs_obj
*, const char *, size_t);
690 ecryptfs_attr_store(struct kobject
*kobj
,
691 struct attribute
*attr
, const char *buf
, size_t len
)
693 struct ecryptfs_obj
*obj
= container_of(kobj
, struct ecryptfs_obj
,
695 struct ecryptfs_attribute
*attribute
=
696 container_of(attr
, struct ecryptfs_attribute
, attr
);
698 return (attribute
->store
? attribute
->store(obj
, buf
, len
) : 0);
702 ecryptfs_attr_show(struct kobject
*kobj
, struct attribute
*attr
, char *buf
)
704 struct ecryptfs_obj
*obj
= container_of(kobj
, struct ecryptfs_obj
,
706 struct ecryptfs_attribute
*attribute
=
707 container_of(attr
, struct ecryptfs_attribute
, attr
);
709 return (attribute
->show
? attribute
->show(obj
, buf
) : 0);
712 static struct sysfs_ops ecryptfs_sysfs_ops
= {
713 .show
= ecryptfs_attr_show
,
714 .store
= ecryptfs_attr_store
717 static struct kobj_type ecryptfs_ktype
= {
718 .sysfs_ops
= &ecryptfs_sysfs_ops
721 static decl_subsys(ecryptfs
, &ecryptfs_ktype
, NULL
);
723 static ssize_t
version_show(struct ecryptfs_obj
*obj
, char *buff
)
725 return snprintf(buff
, PAGE_SIZE
, "%d\n", ECRYPTFS_VERSIONING_MASK
);
728 static struct ecryptfs_attribute sysfs_attr_version
= __ATTR_RO(version
);
730 static struct ecryptfs_version_str_map_elem
{
733 } ecryptfs_version_str_map
[] = {
734 {ECRYPTFS_VERSIONING_PASSPHRASE
, "passphrase"},
735 {ECRYPTFS_VERSIONING_PUBKEY
, "pubkey"},
736 {ECRYPTFS_VERSIONING_PLAINTEXT_PASSTHROUGH
, "plaintext passthrough"},
737 {ECRYPTFS_VERSIONING_POLICY
, "policy"}
740 static ssize_t
version_str_show(struct ecryptfs_obj
*obj
, char *buff
)
743 int remaining
= PAGE_SIZE
;
744 int total_written
= 0;
747 for (i
= 0; i
< ARRAY_SIZE(ecryptfs_version_str_map
); i
++) {
750 if (!(ECRYPTFS_VERSIONING_MASK
751 & ecryptfs_version_str_map
[i
].flag
))
753 entry_size
= strlen(ecryptfs_version_str_map
[i
].str
);
754 if ((entry_size
+ 2) > remaining
)
756 memcpy(buff
, ecryptfs_version_str_map
[i
].str
, entry_size
);
757 buff
[entry_size
++] = '\n';
758 buff
[entry_size
] = '\0';
760 total_written
+= entry_size
;
761 remaining
-= entry_size
;
764 return total_written
;
767 static struct ecryptfs_attribute sysfs_attr_version_str
= __ATTR_RO(version_str
);
769 static int do_sysfs_registration(void)
773 if ((rc
= subsystem_register(&ecryptfs_subsys
))) {
775 "Unable to register ecryptfs sysfs subsystem\n");
778 rc
= sysfs_create_file(&ecryptfs_subsys
.kset
.kobj
,
779 &sysfs_attr_version
.attr
);
782 "Unable to create ecryptfs version attribute\n");
783 subsystem_unregister(&ecryptfs_subsys
);
786 rc
= sysfs_create_file(&ecryptfs_subsys
.kset
.kobj
,
787 &sysfs_attr_version_str
.attr
);
790 "Unable to create ecryptfs version_str attribute\n");
791 sysfs_remove_file(&ecryptfs_subsys
.kset
.kobj
,
792 &sysfs_attr_version
.attr
);
793 subsystem_unregister(&ecryptfs_subsys
);
800 static int __init
ecryptfs_init(void)
804 if (ECRYPTFS_DEFAULT_EXTENT_SIZE
> PAGE_CACHE_SIZE
) {
806 ecryptfs_printk(KERN_ERR
, "The eCryptfs extent size is "
807 "larger than the host's page size, and so "
808 "eCryptfs cannot run on this system. The "
809 "default eCryptfs extent size is [%d] bytes; "
810 "the page size is [%d] bytes.\n",
811 ECRYPTFS_DEFAULT_EXTENT_SIZE
, PAGE_CACHE_SIZE
);
814 rc
= ecryptfs_init_kmem_caches();
817 "Failed to allocate one or more kmem_cache objects\n");
820 rc
= register_filesystem(&ecryptfs_fs_type
);
822 printk(KERN_ERR
"Failed to register filesystem\n");
823 ecryptfs_free_kmem_caches();
826 kset_set_kset_s(&ecryptfs_subsys
, fs_subsys
);
827 sysfs_attr_version
.attr
.owner
= THIS_MODULE
;
828 sysfs_attr_version_str
.attr
.owner
= THIS_MODULE
;
829 rc
= do_sysfs_registration();
831 printk(KERN_ERR
"sysfs registration failed\n");
832 unregister_filesystem(&ecryptfs_fs_type
);
833 ecryptfs_free_kmem_caches();
836 rc
= ecryptfs_init_messaging(ecryptfs_transport
);
838 ecryptfs_printk(KERN_ERR
, "Failure occured while attempting to "
839 "initialize the eCryptfs netlink socket\n");
845 static void __exit
ecryptfs_exit(void)
847 sysfs_remove_file(&ecryptfs_subsys
.kset
.kobj
,
848 &sysfs_attr_version
.attr
);
849 sysfs_remove_file(&ecryptfs_subsys
.kset
.kobj
,
850 &sysfs_attr_version_str
.attr
);
851 subsystem_unregister(&ecryptfs_subsys
);
852 ecryptfs_release_messaging(ecryptfs_transport
);
853 unregister_filesystem(&ecryptfs_fs_type
);
854 ecryptfs_free_kmem_caches();
857 MODULE_AUTHOR("Michael A. Halcrow <mhalcrow@us.ibm.com>");
858 MODULE_DESCRIPTION("eCryptfs");
860 MODULE_LICENSE("GPL");
862 module_init(ecryptfs_init
)
863 module_exit(ecryptfs_exit
)