blob: 520d05f5ad01ed13e679df57bc86ce51c7244e40 [file] [log] [blame]
Michael Halcrow237fead2006-10-04 02:16:22 -07001/**
2 * eCryptfs: Linux filesystem encryption layer
3 *
4 * Copyright (C) 1997-2003 Erez Zadok
5 * Copyright (C) 2001-2003 Stony Brook University
Michael Halcrowdd2a3b72007-02-12 00:53:46 -08006 * Copyright (C) 2004-2007 International Business Machines Corp.
Michael Halcrow237fead2006-10-04 02:16:22 -07007 * Author(s): Michael A. Halcrow <mahalcro@us.ibm.com>
8 * Michael C. Thompson <mcthomps@us.ibm.com>
Michael Halcrowdddfa462007-02-12 00:53:44 -08009 * Tyler Hicks <tyhicks@ou.edu>
Michael Halcrow237fead2006-10-04 02:16:22 -070010 *
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.
15 *
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.
20 *
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
24 * 02111-1307, USA.
25 */
26
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>
Michael Halcrow237fead2006-10-04 02:16:22 -070033#include <linux/mount.h>
Michael Halcrow237fead2006-10-04 02:16:22 -070034#include <linux/pagemap.h>
35#include <linux/key.h>
36#include <linux/parser.h>
Josef "Jeff" Sipek0cc72dc2006-12-08 02:36:31 -080037#include <linux/fs_stack.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090038#include <linux/slab.h>
Roberto Sassu070baa52010-11-03 11:11:22 +010039#include <linux/magic.h>
Michael Halcrow237fead2006-10-04 02:16:22 -070040#include "ecryptfs_kernel.h"
41
42/**
43 * Module parameter that defines the ecryptfs_verbosity level.
44 */
45int ecryptfs_verbosity = 0;
46
47module_param(ecryptfs_verbosity, int, 0);
48MODULE_PARM_DESC(ecryptfs_verbosity,
49 "Initial verbosity level (0 or 1; defaults to "
50 "0, which is Quiet)");
51
Michael Halcrowdddfa462007-02-12 00:53:44 -080052/**
Tyler Hicks624ae522008-10-15 22:02:51 -070053 * Module parameter that defines the number of message buffer elements
Michael Halcrowdddfa462007-02-12 00:53:44 -080054 */
55unsigned int ecryptfs_message_buf_len = ECRYPTFS_DEFAULT_MSG_CTX_ELEMS;
56
57module_param(ecryptfs_message_buf_len, uint, 0);
58MODULE_PARM_DESC(ecryptfs_message_buf_len,
59 "Number of message buffer elements");
60
61/**
62 * Module parameter that defines the maximum guaranteed amount of time to wait
Tyler Hicks624ae522008-10-15 22:02:51 -070063 * for a response from ecryptfsd. The actual sleep time will be, more than
Michael Halcrowdddfa462007-02-12 00:53:44 -080064 * likely, a small amount greater than this specified value, but only less if
Tyler Hicks624ae522008-10-15 22:02:51 -070065 * the message successfully arrives.
Michael Halcrowdddfa462007-02-12 00:53:44 -080066 */
67signed long ecryptfs_message_wait_timeout = ECRYPTFS_MAX_MSG_CTX_TTL / HZ;
68
69module_param(ecryptfs_message_wait_timeout, long, 0);
70MODULE_PARM_DESC(ecryptfs_message_wait_timeout,
71 "Maximum number of seconds that an operation will "
72 "sleep while waiting for a message response from "
73 "userspace");
74
75/**
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.
79 */
80unsigned int ecryptfs_number_of_users = ECRYPTFS_DEFAULT_NUM_USERS;
81
82module_param(ecryptfs_number_of_users, uint, 0);
83MODULE_PARM_DESC(ecryptfs_number_of_users, "An estimate of the number of "
84 "concurrent users of eCryptfs");
85
Michael Halcrow237fead2006-10-04 02:16:22 -070086void __ecryptfs_printk(const char *fmt, ...)
87{
88 va_list args;
89 va_start(args, fmt);
90 if (fmt[1] == '7') { /* KERN_DEBUG */
91 if (ecryptfs_verbosity >= 1)
92 vprintk(fmt, args);
93 } else
94 vprintk(fmt, args);
95 va_end(args);
96}
97
98/**
Michael Halcrow4981e082007-10-16 01:28:09 -070099 * ecryptfs_init_persistent_file
100 * @ecryptfs_dentry: Fully initialized eCryptfs dentry object, with
101 * the lower dentry and the lower mount set
102 *
103 * eCryptfs only ever keeps a single open file for every lower
104 * inode. All I/O operations to the lower inode occur through that
105 * file. When the first eCryptfs dentry that interposes with the first
106 * lower dentry for that inode is created, this function creates the
107 * persistent file struct and associates it with the eCryptfs
108 * inode. When the eCryptfs inode is destroyed, the file is closed.
109 *
110 * The persistent file will be opened with read/write permissions, if
111 * possible. Otherwise, it is opened read-only.
112 *
113 * This function does nothing if a lower persistent file is already
114 * associated with the eCryptfs inode.
115 *
116 * Returns zero on success; non-zero otherwise
117 */
Michael Halcrow72b55ff2008-07-23 21:30:07 -0700118int ecryptfs_init_persistent_file(struct dentry *ecryptfs_dentry)
Michael Halcrow4981e082007-10-16 01:28:09 -0700119{
David Howells745ca242008-11-14 10:39:22 +1100120 const struct cred *cred = current_cred();
Michael Halcrow4981e082007-10-16 01:28:09 -0700121 struct ecryptfs_inode_info *inode_info =
122 ecryptfs_inode_to_private(ecryptfs_dentry->d_inode);
123 int rc = 0;
124
Michael Halcrow4981e082007-10-16 01:28:09 -0700125 if (!inode_info->lower_file) {
126 struct dentry *lower_dentry;
127 struct vfsmount *lower_mnt =
128 ecryptfs_dentry_to_lower_mnt(ecryptfs_dentry);
129
130 lower_dentry = ecryptfs_dentry_to_lower(ecryptfs_dentry);
Michael Halcrow746f1e52008-07-23 21:30:02 -0700131 rc = ecryptfs_privileged_open(&inode_info->lower_file,
David Howells745ca242008-11-14 10:39:22 +1100132 lower_dentry, lower_mnt, cred);
Tyler Hicksac22ba22009-08-12 01:06:54 -0500133 if (rc) {
Michael Halcrow4981e082007-10-16 01:28:09 -0700134 printk(KERN_ERR "Error opening lower persistent file "
Michael Halcrow746f1e52008-07-23 21:30:02 -0700135 "for lower_dentry [0x%p] and lower_mnt [0x%p]; "
136 "rc = [%d]\n", lower_dentry, lower_mnt, rc);
Michael Halcrow4981e082007-10-16 01:28:09 -0700137 inode_info->lower_file = NULL;
Al Virob65a9cf2009-12-16 06:27:40 -0500138 }
Michael Halcrow4981e082007-10-16 01:28:09 -0700139 }
Michael Halcrow4981e082007-10-16 01:28:09 -0700140 return rc;
141}
142
Linus Torvalds6254b322011-01-13 17:19:38 -0800143static struct inode *ecryptfs_get_inode(struct inode *lower_inode,
Al Viro66cb7662011-01-12 20:04:37 -0500144 struct super_block *sb)
Michael Halcrow237fead2006-10-04 02:16:22 -0700145{
Michael Halcrow237fead2006-10-04 02:16:22 -0700146 struct inode *inode;
147 int rc = 0;
148
Michael Halcrow237fead2006-10-04 02:16:22 -0700149 if (lower_inode->i_sb != ecryptfs_superblock_to_lower(sb)) {
150 rc = -EXDEV;
151 goto out;
152 }
153 if (!igrab(lower_inode)) {
154 rc = -ESTALE;
155 goto out;
156 }
157 inode = iget5_locked(sb, (unsigned long)lower_inode,
158 ecryptfs_inode_test, ecryptfs_inode_set,
159 lower_inode);
160 if (!inode) {
161 rc = -EACCES;
162 iput(lower_inode);
163 goto out;
164 }
165 if (inode->i_state & I_NEW)
166 unlock_new_inode(inode);
167 else
168 iput(lower_inode);
169 if (S_ISLNK(lower_inode->i_mode))
170 inode->i_op = &ecryptfs_symlink_iops;
171 else if (S_ISDIR(lower_inode->i_mode))
172 inode->i_op = &ecryptfs_dir_iops;
173 if (S_ISDIR(lower_inode->i_mode))
174 inode->i_fop = &ecryptfs_dir_fops;
Pekka Enberg26da8202006-10-19 23:28:14 -0700175 if (special_file(lower_inode->i_mode))
Michael Halcrow237fead2006-10-04 02:16:22 -0700176 init_special_inode(inode, lower_inode->i_mode,
177 lower_inode->i_rdev);
Erez Zadok9afa2fb2009-12-02 19:51:54 -0500178 fsstack_copy_attr_all(inode, lower_inode);
Michael Halcrow237fead2006-10-04 02:16:22 -0700179 /* This size will be overwritten for real files w/ headers and
180 * other metadata */
Josef "Jeff" Sipek0cc72dc2006-12-08 02:36:31 -0800181 fsstack_copy_inode_size(inode, lower_inode);
Al Viro66cb7662011-01-12 20:04:37 -0500182 return inode;
183out:
184 return ERR_PTR(rc);
185}
186
187/**
188 * ecryptfs_interpose
189 * @lower_dentry: Existing dentry in the lower filesystem
190 * @dentry: ecryptfs' dentry
191 * @sb: ecryptfs's super_block
192 * @flags: flags to govern behavior of interpose procedure
193 *
194 * Interposes upper and lower dentries.
195 *
196 * Returns zero on success; non-zero otherwise
197 */
198int ecryptfs_interpose(struct dentry *lower_dentry, struct dentry *dentry,
199 struct super_block *sb, u32 flags)
200{
201 struct inode *lower_inode = lower_dentry->d_inode;
202 struct inode *inode = ecryptfs_get_inode(lower_inode, sb);
Linus Torvalds6254b322011-01-13 17:19:38 -0800203 if (IS_ERR(inode))
Al Viro66cb7662011-01-12 20:04:37 -0500204 return PTR_ERR(inode);
Tyler Hicksae6e8452009-03-12 00:19:46 -0500205 if (flags & ECRYPTFS_INTERPOSE_FLAG_D_ADD)
206 d_add(dentry, inode);
207 else
208 d_instantiate(dentry, inode);
Al Viro66cb7662011-01-12 20:04:37 -0500209 return 0;
Michael Halcrow237fead2006-10-04 02:16:22 -0700210}
211
Eric Sandeen2830bfd2008-02-06 01:38:34 -0800212enum { ecryptfs_opt_sig, ecryptfs_opt_ecryptfs_sig,
213 ecryptfs_opt_cipher, ecryptfs_opt_ecryptfs_cipher,
214 ecryptfs_opt_ecryptfs_key_bytes,
Michael Halcrow17398952007-02-12 00:53:45 -0800215 ecryptfs_opt_passthrough, ecryptfs_opt_xattr_metadata,
Michael Halcrow87c94c42009-01-06 14:42:01 -0800216 ecryptfs_opt_encrypted_view, ecryptfs_opt_fnek_sig,
217 ecryptfs_opt_fn_cipher, ecryptfs_opt_fn_cipher_key_bytes,
Roberto Sassuf16feb52010-10-06 18:31:32 +0200218 ecryptfs_opt_unlink_sigs, ecryptfs_opt_mount_auth_tok_only,
219 ecryptfs_opt_err };
Michael Halcrow237fead2006-10-04 02:16:22 -0700220
Steven Whitehousea447c092008-10-13 10:46:57 +0100221static const match_table_t tokens = {
Michael Halcrow237fead2006-10-04 02:16:22 -0700222 {ecryptfs_opt_sig, "sig=%s"},
223 {ecryptfs_opt_ecryptfs_sig, "ecryptfs_sig=%s"},
Michael Halcrow237fead2006-10-04 02:16:22 -0700224 {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"},
Michael Halcrow17398952007-02-12 00:53:45 -0800228 {ecryptfs_opt_xattr_metadata, "ecryptfs_xattr_metadata"},
229 {ecryptfs_opt_encrypted_view, "ecryptfs_encrypted_view"},
Michael Halcrow87c94c42009-01-06 14:42:01 -0800230 {ecryptfs_opt_fnek_sig, "ecryptfs_fnek_sig=%s"},
231 {ecryptfs_opt_fn_cipher, "ecryptfs_fn_cipher=%s"},
232 {ecryptfs_opt_fn_cipher_key_bytes, "ecryptfs_fn_key_bytes=%u"},
Tyler Hickse77cc8d2009-04-22 04:08:46 -0500233 {ecryptfs_opt_unlink_sigs, "ecryptfs_unlink_sigs"},
Roberto Sassuf16feb52010-10-06 18:31:32 +0200234 {ecryptfs_opt_mount_auth_tok_only, "ecryptfs_mount_auth_tok_only"},
Michael Halcrow237fead2006-10-04 02:16:22 -0700235 {ecryptfs_opt_err, NULL}
236};
237
Michael Halcrowf4aad162007-10-16 01:27:53 -0700238static int ecryptfs_init_global_auth_toks(
239 struct ecryptfs_mount_crypt_stat *mount_crypt_stat)
Michael Halcrow237fead2006-10-04 02:16:22 -0700240{
Michael Halcrowf4aad162007-10-16 01:27:53 -0700241 struct ecryptfs_global_auth_tok *global_auth_tok;
Roberto Sassu0e1fc5e2011-03-21 16:00:53 +0100242 struct ecryptfs_auth_tok *auth_tok;
Michael Halcrow237fead2006-10-04 02:16:22 -0700243 int rc = 0;
Michael Halcrow237fead2006-10-04 02:16:22 -0700244
Michael Halcrowf4aad162007-10-16 01:27:53 -0700245 list_for_each_entry(global_auth_tok,
246 &mount_crypt_stat->global_auth_tok_list,
247 mount_crypt_stat_list) {
Michael Halcrow5dda6992007-10-16 01:28:06 -0700248 rc = ecryptfs_keyring_auth_tok_for_sig(
Roberto Sassu0e1fc5e2011-03-21 16:00:53 +0100249 &global_auth_tok->global_auth_tok_key, &auth_tok,
Michael Halcrow5dda6992007-10-16 01:28:06 -0700250 global_auth_tok->sig);
251 if (rc) {
Michael Halcrowf4aad162007-10-16 01:27:53 -0700252 printk(KERN_ERR "Could not find valid key in user "
253 "session keyring for sig specified in mount "
254 "option: [%s]\n", global_auth_tok->sig);
255 global_auth_tok->flags |= ECRYPTFS_AUTH_TOK_INVALID;
Eric Sandeen982363c2008-07-23 21:30:04 -0700256 goto out;
Michael Halcrowf4aad162007-10-16 01:27:53 -0700257 } else
258 global_auth_tok->flags &= ~ECRYPTFS_AUTH_TOK_INVALID;
Michael Halcrow237fead2006-10-04 02:16:22 -0700259 }
Eric Sandeen982363c2008-07-23 21:30:04 -0700260out:
Michael Halcrow237fead2006-10-04 02:16:22 -0700261 return rc;
262}
263
Michael Halcrowf4aad162007-10-16 01:27:53 -0700264static void ecryptfs_init_mount_crypt_stat(
265 struct ecryptfs_mount_crypt_stat *mount_crypt_stat)
266{
267 memset((void *)mount_crypt_stat, 0,
268 sizeof(struct ecryptfs_mount_crypt_stat));
269 INIT_LIST_HEAD(&mount_crypt_stat->global_auth_tok_list);
270 mutex_init(&mount_crypt_stat->global_auth_tok_list_mutex);
271 mount_crypt_stat->flags |= ECRYPTFS_MOUNT_CRYPT_STAT_INITIALIZED;
272}
273
Michael Halcrow237fead2006-10-04 02:16:22 -0700274/**
275 * ecryptfs_parse_options
276 * @sb: The ecryptfs super block
277 * @options: The options pased to the kernel
278 *
279 * Parse mount options:
280 * debug=N - ecryptfs_verbosity level for debug output
281 * sig=XXX - description(signature) of the key to use
282 *
283 * Returns the dentry object of the lower-level (lower/interposed)
284 * directory; We want to mount our stackable file system on top of
285 * that lower directory.
286 *
287 * The signature of the key to use must be the description of a key
288 * already in the keyring. Mounting will fail if the key can not be
289 * found.
290 *
291 * Returns zero on success; non-zero on error
292 */
Al Viro2ccde7c2010-03-21 12:24:29 -0400293static int ecryptfs_parse_options(struct ecryptfs_sb_info *sbi, char *options)
Michael Halcrow237fead2006-10-04 02:16:22 -0700294{
295 char *p;
296 int rc = 0;
297 int sig_set = 0;
298 int cipher_name_set = 0;
Michael Halcrow87c94c42009-01-06 14:42:01 -0800299 int fn_cipher_name_set = 0;
Michael Halcrow237fead2006-10-04 02:16:22 -0700300 int cipher_key_bytes;
301 int cipher_key_bytes_set = 0;
Michael Halcrow87c94c42009-01-06 14:42:01 -0800302 int fn_cipher_key_bytes;
303 int fn_cipher_key_bytes_set = 0;
Michael Halcrow237fead2006-10-04 02:16:22 -0700304 struct ecryptfs_mount_crypt_stat *mount_crypt_stat =
Al Viro2ccde7c2010-03-21 12:24:29 -0400305 &sbi->mount_crypt_stat;
Michael Halcrow237fead2006-10-04 02:16:22 -0700306 substring_t args[MAX_OPT_ARGS];
307 int token;
308 char *sig_src;
Michael Halcrow237fead2006-10-04 02:16:22 -0700309 char *cipher_name_dst;
310 char *cipher_name_src;
Michael Halcrow87c94c42009-01-06 14:42:01 -0800311 char *fn_cipher_name_dst;
312 char *fn_cipher_name_src;
313 char *fnek_dst;
314 char *fnek_src;
Michael Halcrow237fead2006-10-04 02:16:22 -0700315 char *cipher_key_bytes_src;
Michael Halcrow87c94c42009-01-06 14:42:01 -0800316 char *fn_cipher_key_bytes_src;
Michael Halcrow237fead2006-10-04 02:16:22 -0700317
318 if (!options) {
319 rc = -EINVAL;
320 goto out;
321 }
Michael Halcrow956159c2007-10-16 01:27:55 -0700322 ecryptfs_init_mount_crypt_stat(mount_crypt_stat);
Michael Halcrow237fead2006-10-04 02:16:22 -0700323 while ((p = strsep(&options, ",")) != NULL) {
324 if (!*p)
325 continue;
326 token = match_token(p, tokens, args);
327 switch (token) {
328 case ecryptfs_opt_sig:
329 case ecryptfs_opt_ecryptfs_sig:
330 sig_src = args[0].from;
Michael Halcrowf4aad162007-10-16 01:27:53 -0700331 rc = ecryptfs_add_global_auth_tok(mount_crypt_stat,
Tyler Hicks84814d62009-03-13 13:51:59 -0700332 sig_src, 0);
Michael Halcrowf4aad162007-10-16 01:27:53 -0700333 if (rc) {
334 printk(KERN_ERR "Error attempting to register "
335 "global sig; rc = [%d]\n", rc);
336 goto out;
337 }
Michael Halcrow237fead2006-10-04 02:16:22 -0700338 sig_set = 1;
339 break;
Michael Halcrow237fead2006-10-04 02:16:22 -0700340 case ecryptfs_opt_cipher:
341 case ecryptfs_opt_ecryptfs_cipher:
342 cipher_name_src = args[0].from;
343 cipher_name_dst =
344 mount_crypt_stat->
345 global_default_cipher_name;
346 strncpy(cipher_name_dst, cipher_name_src,
347 ECRYPTFS_MAX_CIPHER_NAME_SIZE);
Michael Halcrow87c94c42009-01-06 14:42:01 -0800348 cipher_name_dst[ECRYPTFS_MAX_CIPHER_NAME_SIZE] = '\0';
Michael Halcrow237fead2006-10-04 02:16:22 -0700349 cipher_name_set = 1;
350 break;
351 case ecryptfs_opt_ecryptfs_key_bytes:
352 cipher_key_bytes_src = args[0].from;
353 cipher_key_bytes =
354 (int)simple_strtol(cipher_key_bytes_src,
355 &cipher_key_bytes_src, 0);
356 mount_crypt_stat->global_default_cipher_key_size =
357 cipher_key_bytes;
Michael Halcrow237fead2006-10-04 02:16:22 -0700358 cipher_key_bytes_set = 1;
359 break;
360 case ecryptfs_opt_passthrough:
361 mount_crypt_stat->flags |=
362 ECRYPTFS_PLAINTEXT_PASSTHROUGH_ENABLED;
363 break;
Michael Halcrow17398952007-02-12 00:53:45 -0800364 case ecryptfs_opt_xattr_metadata:
365 mount_crypt_stat->flags |=
366 ECRYPTFS_XATTR_METADATA_ENABLED;
367 break;
368 case ecryptfs_opt_encrypted_view:
369 mount_crypt_stat->flags |=
370 ECRYPTFS_XATTR_METADATA_ENABLED;
371 mount_crypt_stat->flags |=
372 ECRYPTFS_ENCRYPTED_VIEW_ENABLED;
373 break;
Michael Halcrow87c94c42009-01-06 14:42:01 -0800374 case ecryptfs_opt_fnek_sig:
375 fnek_src = args[0].from;
376 fnek_dst =
377 mount_crypt_stat->global_default_fnek_sig;
378 strncpy(fnek_dst, fnek_src, ECRYPTFS_SIG_SIZE_HEX);
379 mount_crypt_stat->global_default_fnek_sig[
380 ECRYPTFS_SIG_SIZE_HEX] = '\0';
381 rc = ecryptfs_add_global_auth_tok(
382 mount_crypt_stat,
Tyler Hicks84814d62009-03-13 13:51:59 -0700383 mount_crypt_stat->global_default_fnek_sig,
384 ECRYPTFS_AUTH_TOK_FNEK);
Michael Halcrow87c94c42009-01-06 14:42:01 -0800385 if (rc) {
386 printk(KERN_ERR "Error attempting to register "
387 "global fnek sig [%s]; rc = [%d]\n",
388 mount_crypt_stat->global_default_fnek_sig,
389 rc);
390 goto out;
391 }
392 mount_crypt_stat->flags |=
393 (ECRYPTFS_GLOBAL_ENCRYPT_FILENAMES
394 | ECRYPTFS_GLOBAL_ENCFN_USE_MOUNT_FNEK);
395 break;
396 case ecryptfs_opt_fn_cipher:
397 fn_cipher_name_src = args[0].from;
398 fn_cipher_name_dst =
399 mount_crypt_stat->global_default_fn_cipher_name;
400 strncpy(fn_cipher_name_dst, fn_cipher_name_src,
401 ECRYPTFS_MAX_CIPHER_NAME_SIZE);
402 mount_crypt_stat->global_default_fn_cipher_name[
403 ECRYPTFS_MAX_CIPHER_NAME_SIZE] = '\0';
404 fn_cipher_name_set = 1;
405 break;
406 case ecryptfs_opt_fn_cipher_key_bytes:
407 fn_cipher_key_bytes_src = args[0].from;
408 fn_cipher_key_bytes =
409 (int)simple_strtol(fn_cipher_key_bytes_src,
410 &fn_cipher_key_bytes_src, 0);
411 mount_crypt_stat->global_default_fn_cipher_key_bytes =
412 fn_cipher_key_bytes;
413 fn_cipher_key_bytes_set = 1;
414 break;
Tyler Hickse77cc8d2009-04-22 04:08:46 -0500415 case ecryptfs_opt_unlink_sigs:
416 mount_crypt_stat->flags |= ECRYPTFS_UNLINK_SIGS;
417 break;
Roberto Sassuf16feb52010-10-06 18:31:32 +0200418 case ecryptfs_opt_mount_auth_tok_only:
419 mount_crypt_stat->flags |=
420 ECRYPTFS_GLOBAL_MOUNT_AUTH_TOK_ONLY;
421 break;
Michael Halcrow237fead2006-10-04 02:16:22 -0700422 case ecryptfs_opt_err:
423 default:
Michael Halcrow87c94c42009-01-06 14:42:01 -0800424 printk(KERN_WARNING
425 "%s: eCryptfs: unrecognized option [%s]\n",
426 __func__, p);
Michael Halcrow237fead2006-10-04 02:16:22 -0700427 }
428 }
Michael Halcrow237fead2006-10-04 02:16:22 -0700429 if (!sig_set) {
430 rc = -EINVAL;
Michael Halcrow956159c2007-10-16 01:27:55 -0700431 ecryptfs_printk(KERN_ERR, "You must supply at least one valid "
432 "auth tok signature as a mount "
Michael Halcrow237fead2006-10-04 02:16:22 -0700433 "parameter; see the eCryptfs README\n");
434 goto out;
435 }
436 if (!cipher_name_set) {
Miklos Szeredi8f236802008-07-23 21:30:05 -0700437 int cipher_name_len = strlen(ECRYPTFS_DEFAULT_CIPHER);
438
439 BUG_ON(cipher_name_len >= ECRYPTFS_MAX_CIPHER_NAME_SIZE);
Miklos Szeredi8f236802008-07-23 21:30:05 -0700440 strcpy(mount_crypt_stat->global_default_cipher_name,
441 ECRYPTFS_DEFAULT_CIPHER);
Michael Halcrow237fead2006-10-04 02:16:22 -0700442 }
Michael Halcrow87c94c42009-01-06 14:42:01 -0800443 if ((mount_crypt_stat->flags & ECRYPTFS_GLOBAL_ENCRYPT_FILENAMES)
444 && !fn_cipher_name_set)
445 strcpy(mount_crypt_stat->global_default_fn_cipher_name,
446 mount_crypt_stat->global_default_cipher_name);
447 if (!cipher_key_bytes_set)
Michael Halcrowe5d9cbd2006-10-30 22:07:16 -0800448 mount_crypt_stat->global_default_cipher_key_size = 0;
Michael Halcrow87c94c42009-01-06 14:42:01 -0800449 if ((mount_crypt_stat->flags & ECRYPTFS_GLOBAL_ENCRYPT_FILENAMES)
450 && !fn_cipher_key_bytes_set)
451 mount_crypt_stat->global_default_fn_cipher_key_bytes =
452 mount_crypt_stat->global_default_cipher_key_size;
Eric Sandeenaf440f52008-02-06 01:38:37 -0800453 mutex_lock(&key_tfm_list_mutex);
454 if (!ecryptfs_tfm_exists(mount_crypt_stat->global_default_cipher_name,
Michael Halcrow87c94c42009-01-06 14:42:01 -0800455 NULL)) {
Eric Sandeenaf440f52008-02-06 01:38:37 -0800456 rc = ecryptfs_add_new_key_tfm(
457 NULL, mount_crypt_stat->global_default_cipher_name,
458 mount_crypt_stat->global_default_cipher_key_size);
Michael Halcrow87c94c42009-01-06 14:42:01 -0800459 if (rc) {
460 printk(KERN_ERR "Error attempting to initialize "
461 "cipher with name = [%s] and key size = [%td]; "
462 "rc = [%d]\n",
463 mount_crypt_stat->global_default_cipher_name,
464 mount_crypt_stat->global_default_cipher_key_size,
465 rc);
466 rc = -EINVAL;
467 mutex_unlock(&key_tfm_list_mutex);
468 goto out;
469 }
Michael Halcrow237fead2006-10-04 02:16:22 -0700470 }
Michael Halcrow87c94c42009-01-06 14:42:01 -0800471 if ((mount_crypt_stat->flags & ECRYPTFS_GLOBAL_ENCRYPT_FILENAMES)
472 && !ecryptfs_tfm_exists(
473 mount_crypt_stat->global_default_fn_cipher_name, NULL)) {
474 rc = ecryptfs_add_new_key_tfm(
475 NULL, mount_crypt_stat->global_default_fn_cipher_name,
476 mount_crypt_stat->global_default_fn_cipher_key_bytes);
477 if (rc) {
478 printk(KERN_ERR "Error attempting to initialize "
479 "cipher with name = [%s] and key size = [%td]; "
480 "rc = [%d]\n",
481 mount_crypt_stat->global_default_fn_cipher_name,
482 mount_crypt_stat->global_default_fn_cipher_key_bytes,
483 rc);
484 rc = -EINVAL;
485 mutex_unlock(&key_tfm_list_mutex);
486 goto out;
487 }
488 }
489 mutex_unlock(&key_tfm_list_mutex);
Michael Halcrow5dda6992007-10-16 01:28:06 -0700490 rc = ecryptfs_init_global_auth_toks(mount_crypt_stat);
Michael Halcrow87c94c42009-01-06 14:42:01 -0800491 if (rc)
Michael Halcrowf4aad162007-10-16 01:27:53 -0700492 printk(KERN_WARNING "One or more global auth toks could not "
493 "properly register; rc = [%d]\n", rc);
Michael Halcrow237fead2006-10-04 02:16:22 -0700494out:
495 return rc;
496}
497
498struct kmem_cache *ecryptfs_sb_info_cache;
Al Viro44031582010-05-17 00:59:46 -0400499static struct file_system_type ecryptfs_fs_type;
Michael Halcrow237fead2006-10-04 02:16:22 -0700500
501/**
Michael Halcrow237fead2006-10-04 02:16:22 -0700502 * ecryptfs_get_sb
503 * @fs_type
504 * @flags
505 * @dev_name: The path to mount over
506 * @raw_data: The options passed into the kernel
Michael Halcrow237fead2006-10-04 02:16:22 -0700507 */
Al Viro4d143be2010-07-26 13:33:36 +0400508static struct dentry *ecryptfs_mount(struct file_system_type *fs_type, int flags,
509 const char *dev_name, void *raw_data)
Michael Halcrow237fead2006-10-04 02:16:22 -0700510{
Al Viro2ccde7c2010-03-21 12:24:29 -0400511 struct super_block *s;
512 struct ecryptfs_sb_info *sbi;
513 struct ecryptfs_dentry_info *root_info;
514 const char *err = "Getting sb failed";
Al Viro66cb7662011-01-12 20:04:37 -0500515 struct inode *inode;
516 struct path path;
Michael Halcrow237fead2006-10-04 02:16:22 -0700517 int rc;
Michael Halcrow237fead2006-10-04 02:16:22 -0700518
Al Viro2ccde7c2010-03-21 12:24:29 -0400519 sbi = kmem_cache_zalloc(ecryptfs_sb_info_cache, GFP_KERNEL);
520 if (!sbi) {
521 rc = -ENOMEM;
Michael Halcrow237fead2006-10-04 02:16:22 -0700522 goto out;
523 }
Al Viro2ccde7c2010-03-21 12:24:29 -0400524
525 rc = ecryptfs_parse_options(sbi, raw_data);
Michael Halcrow237fead2006-10-04 02:16:22 -0700526 if (rc) {
Al Viro2ccde7c2010-03-21 12:24:29 -0400527 err = "Error parsing options";
528 goto out;
Michael Halcrow237fead2006-10-04 02:16:22 -0700529 }
Al Viro2ccde7c2010-03-21 12:24:29 -0400530
531 s = sget(fs_type, NULL, set_anon_super, NULL);
532 if (IS_ERR(s)) {
533 rc = PTR_ERR(s);
534 goto out;
535 }
536
537 s->s_flags = flags;
538 rc = bdi_setup_and_register(&sbi->bdi, "ecryptfs", BDI_CAP_MAP_COPY);
Al Viro66cb7662011-01-12 20:04:37 -0500539 if (rc)
540 goto out1;
Al Viro2ccde7c2010-03-21 12:24:29 -0400541
542 ecryptfs_set_superblock_private(s, sbi);
543 s->s_bdi = &sbi->bdi;
544
545 /* ->kill_sb() will take care of sbi after that point */
546 sbi = NULL;
547 s->s_op = &ecryptfs_sops;
Al Viro66cb7662011-01-12 20:04:37 -0500548 s->s_d_op = &ecryptfs_dops;
549
550 err = "Reading sb failed";
551 rc = kern_path(dev_name, LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &path);
552 if (rc) {
553 ecryptfs_printk(KERN_WARNING, "kern_path() failed\n");
554 goto out1;
555 }
556 if (path.dentry->d_sb->s_type == &ecryptfs_fs_type) {
557 rc = -EINVAL;
558 printk(KERN_ERR "Mount on filesystem of type "
559 "eCryptfs explicitly disallowed due to "
560 "known incompatibilities\n");
561 goto out_free;
562 }
563 ecryptfs_set_superblock_lower(s, path.dentry->d_sb);
564 s->s_maxbytes = path.dentry->d_sb->s_maxbytes;
565 s->s_blocksize = path.dentry->d_sb->s_blocksize;
Roberto Sassu070baa52010-11-03 11:11:22 +0100566 s->s_magic = ECRYPTFS_SUPER_MAGIC;
Al Viro66cb7662011-01-12 20:04:37 -0500567
568 inode = ecryptfs_get_inode(path.dentry->d_inode, s);
569 rc = PTR_ERR(inode);
570 if (IS_ERR(inode))
571 goto out_free;
572
573 s->s_root = d_alloc_root(inode);
574 if (!s->s_root) {
575 iput(inode);
576 rc = -ENOMEM;
577 goto out_free;
578 }
Al Viro2ccde7c2010-03-21 12:24:29 -0400579
580 rc = -ENOMEM;
Al Viro2ccde7c2010-03-21 12:24:29 -0400581 root_info = kmem_cache_zalloc(ecryptfs_dentry_info_cache, GFP_KERNEL);
Al Viro66cb7662011-01-12 20:04:37 -0500582 if (!root_info)
583 goto out_free;
584
Al Viro2ccde7c2010-03-21 12:24:29 -0400585 /* ->kill_sb() will take care of root_info */
586 ecryptfs_set_dentry_private(s->s_root, root_info);
Al Viro66cb7662011-01-12 20:04:37 -0500587 ecryptfs_set_dentry_lower(s->s_root, path.dentry);
588 ecryptfs_set_dentry_lower_mnt(s->s_root, path.mnt);
589
Al Viro2ccde7c2010-03-21 12:24:29 -0400590 s->s_flags |= MS_ACTIVE;
Al Viro4d143be2010-07-26 13:33:36 +0400591 return dget(s->s_root);
Al Viro2ccde7c2010-03-21 12:24:29 -0400592
Al Viro66cb7662011-01-12 20:04:37 -0500593out_free:
594 path_put(&path);
595out1:
596 deactivate_locked_super(s);
Michael Halcrow237fead2006-10-04 02:16:22 -0700597out:
Al Viro2ccde7c2010-03-21 12:24:29 -0400598 if (sbi) {
599 ecryptfs_destroy_mount_crypt_stat(&sbi->mount_crypt_stat);
600 kmem_cache_free(ecryptfs_sb_info_cache, sbi);
601 }
602 printk(KERN_ERR "%s; rc = [%d]\n", err, rc);
Al Viro4d143be2010-07-26 13:33:36 +0400603 return ERR_PTR(rc);
Michael Halcrow237fead2006-10-04 02:16:22 -0700604}
605
606/**
607 * ecryptfs_kill_block_super
608 * @sb: The ecryptfs super block
609 *
610 * Used to bring the superblock down and free the private data.
Michael Halcrow237fead2006-10-04 02:16:22 -0700611 */
612static void ecryptfs_kill_block_super(struct super_block *sb)
613{
Al Virodecabd62010-03-20 22:32:26 -0400614 struct ecryptfs_sb_info *sb_info = ecryptfs_superblock_to_private(sb);
615 kill_anon_super(sb);
616 if (!sb_info)
617 return;
618 ecryptfs_destroy_mount_crypt_stat(&sb_info->mount_crypt_stat);
619 bdi_destroy(&sb_info->bdi);
620 kmem_cache_free(ecryptfs_sb_info_cache, sb_info);
Michael Halcrow237fead2006-10-04 02:16:22 -0700621}
622
623static struct file_system_type ecryptfs_fs_type = {
624 .owner = THIS_MODULE,
625 .name = "ecryptfs",
Al Viro4d143be2010-07-26 13:33:36 +0400626 .mount = ecryptfs_mount,
Michael Halcrow237fead2006-10-04 02:16:22 -0700627 .kill_sb = ecryptfs_kill_block_super,
628 .fs_flags = 0
629};
630
631/**
632 * inode_info_init_once
633 *
634 * Initializes the ecryptfs_inode_info_cache when it is created
635 */
636static void
Alexey Dobriyan51cc5062008-07-25 19:45:34 -0700637inode_info_init_once(void *vptr)
Michael Halcrow237fead2006-10-04 02:16:22 -0700638{
639 struct ecryptfs_inode_info *ei = (struct ecryptfs_inode_info *)vptr;
640
Christoph Lametera35afb82007-05-16 22:10:57 -0700641 inode_init_once(&ei->vfs_inode);
Michael Halcrow237fead2006-10-04 02:16:22 -0700642}
643
644static struct ecryptfs_cache_info {
Christoph Lametere18b8902006-12-06 20:33:20 -0800645 struct kmem_cache **cache;
Michael Halcrow237fead2006-10-04 02:16:22 -0700646 const char *name;
647 size_t size;
Alexey Dobriyan51cc5062008-07-25 19:45:34 -0700648 void (*ctor)(void *obj);
Michael Halcrow237fead2006-10-04 02:16:22 -0700649} ecryptfs_cache_infos[] = {
650 {
651 .cache = &ecryptfs_auth_tok_list_item_cache,
652 .name = "ecryptfs_auth_tok_list_item",
653 .size = sizeof(struct ecryptfs_auth_tok_list_item),
654 },
655 {
656 .cache = &ecryptfs_file_info_cache,
657 .name = "ecryptfs_file_cache",
658 .size = sizeof(struct ecryptfs_file_info),
659 },
660 {
661 .cache = &ecryptfs_dentry_info_cache,
662 .name = "ecryptfs_dentry_info_cache",
663 .size = sizeof(struct ecryptfs_dentry_info),
664 },
665 {
666 .cache = &ecryptfs_inode_info_cache,
667 .name = "ecryptfs_inode_cache",
668 .size = sizeof(struct ecryptfs_inode_info),
669 .ctor = inode_info_init_once,
670 },
671 {
672 .cache = &ecryptfs_sb_info_cache,
673 .name = "ecryptfs_sb_cache",
674 .size = sizeof(struct ecryptfs_sb_info),
675 },
676 {
Michael Halcrow237fead2006-10-04 02:16:22 -0700677 .cache = &ecryptfs_header_cache_1,
678 .name = "ecryptfs_headers_1",
679 .size = PAGE_CACHE_SIZE,
680 },
681 {
682 .cache = &ecryptfs_header_cache_2,
683 .name = "ecryptfs_headers_2",
684 .size = PAGE_CACHE_SIZE,
685 },
686 {
Michael Halcrowdd2a3b72007-02-12 00:53:46 -0800687 .cache = &ecryptfs_xattr_cache,
688 .name = "ecryptfs_xattr_cache",
689 .size = PAGE_CACHE_SIZE,
690 },
691 {
Michael Halcroweb95e7f2007-02-16 01:28:40 -0800692 .cache = &ecryptfs_key_record_cache,
693 .name = "ecryptfs_key_record_cache",
694 .size = sizeof(struct ecryptfs_key_record),
695 },
Michael Halcrow956159c2007-10-16 01:27:55 -0700696 {
697 .cache = &ecryptfs_key_sig_cache,
698 .name = "ecryptfs_key_sig_cache",
699 .size = sizeof(struct ecryptfs_key_sig),
700 },
701 {
702 .cache = &ecryptfs_global_auth_tok_cache,
703 .name = "ecryptfs_global_auth_tok_cache",
704 .size = sizeof(struct ecryptfs_global_auth_tok),
705 },
706 {
707 .cache = &ecryptfs_key_tfm_cache,
708 .name = "ecryptfs_key_tfm_cache",
709 .size = sizeof(struct ecryptfs_key_tfm),
710 },
Michael Halcrow746f1e52008-07-23 21:30:02 -0700711 {
712 .cache = &ecryptfs_open_req_cache,
713 .name = "ecryptfs_open_req_cache",
714 .size = sizeof(struct ecryptfs_open_req),
715 },
Michael Halcrow237fead2006-10-04 02:16:22 -0700716};
717
718static void ecryptfs_free_kmem_caches(void)
719{
720 int i;
721
722 for (i = 0; i < ARRAY_SIZE(ecryptfs_cache_infos); i++) {
723 struct ecryptfs_cache_info *info;
724
725 info = &ecryptfs_cache_infos[i];
726 if (*(info->cache))
727 kmem_cache_destroy(*(info->cache));
728 }
729}
730
731/**
732 * ecryptfs_init_kmem_caches
733 *
734 * Returns zero on success; non-zero otherwise
735 */
736static int ecryptfs_init_kmem_caches(void)
737{
738 int i;
739
740 for (i = 0; i < ARRAY_SIZE(ecryptfs_cache_infos); i++) {
741 struct ecryptfs_cache_info *info;
742
743 info = &ecryptfs_cache_infos[i];
744 *(info->cache) = kmem_cache_create(info->name, info->size,
Paul Mundt20c2df82007-07-20 10:11:58 +0900745 0, SLAB_HWCACHE_ALIGN, info->ctor);
Michael Halcrow237fead2006-10-04 02:16:22 -0700746 if (!*(info->cache)) {
747 ecryptfs_free_kmem_caches();
748 ecryptfs_printk(KERN_WARNING, "%s: "
749 "kmem_cache_create failed\n",
750 info->name);
751 return -ENOMEM;
752 }
753 }
754 return 0;
755}
756
Greg Kroah-Hartman6e90aa92007-11-06 15:08:08 -0800757static struct kobject *ecryptfs_kobj;
Michael Halcrow237fead2006-10-04 02:16:22 -0700758
Kay Sievers386f2752007-11-02 13:47:53 +0100759static ssize_t version_show(struct kobject *kobj,
760 struct kobj_attribute *attr, char *buff)
Michael Halcrow237fead2006-10-04 02:16:22 -0700761{
762 return snprintf(buff, PAGE_SIZE, "%d\n", ECRYPTFS_VERSIONING_MASK);
763}
764
Kay Sievers386f2752007-11-02 13:47:53 +0100765static struct kobj_attribute version_attr = __ATTR_RO(version);
Michael Halcrow237fead2006-10-04 02:16:22 -0700766
Greg Kroah-Hartman30a468b2007-10-15 15:01:24 -0700767static struct attribute *attributes[] = {
768 &version_attr.attr,
Greg Kroah-Hartman30a468b2007-10-15 15:01:24 -0700769 NULL,
770};
771
772static struct attribute_group attr_group = {
773 .attrs = attributes,
774};
Michael Halcrow237fead2006-10-04 02:16:22 -0700775
776static int do_sysfs_registration(void)
777{
778 int rc;
779
Greg Kroah-Hartman6e90aa92007-11-06 15:08:08 -0800780 ecryptfs_kobj = kobject_create_and_add("ecryptfs", fs_kobj);
781 if (!ecryptfs_kobj) {
Greg Kroah-Hartman917e8652007-10-29 20:13:17 +0100782 printk(KERN_ERR "Unable to create ecryptfs kset\n");
783 rc = -ENOMEM;
Michael Halcrow237fead2006-10-04 02:16:22 -0700784 goto out;
785 }
Greg Kroah-Hartman6e90aa92007-11-06 15:08:08 -0800786 rc = sysfs_create_group(ecryptfs_kobj, &attr_group);
Michael Halcrow237fead2006-10-04 02:16:22 -0700787 if (rc) {
788 printk(KERN_ERR
Greg Kroah-Hartman30a468b2007-10-15 15:01:24 -0700789 "Unable to create ecryptfs version attributes\n");
Greg Kroah-Hartman197b12d2007-12-20 08:13:05 -0800790 kobject_put(ecryptfs_kobj);
Michael Halcrow237fead2006-10-04 02:16:22 -0700791 }
792out:
793 return rc;
794}
795
Ryusuke Konishia75de1b2007-08-10 13:00:56 -0700796static void do_sysfs_unregistration(void)
797{
Greg Kroah-Hartman6e90aa92007-11-06 15:08:08 -0800798 sysfs_remove_group(ecryptfs_kobj, &attr_group);
Greg Kroah-Hartman197b12d2007-12-20 08:13:05 -0800799 kobject_put(ecryptfs_kobj);
Ryusuke Konishia75de1b2007-08-10 13:00:56 -0700800}
801
Michael Halcrow237fead2006-10-04 02:16:22 -0700802static int __init ecryptfs_init(void)
803{
804 int rc;
805
806 if (ECRYPTFS_DEFAULT_EXTENT_SIZE > PAGE_CACHE_SIZE) {
807 rc = -EINVAL;
808 ecryptfs_printk(KERN_ERR, "The eCryptfs extent size is "
809 "larger than the host's page size, and so "
810 "eCryptfs cannot run on this system. The "
Joe Perches888d57b2010-11-10 15:46:16 -0800811 "default eCryptfs extent size is [%u] bytes; "
812 "the page size is [%lu] bytes.\n",
813 ECRYPTFS_DEFAULT_EXTENT_SIZE,
814 (unsigned long)PAGE_CACHE_SIZE);
Michael Halcrow237fead2006-10-04 02:16:22 -0700815 goto out;
816 }
817 rc = ecryptfs_init_kmem_caches();
818 if (rc) {
819 printk(KERN_ERR
820 "Failed to allocate one or more kmem_cache objects\n");
821 goto out;
822 }
823 rc = register_filesystem(&ecryptfs_fs_type);
824 if (rc) {
825 printk(KERN_ERR "Failed to register filesystem\n");
Michael Halcrowcf81f892007-10-16 01:28:07 -0700826 goto out_free_kmem_caches;
Michael Halcrow237fead2006-10-04 02:16:22 -0700827 }
Michael Halcrow237fead2006-10-04 02:16:22 -0700828 rc = do_sysfs_registration();
829 if (rc) {
830 printk(KERN_ERR "sysfs registration failed\n");
Michael Halcrowcf81f892007-10-16 01:28:07 -0700831 goto out_unregister_filesystem;
Michael Halcrow237fead2006-10-04 02:16:22 -0700832 }
Michael Halcrow746f1e52008-07-23 21:30:02 -0700833 rc = ecryptfs_init_kthread();
834 if (rc) {
835 printk(KERN_ERR "%s: kthread initialization failed; "
836 "rc = [%d]\n", __func__, rc);
837 goto out_do_sysfs_unregistration;
838 }
Tyler Hicks624ae522008-10-15 22:02:51 -0700839 rc = ecryptfs_init_messaging();
Michael Halcrowdddfa462007-02-12 00:53:44 -0800840 if (rc) {
Michael Halcrow746f1e52008-07-23 21:30:02 -0700841 printk(KERN_ERR "Failure occured while attempting to "
Tyler Hicks624ae522008-10-15 22:02:51 -0700842 "initialize the communications channel to "
843 "ecryptfsd\n");
Michael Halcrow746f1e52008-07-23 21:30:02 -0700844 goto out_destroy_kthread;
Michael Halcrow956159c2007-10-16 01:27:55 -0700845 }
846 rc = ecryptfs_init_crypto();
847 if (rc) {
848 printk(KERN_ERR "Failure whilst attempting to init crypto; "
849 "rc = [%d]\n", rc);
Michael Halcrowcf81f892007-10-16 01:28:07 -0700850 goto out_release_messaging;
Michael Halcrowdddfa462007-02-12 00:53:44 -0800851 }
Eric Sandeen2830bfd2008-02-06 01:38:34 -0800852 if (ecryptfs_verbosity > 0)
853 printk(KERN_CRIT "eCryptfs verbosity set to %d. Secret values "
854 "will be written to the syslog!\n", ecryptfs_verbosity);
855
Michael Halcrowcf81f892007-10-16 01:28:07 -0700856 goto out;
857out_release_messaging:
Tyler Hicks624ae522008-10-15 22:02:51 -0700858 ecryptfs_release_messaging();
Michael Halcrow746f1e52008-07-23 21:30:02 -0700859out_destroy_kthread:
860 ecryptfs_destroy_kthread();
Michael Halcrowcf81f892007-10-16 01:28:07 -0700861out_do_sysfs_unregistration:
862 do_sysfs_unregistration();
863out_unregister_filesystem:
864 unregister_filesystem(&ecryptfs_fs_type);
865out_free_kmem_caches:
866 ecryptfs_free_kmem_caches();
Michael Halcrow237fead2006-10-04 02:16:22 -0700867out:
868 return rc;
869}
870
871static void __exit ecryptfs_exit(void)
872{
Michael Halcrowcf81f892007-10-16 01:28:07 -0700873 int rc;
874
875 rc = ecryptfs_destroy_crypto();
876 if (rc)
877 printk(KERN_ERR "Failure whilst attempting to destroy crypto; "
878 "rc = [%d]\n", rc);
Tyler Hicks624ae522008-10-15 22:02:51 -0700879 ecryptfs_release_messaging();
Michael Halcrow746f1e52008-07-23 21:30:02 -0700880 ecryptfs_destroy_kthread();
Michael Halcrowcf81f892007-10-16 01:28:07 -0700881 do_sysfs_unregistration();
Michael Halcrow237fead2006-10-04 02:16:22 -0700882 unregister_filesystem(&ecryptfs_fs_type);
883 ecryptfs_free_kmem_caches();
884}
885
886MODULE_AUTHOR("Michael A. Halcrow <mhalcrow@us.ibm.com>");
887MODULE_DESCRIPTION("eCryptfs");
888
889MODULE_LICENSE("GPL");
890
891module_init(ecryptfs_init)
892module_exit(ecryptfs_exit)