Linux kernel & device driver programming

Cross-Referenced Linux and Device Driver Code

[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ]
Version: [ 2.6.11.8 ] [ 2.6.25 ] [ 2.6.25.8 ] [ 2.6.31.13 ] Architecture: [ i386 ]

Diff markup

Differences between /linux/fs/ecryptfs/main.c (Version 2.6.25) and /linux/fs/ecryptfs/main.c (Version 2.6.25.8)


  1 /**                                                 1 /**
  2  * eCryptfs: Linux filesystem encryption layer      2  * eCryptfs: Linux filesystem encryption layer
  3  *                                                  3  *
  4  * Copyright (C) 1997-2003 Erez Zadok               4  * Copyright (C) 1997-2003 Erez Zadok
  5  * Copyright (C) 2001-2003 Stony Brook Univers      5  * Copyright (C) 2001-2003 Stony Brook University
  6  * Copyright (C) 2004-2007 International Busin      6  * Copyright (C) 2004-2007 International Business Machines Corp.
  7  *   Author(s): Michael A. Halcrow <mahalcro@u      7  *   Author(s): Michael A. Halcrow <mahalcro@us.ibm.com>
  8  *              Michael C. Thompson <mcthomps@      8  *              Michael C. Thompson <mcthomps@us.ibm.com>
  9  *              Tyler Hicks <tyhicks@ou.edu>        9  *              Tyler Hicks <tyhicks@ou.edu>
 10  *                                                 10  *
 11  * This program is free software; you can redi     11  * This program is free software; you can redistribute it and/or
 12  * modify it under the terms of the GNU Genera     12  * modify it under the terms of the GNU General Public License as
 13  * published by the Free Software Foundation;      13  * published by the Free Software Foundation; either version 2 of the
 14  * License, or (at your option) any later vers     14  * License, or (at your option) any later version.
 15  *                                                 15  *
 16  * This program is distributed in the hope tha     16  * This program is distributed in the hope that it will be useful, but
 17  * WITHOUT ANY WARRANTY; without even the impl     17  * WITHOUT ANY WARRANTY; without even the implied warranty of
 18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR     18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 19  * General Public License for more details.        19  * General Public License for more details.
 20  *                                                 20  *
 21  * You should have received a copy of the GNU      21  * You should have received a copy of the GNU General Public License
 22  * along with this program; if not, write to t     22  * along with this program; if not, write to the Free Software
 23  * Foundation, Inc., 59 Temple Place - Suite 3     23  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 24  * 02111-1307, USA.                                24  * 02111-1307, USA.
 25  */                                                25  */
 26                                                    26 
 27 #include <linux/dcache.h>                          27 #include <linux/dcache.h>
 28 #include <linux/file.h>                            28 #include <linux/file.h>
 29 #include <linux/module.h>                          29 #include <linux/module.h>
 30 #include <linux/namei.h>                           30 #include <linux/namei.h>
 31 #include <linux/skbuff.h>                          31 #include <linux/skbuff.h>
 32 #include <linux/crypto.h>                          32 #include <linux/crypto.h>
 33 #include <linux/netlink.h>                         33 #include <linux/netlink.h>
 34 #include <linux/mount.h>                           34 #include <linux/mount.h>
 35 #include <linux/pagemap.h>                         35 #include <linux/pagemap.h>
 36 #include <linux/key.h>                             36 #include <linux/key.h>
 37 #include <linux/parser.h>                          37 #include <linux/parser.h>
 38 #include <linux/fs_stack.h>                        38 #include <linux/fs_stack.h>
 39 #include "ecryptfs_kernel.h"                       39 #include "ecryptfs_kernel.h"
 40                                                    40 
 41 /**                                                41 /**
 42  * Module parameter that defines the ecryptfs_     42  * Module parameter that defines the ecryptfs_verbosity level.
 43  */                                                43  */
 44 int ecryptfs_verbosity = 0;                        44 int ecryptfs_verbosity = 0;
 45                                                    45 
 46 module_param(ecryptfs_verbosity, int, 0);          46 module_param(ecryptfs_verbosity, int, 0);
 47 MODULE_PARM_DESC(ecryptfs_verbosity,               47 MODULE_PARM_DESC(ecryptfs_verbosity,
 48                  "Initial verbosity level (0 o     48                  "Initial verbosity level (0 or 1; defaults to "
 49                  "0, which is Quiet)");            49                  "0, which is Quiet)");
 50                                                    50 
 51 /**                                                51 /**
 52  * Module parameter that defines the number of     52  * Module parameter that defines the number of netlink message buffer
 53  * elements                                        53  * elements
 54  */                                                54  */
 55 unsigned int ecryptfs_message_buf_len = ECRYPT     55 unsigned int ecryptfs_message_buf_len = ECRYPTFS_DEFAULT_MSG_CTX_ELEMS;
 56                                                    56 
 57 module_param(ecryptfs_message_buf_len, uint, 0     57 module_param(ecryptfs_message_buf_len, uint, 0);
 58 MODULE_PARM_DESC(ecryptfs_message_buf_len,         58 MODULE_PARM_DESC(ecryptfs_message_buf_len,
 59                  "Number of message buffer ele     59                  "Number of message buffer elements");
 60                                                    60 
 61 /**                                                61 /**
 62  * Module parameter that defines the maximum g     62  * Module parameter that defines the maximum guaranteed amount of time to wait
 63  * for a response through netlink.  The actual     63  * for a response through netlink.  The actual sleep time will be, more than
 64  * likely, a small amount greater than this sp     64  * likely, a small amount greater than this specified value, but only less if
 65  * the netlink message successfully arrives.       65  * the netlink message successfully arrives.
 66  */                                                66  */
 67 signed long ecryptfs_message_wait_timeout = EC     67 signed long ecryptfs_message_wait_timeout = ECRYPTFS_MAX_MSG_CTX_TTL / HZ;
 68                                                    68 
 69 module_param(ecryptfs_message_wait_timeout, lo     69 module_param(ecryptfs_message_wait_timeout, long, 0);
 70 MODULE_PARM_DESC(ecryptfs_message_wait_timeout     70 MODULE_PARM_DESC(ecryptfs_message_wait_timeout,
 71                  "Maximum number of seconds th     71                  "Maximum number of seconds that an operation will "
 72                  "sleep while waiting for a me     72                  "sleep while waiting for a message response from "
 73                  "userspace");                     73                  "userspace");
 74                                                    74 
 75 /**                                                75 /**
 76  * Module parameter that is an estimate of the     76  * Module parameter that is an estimate of the maximum number of users
 77  * that will be concurrently using eCryptfs. S     77  * that will be concurrently using eCryptfs. Set this to the right
 78  * value to balance performance and memory use     78  * value to balance performance and memory use.
 79  */                                                79  */
 80 unsigned int ecryptfs_number_of_users = ECRYPT     80 unsigned int ecryptfs_number_of_users = ECRYPTFS_DEFAULT_NUM_USERS;
 81                                                    81 
 82 module_param(ecryptfs_number_of_users, uint, 0     82 module_param(ecryptfs_number_of_users, uint, 0);
 83 MODULE_PARM_DESC(ecryptfs_number_of_users, "An     83 MODULE_PARM_DESC(ecryptfs_number_of_users, "An estimate of the number of "
 84                  "concurrent users of eCryptfs     84                  "concurrent users of eCryptfs");
 85                                                    85 
 86 unsigned int ecryptfs_transport = ECRYPTFS_DEF     86 unsigned int ecryptfs_transport = ECRYPTFS_DEFAULT_TRANSPORT;
 87                                                    87 
 88 void __ecryptfs_printk(const char *fmt, ...)       88 void __ecryptfs_printk(const char *fmt, ...)
 89 {                                                  89 {
 90         va_list args;                              90         va_list args;
 91         va_start(args, fmt);                       91         va_start(args, fmt);
 92         if (fmt[1] == '7') { /* KERN_DEBUG */      92         if (fmt[1] == '7') { /* KERN_DEBUG */
 93                 if (ecryptfs_verbosity >= 1)       93                 if (ecryptfs_verbosity >= 1)
 94                         vprintk(fmt, args);        94                         vprintk(fmt, args);
 95         } else                                     95         } else
 96                 vprintk(fmt, args);                96                 vprintk(fmt, args);
 97         va_end(args);                              97         va_end(args);
 98 }                                                  98 }
 99                                                    99 
100 /**                                               100 /**
101  * ecryptfs_init_persistent_file                  101  * ecryptfs_init_persistent_file
102  * @ecryptfs_dentry: Fully initialized eCryptf    102  * @ecryptfs_dentry: Fully initialized eCryptfs dentry object, with
103  *                   the lower dentry and the     103  *                   the lower dentry and the lower mount set
104  *                                                104  *
105  * eCryptfs only ever keeps a single open file    105  * eCryptfs only ever keeps a single open file for every lower
106  * inode. All I/O operations to the lower inod    106  * inode. All I/O operations to the lower inode occur through that
107  * file. When the first eCryptfs dentry that i    107  * file. When the first eCryptfs dentry that interposes with the first
108  * lower dentry for that inode is created, thi    108  * lower dentry for that inode is created, this function creates the
109  * persistent file struct and associates it wi    109  * persistent file struct and associates it with the eCryptfs
110  * inode. When the eCryptfs inode is destroyed    110  * inode. When the eCryptfs inode is destroyed, the file is closed.
111  *                                                111  *
112  * The persistent file will be opened with rea    112  * The persistent file will be opened with read/write permissions, if
113  * possible. Otherwise, it is opened read-only    113  * possible. Otherwise, it is opened read-only.
114  *                                                114  *
115  * This function does nothing if a lower persi    115  * This function does nothing if a lower persistent file is already
116  * associated with the eCryptfs inode.            116  * associated with the eCryptfs inode.
117  *                                                117  *
118  * Returns zero on success; non-zero otherwise    118  * Returns zero on success; non-zero otherwise
119  */                                               119  */
120 static int ecryptfs_init_persistent_file(struc    120 static int ecryptfs_init_persistent_file(struct dentry *ecryptfs_dentry)
121 {                                                 121 {
122         struct ecryptfs_inode_info *inode_info    122         struct ecryptfs_inode_info *inode_info =
123                 ecryptfs_inode_to_private(ecry    123                 ecryptfs_inode_to_private(ecryptfs_dentry->d_inode);
124         int rc = 0;                               124         int rc = 0;
125                                                   125 
126         mutex_lock(&inode_info->lower_file_mut    126         mutex_lock(&inode_info->lower_file_mutex);
127         if (!inode_info->lower_file) {            127         if (!inode_info->lower_file) {
128                 struct dentry *lower_dentry;      128                 struct dentry *lower_dentry;
129                 struct vfsmount *lower_mnt =      129                 struct vfsmount *lower_mnt =
130                         ecryptfs_dentry_to_low    130                         ecryptfs_dentry_to_lower_mnt(ecryptfs_dentry);
131                                                   131 
132                 lower_dentry = ecryptfs_dentry    132                 lower_dentry = ecryptfs_dentry_to_lower(ecryptfs_dentry);
133                 /* Corresponding dput() and mn    133                 /* Corresponding dput() and mntput() are done when the
134                  * persistent file is fput() w    134                  * persistent file is fput() when the eCryptfs inode
135                  * is destroyed. */               135                  * is destroyed. */
136                 dget(lower_dentry);               136                 dget(lower_dentry);
137                 mntget(lower_mnt);                137                 mntget(lower_mnt);
138                 inode_info->lower_file = dentr    138                 inode_info->lower_file = dentry_open(lower_dentry,
139                                                   139                                                      lower_mnt,
140                                                   140                                                      (O_RDWR | O_LARGEFILE));
141                 if (IS_ERR(inode_info->lower_f    141                 if (IS_ERR(inode_info->lower_file)) {
142                         dget(lower_dentry);       142                         dget(lower_dentry);
143                         mntget(lower_mnt);        143                         mntget(lower_mnt);
144                         inode_info->lower_file    144                         inode_info->lower_file = dentry_open(lower_dentry,
145                                                   145                                                              lower_mnt,
146                                                   146                                                              (O_RDONLY
147                                                   147                                                               | O_LARGEFILE));
148                 }                                 148                 }
149                 if (IS_ERR(inode_info->lower_f    149                 if (IS_ERR(inode_info->lower_file)) {
150                         printk(KERN_ERR "Error    150                         printk(KERN_ERR "Error opening lower persistent file "
151                                "for lower_dent    151                                "for lower_dentry [0x%p] and lower_mnt [0x%p]\n",
152                                lower_dentry, l    152                                lower_dentry, lower_mnt);
153                         rc = PTR_ERR(inode_inf    153                         rc = PTR_ERR(inode_info->lower_file);
154                         inode_info->lower_file    154                         inode_info->lower_file = NULL;
155                 }                                 155                 }
156         }                                         156         }
157         mutex_unlock(&inode_info->lower_file_m    157         mutex_unlock(&inode_info->lower_file_mutex);
158         return rc;                                158         return rc;
159 }                                                 159 }
160                                                   160 
161 /**                                               161 /**
162  * ecryptfs_interpose                             162  * ecryptfs_interpose
163  * @lower_dentry: Existing dentry in the lower    163  * @lower_dentry: Existing dentry in the lower filesystem
164  * @dentry: ecryptfs' dentry                      164  * @dentry: ecryptfs' dentry
165  * @sb: ecryptfs's super_block                    165  * @sb: ecryptfs's super_block
166  * @flag: If set to true, then d_add is called    166  * @flag: If set to true, then d_add is called, else d_instantiate is called
167  *                                                167  *
168  * Interposes upper and lower dentries.           168  * Interposes upper and lower dentries.
169  *                                                169  *
170  * Returns zero on success; non-zero otherwise    170  * Returns zero on success; non-zero otherwise
171  */                                               171  */
172 int ecryptfs_interpose(struct dentry *lower_de    172 int ecryptfs_interpose(struct dentry *lower_dentry, struct dentry *dentry,
173                        struct super_block *sb,    173                        struct super_block *sb, int flag)
174 {                                                 174 {
175         struct inode *lower_inode;                175         struct inode *lower_inode;
176         struct inode *inode;                      176         struct inode *inode;
177         int rc = 0;                               177         int rc = 0;
178                                                   178 
179         lower_inode = lower_dentry->d_inode;      179         lower_inode = lower_dentry->d_inode;
180         if (lower_inode->i_sb != ecryptfs_supe    180         if (lower_inode->i_sb != ecryptfs_superblock_to_lower(sb)) {
181                 rc = -EXDEV;                      181                 rc = -EXDEV;
182                 goto out;                         182                 goto out;
183         }                                         183         }
184         if (!igrab(lower_inode)) {                184         if (!igrab(lower_inode)) {
185                 rc = -ESTALE;                     185                 rc = -ESTALE;
186                 goto out;                         186                 goto out;
187         }                                         187         }
188         inode = iget5_locked(sb, (unsigned lon    188         inode = iget5_locked(sb, (unsigned long)lower_inode,
189                              ecryptfs_inode_te    189                              ecryptfs_inode_test, ecryptfs_inode_set,
190                              lower_inode);        190                              lower_inode);
191         if (!inode) {                             191         if (!inode) {
192                 rc = -EACCES;                     192                 rc = -EACCES;
193                 iput(lower_inode);                193                 iput(lower_inode);
194                 goto out;                         194                 goto out;
195         }                                         195         }
196         if (inode->i_state & I_NEW)               196         if (inode->i_state & I_NEW)
197                 unlock_new_inode(inode);          197                 unlock_new_inode(inode);
198         else                                      198         else
199                 iput(lower_inode);                199                 iput(lower_inode);
200         if (S_ISLNK(lower_inode->i_mode))         200         if (S_ISLNK(lower_inode->i_mode))
201                 inode->i_op = &ecryptfs_symlin    201                 inode->i_op = &ecryptfs_symlink_iops;
202         else if (S_ISDIR(lower_inode->i_mode))    202         else if (S_ISDIR(lower_inode->i_mode))
203                 inode->i_op = &ecryptfs_dir_io    203                 inode->i_op = &ecryptfs_dir_iops;
204         if (S_ISDIR(lower_inode->i_mode))         204         if (S_ISDIR(lower_inode->i_mode))
205                 inode->i_fop = &ecryptfs_dir_f    205                 inode->i_fop = &ecryptfs_dir_fops;
206         if (special_file(lower_inode->i_mode))    206         if (special_file(lower_inode->i_mode))
207                 init_special_inode(inode, lowe    207                 init_special_inode(inode, lower_inode->i_mode,
208                                    lower_inode    208                                    lower_inode->i_rdev);
209         dentry->d_op = &ecryptfs_dops;            209         dentry->d_op = &ecryptfs_dops;
210         if (flag)                                 210         if (flag)
211                 d_add(dentry, inode);             211                 d_add(dentry, inode);
212         else                                      212         else
213                 d_instantiate(dentry, inode);     213                 d_instantiate(dentry, inode);
214         fsstack_copy_attr_all(inode, lower_ino    214         fsstack_copy_attr_all(inode, lower_inode, NULL);
215         /* This size will be overwritten for r    215         /* This size will be overwritten for real files w/ headers and
216          * other metadata */                      216          * other metadata */
217         fsstack_copy_inode_size(inode, lower_i    217         fsstack_copy_inode_size(inode, lower_inode);
218         rc = ecryptfs_init_persistent_file(den    218         rc = ecryptfs_init_persistent_file(dentry);
219         if (rc) {                                 219         if (rc) {
220                 printk(KERN_ERR "%s: Error att    220                 printk(KERN_ERR "%s: Error attempting to initialize the "
221                        "persistent file for th    221                        "persistent file for the dentry with name [%s]; "
222                        "rc = [%d]\n", __FUNCTI    222                        "rc = [%d]\n", __FUNCTION__, dentry->d_name.name, rc);
223                 goto out;                         223                 goto out;
224         }                                         224         }
225 out:                                              225 out:
226         return rc;                                226         return rc;
227 }                                                 227 }
228                                                   228 
229 enum { ecryptfs_opt_sig, ecryptfs_opt_ecryptfs    229 enum { ecryptfs_opt_sig, ecryptfs_opt_ecryptfs_sig,
230        ecryptfs_opt_cipher, ecryptfs_opt_ecryp    230        ecryptfs_opt_cipher, ecryptfs_opt_ecryptfs_cipher,
231        ecryptfs_opt_ecryptfs_key_bytes,           231        ecryptfs_opt_ecryptfs_key_bytes,
232        ecryptfs_opt_passthrough, ecryptfs_opt_    232        ecryptfs_opt_passthrough, ecryptfs_opt_xattr_metadata,
233        ecryptfs_opt_encrypted_view, ecryptfs_o    233        ecryptfs_opt_encrypted_view, ecryptfs_opt_err };
234                                                   234 
235 static match_table_t tokens = {                   235 static match_table_t tokens = {
236         {ecryptfs_opt_sig, "sig=%s"},             236         {ecryptfs_opt_sig, "sig=%s"},
237         {ecryptfs_opt_ecryptfs_sig, "ecryptfs_    237         {ecryptfs_opt_ecryptfs_sig, "ecryptfs_sig=%s"},
238         {ecryptfs_opt_cipher, "cipher=%s"},       238         {ecryptfs_opt_cipher, "cipher=%s"},
239         {ecryptfs_opt_ecryptfs_cipher, "ecrypt    239         {ecryptfs_opt_ecryptfs_cipher, "ecryptfs_cipher=%s"},
240         {ecryptfs_opt_ecryptfs_key_bytes, "ecr    240         {ecryptfs_opt_ecryptfs_key_bytes, "ecryptfs_key_bytes=%u"},
241         {ecryptfs_opt_passthrough, "ecryptfs_p    241         {ecryptfs_opt_passthrough, "ecryptfs_passthrough"},
242         {ecryptfs_opt_xattr_metadata, "ecryptf    242         {ecryptfs_opt_xattr_metadata, "ecryptfs_xattr_metadata"},
243         {ecryptfs_opt_encrypted_view, "ecryptf    243         {ecryptfs_opt_encrypted_view, "ecryptfs_encrypted_view"},
244         {ecryptfs_opt_err, NULL}                  244         {ecryptfs_opt_err, NULL}
245 };                                                245 };
246                                                   246 
247 static int ecryptfs_init_global_auth_toks(        247 static int ecryptfs_init_global_auth_toks(
248         struct ecryptfs_mount_crypt_stat *moun    248         struct ecryptfs_mount_crypt_stat *mount_crypt_stat)
249 {                                                 249 {
250         struct ecryptfs_global_auth_tok *globa    250         struct ecryptfs_global_auth_tok *global_auth_tok;
251         int rc = 0;                               251         int rc = 0;
252                                                   252 
253         list_for_each_entry(global_auth_tok,      253         list_for_each_entry(global_auth_tok,
254                             &mount_crypt_stat-    254                             &mount_crypt_stat->global_auth_tok_list,
255                             mount_crypt_stat_l    255                             mount_crypt_stat_list) {
256                 rc = ecryptfs_keyring_auth_tok    256                 rc = ecryptfs_keyring_auth_tok_for_sig(
257                         &global_auth_tok->glob    257                         &global_auth_tok->global_auth_tok_key,
258                         &global_auth_tok->glob    258                         &global_auth_tok->global_auth_tok,
259                         global_auth_tok->sig);    259                         global_auth_tok->sig);
260                 if (rc) {                         260                 if (rc) {
261                         printk(KERN_ERR "Could    261                         printk(KERN_ERR "Could not find valid key in user "
262                                "session keyrin    262                                "session keyring for sig specified in mount "
263                                "option: [%s]\n    263                                "option: [%s]\n", global_auth_tok->sig);
264                         global_auth_tok->flags    264                         global_auth_tok->flags |= ECRYPTFS_AUTH_TOK_INVALID;
265                         rc = 0;                   265                         rc = 0;
266                 } else                            266                 } else
267                         global_auth_tok->flags    267                         global_auth_tok->flags &= ~ECRYPTFS_AUTH_TOK_INVALID;
268         }                                         268         }
269         return rc;                                269         return rc;
270 }                                                 270 }
271                                                   271 
272 static void ecryptfs_init_mount_crypt_stat(       272 static void ecryptfs_init_mount_crypt_stat(
273         struct ecryptfs_mount_crypt_stat *moun    273         struct ecryptfs_mount_crypt_stat *mount_crypt_stat)
274 {                                                 274 {
275         memset((void *)mount_crypt_stat, 0,       275         memset((void *)mount_crypt_stat, 0,
276                sizeof(struct ecryptfs_mount_cr    276                sizeof(struct ecryptfs_mount_crypt_stat));
277         INIT_LIST_HEAD(&mount_crypt_stat->glob    277         INIT_LIST_HEAD(&mount_crypt_stat->global_auth_tok_list);
278         mutex_init(&mount_crypt_stat->global_a    278         mutex_init(&mount_crypt_stat->global_auth_tok_list_mutex);
279         mount_crypt_stat->flags |= ECRYPTFS_MO    279         mount_crypt_stat->flags |= ECRYPTFS_MOUNT_CRYPT_STAT_INITIALIZED;
280 }                                                 280 }
281                                                   281 
282 /**                                               282 /**
283  * ecryptfs_parse_options                         283  * ecryptfs_parse_options
284  * @sb: The ecryptfs super block                  284  * @sb: The ecryptfs super block
285  * @options: The options pased to the kernel      285  * @options: The options pased to the kernel
286  *                                                286  *
287  * Parse mount options:                           287  * Parse mount options:
288  * debug=N         - ecryptfs_verbosity level     288  * debug=N         - ecryptfs_verbosity level for debug output
289  * sig=XXX         - description(signature) of    289  * sig=XXX         - description(signature) of the key to use
290  *                                                290  *
291  * Returns the dentry object of the lower-leve    291  * Returns the dentry object of the lower-level (lower/interposed)
292  * directory; We want to mount our stackable f    292  * directory; We want to mount our stackable file system on top of
293  * that lower directory.                          293  * that lower directory.
294  *                                                294  *
295  * The signature of the key to use must be the    295  * The signature of the key to use must be the description of a key
296  * already in the keyring. Mounting will fail     296  * already in the keyring. Mounting will fail if the key can not be
297  * found.                                         297  * found.
298  *                                                298  *
299  * Returns zero on success; non-zero on error     299  * Returns zero on success; non-zero on error
300  */                                               300  */
301 static int ecryptfs_parse_options(struct super    301 static int ecryptfs_parse_options(struct super_block *sb, char *options)
302 {                                                 302 {
303         char *p;                                  303         char *p;
304         int rc = 0;                               304         int rc = 0;
305         int sig_set = 0;                          305         int sig_set = 0;
306         int cipher_name_set = 0;                  306         int cipher_name_set = 0;
307         int cipher_key_bytes;                     307         int cipher_key_bytes;
308         int cipher_key_bytes_set = 0;             308         int cipher_key_bytes_set = 0;
309         struct ecryptfs_mount_crypt_stat *moun    309         struct ecryptfs_mount_crypt_stat *mount_crypt_stat =
310                 &ecryptfs_superblock_to_privat    310                 &ecryptfs_superblock_to_private(sb)->mount_crypt_stat;
311         substring_t args[MAX_OPT_ARGS];           311         substring_t args[MAX_OPT_ARGS];
312         int token;                                312         int token;
313         char *sig_src;                            313         char *sig_src;
314         char *cipher_name_dst;                    314         char *cipher_name_dst;
315         char *cipher_name_src;                    315         char *cipher_name_src;
316         char *cipher_key_bytes_src;               316         char *cipher_key_bytes_src;
317         int cipher_name_len;                      317         int cipher_name_len;
318                                                   318 
319         if (!options) {                           319         if (!options) {
320                 rc = -EINVAL;                     320                 rc = -EINVAL;
321                 goto out;                         321                 goto out;
322         }                                         322         }
323         ecryptfs_init_mount_crypt_stat(mount_c    323         ecryptfs_init_mount_crypt_stat(mount_crypt_stat);
324         while ((p = strsep(&options, ",")) !=     324         while ((p = strsep(&options, ",")) != NULL) {
325                 if (!*p)                          325                 if (!*p)
326                         continue;                 326                         continue;
327                 token = match_token(p, tokens,    327                 token = match_token(p, tokens, args);
328                 switch (token) {                  328                 switch (token) {
329                 case ecryptfs_opt_sig:            329                 case ecryptfs_opt_sig:
330                 case ecryptfs_opt_ecryptfs_sig    330                 case ecryptfs_opt_ecryptfs_sig:
331                         sig_src = args[0].from    331                         sig_src = args[0].from;
332                         rc = ecryptfs_add_glob    332                         rc = ecryptfs_add_global_auth_tok(mount_crypt_stat,
333                                                   333                                                           sig_src);
334                         if (rc) {                 334                         if (rc) {
335                                 printk(KERN_ER    335                                 printk(KERN_ERR "Error attempting to register "
336                                        "global    336                                        "global sig; rc = [%d]\n", rc);
337                                 goto out;         337                                 goto out;
338                         }                         338                         }
339                         sig_set = 1;              339                         sig_set = 1;
340                         break;                    340                         break;
341                 case ecryptfs_opt_cipher:         341                 case ecryptfs_opt_cipher:
342                 case ecryptfs_opt_ecryptfs_cip    342                 case ecryptfs_opt_ecryptfs_cipher:
343                         cipher_name_src = args    343                         cipher_name_src = args[0].from;
344                         cipher_name_dst =         344                         cipher_name_dst =
345                                 mount_crypt_st    345                                 mount_crypt_stat->
346                                 global_default    346                                 global_default_cipher_name;
347                         strncpy(cipher_name_ds    347                         strncpy(cipher_name_dst, cipher_name_src,
348                                 ECRYPTFS_MAX_C    348                                 ECRYPTFS_MAX_CIPHER_NAME_SIZE);
349                         ecryptfs_printk(KERN_D    349                         ecryptfs_printk(KERN_DEBUG,
350                                         "The m    350                                         "The mount_crypt_stat "
351                                         "globa    351                                         "global_default_cipher_name set to: "
352                                         "[%s]\    352                                         "[%s]\n", cipher_name_dst);
353                         cipher_name_set = 1;      353                         cipher_name_set = 1;
354                         break;                    354                         break;
355                 case ecryptfs_opt_ecryptfs_key    355                 case ecryptfs_opt_ecryptfs_key_bytes:
356                         cipher_key_bytes_src =    356                         cipher_key_bytes_src = args[0].from;
357                         cipher_key_bytes =        357                         cipher_key_bytes =
358                                 (int)simple_st    358                                 (int)simple_strtol(cipher_key_bytes_src,
359                                                   359                                                    &cipher_key_bytes_src, 0);
360                         mount_crypt_stat->glob    360                         mount_crypt_stat->global_default_cipher_key_size =
361                                 cipher_key_byt    361                                 cipher_key_bytes;
362                         ecryptfs_printk(KERN_D    362                         ecryptfs_printk(KERN_DEBUG,
363                                         "The m    363                                         "The mount_crypt_stat "
364                                         "globa    364                                         "global_default_cipher_key_size "
365                                         "set t    365                                         "set to: [%d]\n", mount_crypt_stat->
366                                         global    366                                         global_default_cipher_key_size);
367                         cipher_key_bytes_set =    367                         cipher_key_bytes_set = 1;
368                         break;                    368                         break;
369                 case ecryptfs_opt_passthrough:    369                 case ecryptfs_opt_passthrough:
370                         mount_crypt_stat->flag    370                         mount_crypt_stat->flags |=
371                                 ECRYPTFS_PLAIN    371                                 ECRYPTFS_PLAINTEXT_PASSTHROUGH_ENABLED;
372                         break;                    372                         break;
373                 case ecryptfs_opt_xattr_metada    373                 case ecryptfs_opt_xattr_metadata:
374                         mount_crypt_stat->flag    374                         mount_crypt_stat->flags |=
375                                 ECRYPTFS_XATTR    375                                 ECRYPTFS_XATTR_METADATA_ENABLED;
376                         break;                    376                         break;
377                 case ecryptfs_opt_encrypted_vi    377                 case ecryptfs_opt_encrypted_view:
378                         mount_crypt_stat->flag    378                         mount_crypt_stat->flags |=
379                                 ECRYPTFS_XATTR    379                                 ECRYPTFS_XATTR_METADATA_ENABLED;
380                         mount_crypt_stat->flag    380                         mount_crypt_stat->flags |=
381                                 ECRYPTFS_ENCRY    381                                 ECRYPTFS_ENCRYPTED_VIEW_ENABLED;
382                         break;                    382                         break;
383                 case ecryptfs_opt_err:            383                 case ecryptfs_opt_err:
384                 default:                          384                 default:
385                         ecryptfs_printk(KERN_W    385                         ecryptfs_printk(KERN_WARNING,
386                                         "eCryp    386                                         "eCryptfs: unrecognized option '%s'\n",
387                                         p);       387                                         p);
388                 }                                 388                 }
389         }                                         389         }
390         if (!sig_set) {                           390         if (!sig_set) {
391                 rc = -EINVAL;                     391                 rc = -EINVAL;
392                 ecryptfs_printk(KERN_ERR, "You    392                 ecryptfs_printk(KERN_ERR, "You must supply at least one valid "
393                                 "auth tok sign    393                                 "auth tok signature as a mount "
394                                 "parameter; se    394                                 "parameter; see the eCryptfs README\n");
395                 goto out;                         395                 goto out;
396         }                                         396         }
397         if (!cipher_name_set) {                   397         if (!cipher_name_set) {
398                 cipher_name_len = strlen(ECRYP    398                 cipher_name_len = strlen(ECRYPTFS_DEFAULT_CIPHER);
399                 if (unlikely(cipher_name_len      399                 if (unlikely(cipher_name_len
400                              >= ECRYPTFS_MAX_C    400                              >= ECRYPTFS_MAX_CIPHER_NAME_SIZE)) {
401                         rc = -EINVAL;             401                         rc = -EINVAL;
402                         BUG();                    402                         BUG();
403                         goto out;                 403                         goto out;
404                 }                                 404                 }
405                 memcpy(mount_crypt_stat->globa    405                 memcpy(mount_crypt_stat->global_default_cipher_name,
406                        ECRYPTFS_DEFAULT_CIPHER    406                        ECRYPTFS_DEFAULT_CIPHER, cipher_name_len);
407                 mount_crypt_stat->global_defau    407                 mount_crypt_stat->global_default_cipher_name[cipher_name_len]
408                     = '\0';                       408                     = '\0';
409         }                                         409         }
410         if (!cipher_key_bytes_set) {              410         if (!cipher_key_bytes_set) {
411                 mount_crypt_stat->global_defau    411                 mount_crypt_stat->global_default_cipher_key_size = 0;
412         }                                         412         }
413         mutex_lock(&key_tfm_list_mutex);          413         mutex_lock(&key_tfm_list_mutex);
414         if (!ecryptfs_tfm_exists(mount_crypt_s    414         if (!ecryptfs_tfm_exists(mount_crypt_stat->global_default_cipher_name,
415                                  NULL))           415                                  NULL))
416                 rc = ecryptfs_add_new_key_tfm(    416                 rc = ecryptfs_add_new_key_tfm(
417                         NULL, mount_crypt_stat    417                         NULL, mount_crypt_stat->global_default_cipher_name,
418                         mount_crypt_stat->glob    418                         mount_crypt_stat->global_default_cipher_key_size);
419         mutex_unlock(&key_tfm_list_mutex);        419         mutex_unlock(&key_tfm_list_mutex);
420         if (rc) {                                 420         if (rc) {
421                 printk(KERN_ERR "Error attempt    421                 printk(KERN_ERR "Error attempting to initialize cipher with "
422                        "name = [%s] and key si    422                        "name = [%s] and key size = [%td]; rc = [%d]\n",
423                        mount_crypt_stat->globa    423                        mount_crypt_stat->global_default_cipher_name,
424                        mount_crypt_stat->globa    424                        mount_crypt_stat->global_default_cipher_key_size, rc);
425                 rc = -EINVAL;                     425                 rc = -EINVAL;
426                 goto out;                         426                 goto out;
427         }                                         427         }
428         rc = ecryptfs_init_global_auth_toks(mo    428         rc = ecryptfs_init_global_auth_toks(mount_crypt_stat);
429         if (rc) {                                 429         if (rc) {
430                 printk(KERN_WARNING "One or mo    430                 printk(KERN_WARNING "One or more global auth toks could not "
431                        "properly register; rc     431                        "properly register; rc = [%d]\n", rc);
432         }                                         432         }
433         rc = 0;                                   433         rc = 0;
434 out:                                              434 out:
435         return rc;                                435         return rc;
436 }                                                 436 }
437                                                   437 
438 struct kmem_cache *ecryptfs_sb_info_cache;        438 struct kmem_cache *ecryptfs_sb_info_cache;
439                                                   439 
440 /**                                               440 /**
441  * ecryptfs_fill_super                            441  * ecryptfs_fill_super
442  * @sb: The ecryptfs super block                  442  * @sb: The ecryptfs super block
443  * @raw_data: The options passed to mount         443  * @raw_data: The options passed to mount
444  * @silent: Not used but required by function     444  * @silent: Not used but required by function prototype
445  *                                                445  *
446  * Sets up what we can of the sb, rest is done    446  * Sets up what we can of the sb, rest is done in ecryptfs_read_super
447  *                                                447  *
448  * Returns zero on success; non-zero otherwise    448  * Returns zero on success; non-zero otherwise
449  */                                               449  */
450 static int                                        450 static int
451 ecryptfs_fill_super(struct super_block *sb, vo    451 ecryptfs_fill_super(struct super_block *sb, void *raw_data, int silent)
452 {                                                 452 {
453         int rc = 0;                               453         int rc = 0;
454                                                   454 
455         /* Released in ecryptfs_put_super() */    455         /* Released in ecryptfs_put_super() */
456         ecryptfs_set_superblock_private(sb,       456         ecryptfs_set_superblock_private(sb,
457                                         kmem_c    457                                         kmem_cache_zalloc(ecryptfs_sb_info_cache,
458                                                   458                                                          GFP_KERNEL));
459         if (!ecryptfs_superblock_to_private(sb    459         if (!ecryptfs_superblock_to_private(sb)) {
460                 ecryptfs_printk(KERN_WARNING,     460                 ecryptfs_printk(KERN_WARNING, "Out of memory\n");
461                 rc = -ENOMEM;                     461                 rc = -ENOMEM;
462                 goto out;                         462                 goto out;
463         }                                         463         }
464         sb->s_op = &ecryptfs_sops;                464         sb->s_op = &ecryptfs_sops;
465         /* Released through deactivate_super(s    465         /* Released through deactivate_super(sb) from get_sb_nodev */
466         sb->s_root = d_alloc(NULL, &(const str    466         sb->s_root = d_alloc(NULL, &(const struct qstr) {
467                              .hash = 0,.name =    467                              .hash = 0,.name = "/",.len = 1});
468         if (!sb->s_root) {                        468         if (!sb->s_root) {
469                 ecryptfs_printk(KERN_ERR, "d_a    469                 ecryptfs_printk(KERN_ERR, "d_alloc failed\n");
470                 rc = -ENOMEM;                     470                 rc = -ENOMEM;
471                 goto out;                         471                 goto out;
472         }                                         472         }
473         sb->s_root->d_op = &ecryptfs_dops;        473         sb->s_root->d_op = &ecryptfs_dops;
474         sb->s_root->d_sb = sb;                    474         sb->s_root->d_sb = sb;
475         sb->s_root->d_parent = sb->s_root;        475         sb->s_root->d_parent = sb->s_root;
476         /* Released in d_release when dput(sb-    476         /* Released in d_release when dput(sb->s_root) is called */
477         /* through deactivate_super(sb) from g    477         /* through deactivate_super(sb) from get_sb_nodev() */
478         ecryptfs_set_dentry_private(sb->s_root    478         ecryptfs_set_dentry_private(sb->s_root,
479                                     kmem_cache    479                                     kmem_cache_zalloc(ecryptfs_dentry_info_cache,
480                                                   480                                                      GFP_KERNEL));
481         if (!ecryptfs_dentry_to_private(sb->s_    481         if (!ecryptfs_dentry_to_private(sb->s_root)) {
482                 ecryptfs_printk(KERN_ERR,         482                 ecryptfs_printk(KERN_ERR,
483                                 "dentry_info_c    483                                 "dentry_info_cache alloc failed\n");
484                 rc = -ENOMEM;                     484                 rc = -ENOMEM;
485                 goto out;                         485                 goto out;
486         }                                         486         }
487         rc = 0;                                   487         rc = 0;
488 out:                                              488 out:
489         /* Should be able to rely on deactivat    489         /* Should be able to rely on deactivate_super called from
490          * get_sb_nodev */                        490          * get_sb_nodev */
491         return rc;                                491         return rc;
492 }                                                 492 }
493                                                   493 
494 /**                                               494 /**
495  * ecryptfs_read_super                            495  * ecryptfs_read_super
496  * @sb: The ecryptfs super block                  496  * @sb: The ecryptfs super block
497  * @dev_name: The path to mount over              497  * @dev_name: The path to mount over
498  *                                                498  *
499  * Read the super block of the lower filesyste    499  * Read the super block of the lower filesystem, and use
500  * ecryptfs_interpose to create our initial in    500  * ecryptfs_interpose to create our initial inode and super block
501  * struct.                                        501  * struct.
502  */                                               502  */
503 static int ecryptfs_read_super(struct super_bl    503 static int ecryptfs_read_super(struct super_block *sb, const char *dev_name)
504 {                                                 504 {
505         int rc;                                   505         int rc;
506         struct nameidata nd;                      506         struct nameidata nd;
507         struct dentry *lower_root;                507         struct dentry *lower_root;
508         struct vfsmount *lower_mnt;               508         struct vfsmount *lower_mnt;
509                                                   509 
510         memset(&nd, 0, sizeof(struct nameidata    510         memset(&nd, 0, sizeof(struct nameidata));
511         rc = path_lookup(dev_name, LOOKUP_FOLL    511         rc = path_lookup(dev_name, LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &nd);
512         if (rc) {                                 512         if (rc) {
513                 ecryptfs_printk(KERN_WARNING,     513                 ecryptfs_printk(KERN_WARNING, "path_lookup() failed\n");
514                 goto out;                         514                 goto out;
515         }                                         515         }
516         lower_root = nd.path.dentry;              516         lower_root = nd.path.dentry;
517         lower_mnt = nd.path.mnt;                  517         lower_mnt = nd.path.mnt;
518         ecryptfs_set_superblock_lower(sb, lowe    518         ecryptfs_set_superblock_lower(sb, lower_root->d_sb);
519         sb->s_maxbytes = lower_root->d_sb->s_m    519         sb->s_maxbytes = lower_root->d_sb->s_maxbytes;
520         sb->s_blocksize = lower_root->d_sb->s_    520         sb->s_blocksize = lower_root->d_sb->s_blocksize;
521         ecryptfs_set_dentry_lower(sb->s_root,     521         ecryptfs_set_dentry_lower(sb->s_root, lower_root);
522         ecryptfs_set_dentry_lower_mnt(sb->s_ro    522         ecryptfs_set_dentry_lower_mnt(sb->s_root, lower_mnt);
523         rc = ecryptfs_interpose(lower_root, sb    523         rc = ecryptfs_interpose(lower_root, sb->s_root, sb, 0);
524         if (rc)                                   524         if (rc)
525                 goto out_free;                    525                 goto out_free;
526         rc = 0;                                   526         rc = 0;
527         goto out;                                 527         goto out;
528 out_free:                                         528 out_free:
529         path_put(&nd.path);                       529         path_put(&nd.path);
530 out:                                              530 out:
531         return rc;                                531         return rc;
532 }                                                 532 }
533                                                   533 
534 /**                                               534 /**
535  * ecryptfs_get_sb                                535  * ecryptfs_get_sb
536  * @fs_type                                       536  * @fs_type
537  * @flags                                         537  * @flags
538  * @dev_name: The path to mount over              538  * @dev_name: The path to mount over
539  * @raw_data: The options passed into the kern    539  * @raw_data: The options passed into the kernel
540  *                                                540  *
541  * The whole ecryptfs_get_sb process is broken    541  * The whole ecryptfs_get_sb process is broken into 4 functions:
542  * ecryptfs_parse_options(): handle options pa    542  * ecryptfs_parse_options(): handle options passed to ecryptfs, if any
543  * ecryptfs_fill_super(): used by get_sb_nodev    543  * ecryptfs_fill_super(): used by get_sb_nodev, fills out the super_block
544  *                        with as much informa    544  *                        with as much information as it can before needing
545  *                        the lower filesystem    545  *                        the lower filesystem.
546  * ecryptfs_read_super(): this accesses the lo    546  * ecryptfs_read_super(): this accesses the lower filesystem and uses
547  *                        ecryptfs_interpolate    547  *                        ecryptfs_interpolate to perform most of the linking
548  * ecryptfs_interpolate(): links the lower fil    548  * ecryptfs_interpolate(): links the lower filesystem into ecryptfs
549  */                                               549  */
550 static int ecryptfs_get_sb(struct file_system_    550 static int ecryptfs_get_sb(struct file_system_type *fs_type, int flags,
551                         const char *dev_name,     551                         const char *dev_name, void *raw_data,
552                         struct vfsmount *mnt)     552                         struct vfsmount *mnt)
553 {                                                 553 {
554         int rc;                                   554         int rc;
555         struct super_block *sb;                   555         struct super_block *sb;
556                                                   556 
557         rc = get_sb_nodev(fs_type, flags, raw_    557         rc = get_sb_nodev(fs_type, flags, raw_data, ecryptfs_fill_super, mnt);
558         if (rc < 0) {                             558         if (rc < 0) {
559                 printk(KERN_ERR "Getting sb fa    559                 printk(KERN_ERR "Getting sb failed; rc = [%d]\n", rc);
560                 goto out;                         560                 goto out;
561         }                                         561         }
562         sb = mnt->mnt_sb;                         562         sb = mnt->mnt_sb;
563         rc = ecryptfs_parse_options(sb, raw_da    563         rc = ecryptfs_parse_options(sb, raw_data);
564         if (rc) {                                 564         if (rc) {
565                 printk(KERN_ERR "Error parsing    565                 printk(KERN_ERR "Error parsing options; rc = [%d]\n", rc);
566                 goto out_abort;                   566                 goto out_abort;
567         }                                         567         }
568         rc = ecryptfs_read_super(sb, dev_name)    568         rc = ecryptfs_read_super(sb, dev_name);
569         if (rc) {                                 569         if (rc) {
570                 printk(KERN_ERR "Reading sb fa    570                 printk(KERN_ERR "Reading sb failed; rc = [%d]\n", rc);
571                 goto out_abort;                   571                 goto out_abort;
572         }                                         572         }
573         goto out;                                 573         goto out;
574 out_abort:                                        574 out_abort:
575         dput(sb->s_root);                         575         dput(sb->s_root);
576         up_write(&sb->s_umount);                  576         up_write(&sb->s_umount);
577         deactivate_super(sb);                     577         deactivate_super(sb);
578 out:                                              578 out:
579         return rc;                                579         return rc;
580 }                                                 580 }
581                                                   581 
582 /**                                               582 /**
583  * ecryptfs_kill_block_super                      583  * ecryptfs_kill_block_super
584  * @sb: The ecryptfs super block                  584  * @sb: The ecryptfs super block
585  *                                                585  *
586  * Used to bring the superblock down and free     586  * Used to bring the superblock down and free the private data.
587  * Private data is free'd in ecryptfs_put_supe    587  * Private data is free'd in ecryptfs_put_super()
588  */                                               588  */
589 static void ecryptfs_kill_block_super(struct s    589 static void ecryptfs_kill_block_super(struct super_block *sb)
590 {                                                 590 {
591         generic_shutdown_super(sb);               591         generic_shutdown_super(sb);
592 }                                                 592 }
593                                                   593 
594 static struct file_system_type ecryptfs_fs_typ    594 static struct file_system_type ecryptfs_fs_type = {
595         .owner = THIS_MODULE,                     595         .owner = THIS_MODULE,
596         .name = "ecryptfs",                       596         .name = "ecryptfs",
597         .get_sb = ecryptfs_get_sb,                597         .get_sb = ecryptfs_get_sb,
598         .kill_sb = ecryptfs_kill_block_super,     598         .kill_sb = ecryptfs_kill_block_super,
599         .fs_flags = 0                             599         .fs_flags = 0
600 };                                                600 };
601                                                   601 
602 /**                                               602 /**
603  * inode_info_init_once                           603  * inode_info_init_once
604  *                                                604  *
605  * Initializes the ecryptfs_inode_info_cache w    605  * Initializes the ecryptfs_inode_info_cache when it is created
606  */                                               606  */
607 static void                                       607 static void
608 inode_info_init_once(struct kmem_cache *cachep    608 inode_info_init_once(struct kmem_cache *cachep, void *vptr)
609 {                                                 609 {
610         struct ecryptfs_inode_info *ei = (stru    610         struct ecryptfs_inode_info *ei = (struct ecryptfs_inode_info *)vptr;
611                                                   611 
612         inode_init_once(&ei->vfs_inode);          612         inode_init_once(&ei->vfs_inode);
613 }                                                 613 }
614                                                   614 
615 static struct ecryptfs_cache_info {               615 static struct ecryptfs_cache_info {
616         struct kmem_cache **cache;                616         struct kmem_cache **cache;
617         const char *name;                         617         const char *name;
618         size_t size;                              618         size_t size;
619         void (*ctor)(struct kmem_cache *cache,    619         void (*ctor)(struct kmem_cache *cache, void *obj);
620 } ecryptfs_cache_infos[] = {                      620 } ecryptfs_cache_infos[] = {
621         {                                         621         {
622                 .cache = &ecryptfs_auth_tok_li    622                 .cache = &ecryptfs_auth_tok_list_item_cache,
623                 .name = "ecryptfs_auth_tok_lis    623                 .name = "ecryptfs_auth_tok_list_item",
624                 .size = sizeof(struct ecryptfs    624                 .size = sizeof(struct ecryptfs_auth_tok_list_item),
625         },                                        625         },
626         {                                         626         {
627                 .cache = &ecryptfs_file_info_c    627                 .cache = &ecryptfs_file_info_cache,
628                 .name = "ecryptfs_file_cache",    628                 .name = "ecryptfs_file_cache",
629                 .size = sizeof(struct ecryptfs    629                 .size = sizeof(struct ecryptfs_file_info),
630         },                                        630         },
631         {                                         631         {
632                 .cache = &ecryptfs_dentry_info    632                 .cache = &ecryptfs_dentry_info_cache,
633                 .name = "ecryptfs_dentry_info_    633                 .name = "ecryptfs_dentry_info_cache",
634                 .size = sizeof(struct ecryptfs    634                 .size = sizeof(struct ecryptfs_dentry_info),
635         },                                        635         },
636         {                                         636         {
637                 .cache = &ecryptfs_inode_info_    637                 .cache = &ecryptfs_inode_info_cache,
638                 .name = "ecryptfs_inode_cache"    638                 .name = "ecryptfs_inode_cache",
639                 .size = sizeof(struct ecryptfs    639                 .size = sizeof(struct ecryptfs_inode_info),
640                 .ctor = inode_info_init_once,     640                 .ctor = inode_info_init_once,
641         },                                        641         },
642         {                                         642         {
643                 .cache = &ecryptfs_sb_info_cac    643                 .cache = &ecryptfs_sb_info_cache,
644                 .name = "ecryptfs_sb_cache",      644                 .name = "ecryptfs_sb_cache",
645                 .size = sizeof(struct ecryptfs    645                 .size = sizeof(struct ecryptfs_sb_info),
646         },                                        646         },
647         {                                         647         {
648                 .cache = &ecryptfs_header_cach    648                 .cache = &ecryptfs_header_cache_1,
649                 .name = "ecryptfs_headers_1",     649                 .name = "ecryptfs_headers_1",
650                 .size = PAGE_CACHE_SIZE,          650                 .size = PAGE_CACHE_SIZE,
651         },                                        651         },
652         {                                         652         {
653                 .cache = &ecryptfs_header_cach    653                 .cache = &ecryptfs_header_cache_2,
654                 .name = "ecryptfs_headers_2",     654                 .name = "ecryptfs_headers_2",
655                 .size = PAGE_CACHE_SIZE,          655                 .size = PAGE_CACHE_SIZE,
656         },                                        656         },
657         {                                         657         {
658                 .cache = &ecryptfs_xattr_cache    658                 .cache = &ecryptfs_xattr_cache,
659                 .name = "ecryptfs_xattr_cache"    659                 .name = "ecryptfs_xattr_cache",
660                 .size = PAGE_CACHE_SIZE,          660                 .size = PAGE_CACHE_SIZE,
661         },                                        661         },
662         {                                         662         {
663                 .cache = &ecryptfs_key_record_    663                 .cache = &ecryptfs_key_record_cache,
664                 .name = "ecryptfs_key_record_c    664                 .name = "ecryptfs_key_record_cache",
665                 .size = sizeof(struct ecryptfs    665                 .size = sizeof(struct ecryptfs_key_record),
666         },                                        666         },
667         {                                         667         {
668                 .cache = &ecryptfs_key_sig_cac    668                 .cache = &ecryptfs_key_sig_cache,
669                 .name = "ecryptfs_key_sig_cach    669                 .name = "ecryptfs_key_sig_cache",
670                 .size = sizeof(struct ecryptfs    670                 .size = sizeof(struct ecryptfs_key_sig),
671         },                                        671         },
672         {                                         672         {
673                 .cache = &ecryptfs_global_auth    673                 .cache = &ecryptfs_global_auth_tok_cache,
674                 .name = "ecryptfs_global_auth_    674                 .name = "ecryptfs_global_auth_tok_cache",
675                 .size = sizeof(struct ecryptfs    675                 .size = sizeof(struct ecryptfs_global_auth_tok),
676         },                                        676         },
677         {                                         677         {
678                 .cache = &ecryptfs_key_tfm_cac    678                 .cache = &ecryptfs_key_tfm_cache,
679                 .name = "ecryptfs_key_tfm_cach    679                 .name = "ecryptfs_key_tfm_cache",
680                 .size = sizeof(struct ecryptfs    680                 .size = sizeof(struct ecryptfs_key_tfm),
681         },                                        681         },
682 };                                                682 };
683                                                   683 
684 static void ecryptfs_free_kmem_caches(void)       684 static void ecryptfs_free_kmem_caches(void)
685 {                                                 685 {
686         int i;                                    686         int i;
687                                                   687 
688         for (i = 0; i < ARRAY_SIZE(ecryptfs_ca    688         for (i = 0; i < ARRAY_SIZE(ecryptfs_cache_infos); i++) {
689                 struct ecryptfs_cache_info *in    689                 struct ecryptfs_cache_info *info;
690                                                   690 
691                 info = &ecryptfs_cache_infos[i    691                 info = &ecryptfs_cache_infos[i];
692                 if (*(info->cache))               692                 if (*(info->cache))
693                         kmem_cache_destroy(*(i    693                         kmem_cache_destroy(*(info->cache));
694         }                                         694         }
695 }                                                 695 }
696                                                   696 
697 /**                                               697 /**
698  * ecryptfs_init_kmem_caches                      698  * ecryptfs_init_kmem_caches
699  *                                                699  *
700  * Returns zero on success; non-zero otherwise    700  * Returns zero on success; non-zero otherwise
701  */                                               701  */
702 static int ecryptfs_init_kmem_caches(void)        702 static int ecryptfs_init_kmem_caches(void)
703 {                                                 703 {
704         int i;                                    704         int i;
705                                                   705 
706         for (i = 0; i < ARRAY_SIZE(ecryptfs_ca    706         for (i = 0; i < ARRAY_SIZE(ecryptfs_cache_infos); i++) {
707                 struct ecryptfs_cache_info *in    707                 struct ecryptfs_cache_info *info;
708                                                   708 
709                 info = &ecryptfs_cache_infos[i    709                 info = &ecryptfs_cache_infos[i];
710                 *(info->cache) = kmem_cache_cr    710                 *(info->cache) = kmem_cache_create(info->name, info->size,
711                                 0, SLAB_HWCACH    711                                 0, SLAB_HWCACHE_ALIGN, info->ctor);
712                 if (!*(info->cache)) {            712                 if (!*(info->cache)) {
713                         ecryptfs_free_kmem_cac    713                         ecryptfs_free_kmem_caches();
714                         ecryptfs_printk(KERN_W    714                         ecryptfs_printk(KERN_WARNING, "%s: "
715                                         "kmem_    715                                         "kmem_cache_create failed\n",
716                                         info->    716                                         info->name);
717                         return -ENOMEM;           717                         return -ENOMEM;
718                 }                                 718                 }
719         }                                         719         }
720         return 0;                                 720         return 0;
721 }                                                 721 }
722                                                   722 
723 static struct kobject *ecryptfs_kobj;             723 static struct kobject *ecryptfs_kobj;
724                                                   724 
725 static ssize_t version_show(struct kobject *ko    725 static ssize_t version_show(struct kobject *kobj,
726                             struct kobj_attrib    726                             struct kobj_attribute *attr, char *buff)
727 {                                                 727 {
728         return snprintf(buff, PAGE_SIZE, "%d\n    728         return snprintf(buff, PAGE_SIZE, "%d\n", ECRYPTFS_VERSIONING_MASK);
729 }                                                 729 }
730                                                   730 
731 static struct kobj_attribute version_attr = __    731 static struct kobj_attribute version_attr = __ATTR_RO(version);
732                                                   732 
733 static struct attribute *attributes[] = {         733 static struct attribute *attributes[] = {
734         &version_attr.attr,                       734         &version_attr.attr,
735         NULL,                                     735         NULL,
736 };                                                736 };
737                                                   737 
738 static struct attribute_group attr_group = {      738 static struct attribute_group attr_group = {
739         .attrs = attributes,                      739         .attrs = attributes,
740 };                                                740 };
741                                                   741 
742 static int do_sysfs_registration(void)            742 static int do_sysfs_registration(void)
743 {                                                 743 {
744         int rc;                                   744         int rc;
745                                                   745 
746         ecryptfs_kobj = kobject_create_and_add    746         ecryptfs_kobj = kobject_create_and_add("ecryptfs", fs_kobj);
747         if (!ecryptfs_kobj) {                     747         if (!ecryptfs_kobj) {
748                 printk(KERN_ERR "Unable to cre    748                 printk(KERN_ERR "Unable to create ecryptfs kset\n");
749                 rc = -ENOMEM;                     749                 rc = -ENOMEM;
750                 goto out;                         750                 goto out;
751         }                                         751         }
752         rc = sysfs_create_group(ecryptfs_kobj,    752         rc = sysfs_create_group(ecryptfs_kobj, &attr_group);
753         if (rc) {                                 753         if (rc) {
754                 printk(KERN_ERR                   754                 printk(KERN_ERR
755                        "Unable to create ecryp    755                        "Unable to create ecryptfs version attributes\n");
756                 kobject_put(ecryptfs_kobj);       756                 kobject_put(ecryptfs_kobj);
757         }                                         757         }
758 out:                                              758 out:
759         return rc;                                759         return rc;
760 }                                                 760 }
761                                                   761 
762 static void do_sysfs_unregistration(void)         762 static void do_sysfs_unregistration(void)
763 {                                                 763 {
764         sysfs_remove_group(ecryptfs_kobj, &att    764         sysfs_remove_group(ecryptfs_kobj, &attr_group);
765         kobject_put(ecryptfs_kobj);               765         kobject_put(ecryptfs_kobj);
766 }                                                 766 }
767                                                   767 
768 static int __init ecryptfs_init(void)             768 static int __init ecryptfs_init(void)
769 {                                                 769 {
770         int rc;                                   770         int rc;
771                                                   771 
772         if (ECRYPTFS_DEFAULT_EXTENT_SIZE > PAG    772         if (ECRYPTFS_DEFAULT_EXTENT_SIZE > PAGE_CACHE_SIZE) {
773                 rc = -EINVAL;                     773                 rc = -EINVAL;
774                 ecryptfs_printk(KERN_ERR, "The    774                 ecryptfs_printk(KERN_ERR, "The eCryptfs extent size is "
775                                 "larger than t    775                                 "larger than the host's page size, and so "
776                                 "eCryptfs cann    776                                 "eCryptfs cannot run on this system. The "
777                                 "default eCryp    777                                 "default eCryptfs extent size is [%d] bytes; "
778                                 "the page size    778                                 "the page size is [%d] bytes.\n",
779                                 ECRYPTFS_DEFAU    779                                 ECRYPTFS_DEFAULT_EXTENT_SIZE, PAGE_CACHE_SIZE);
780                 goto out;                         780                 goto out;
781         }                                         781         }
782         rc = ecryptfs_init_kmem_caches();         782         rc = ecryptfs_init_kmem_caches();
783         if (rc) {                                 783         if (rc) {
784                 printk(KERN_ERR                   784                 printk(KERN_ERR
785                        "Failed to allocate one    785                        "Failed to allocate one or more kmem_cache objects\n");
786                 goto out;                         786                 goto out;
787         }                                         787         }
788         rc = register_filesystem(&ecryptfs_fs_    788         rc = register_filesystem(&ecryptfs_fs_type);
789         if (rc) {                                 789         if (rc) {
790                 printk(KERN_ERR "Failed to reg    790                 printk(KERN_ERR "Failed to register filesystem\n");
791                 goto out_free_kmem_caches;        791                 goto out_free_kmem_caches;
792         }                                         792         }
793         rc = do_sysfs_registration();             793         rc = do_sysfs_registration();
794         if (rc) {                                 794         if (rc) {
795                 printk(KERN_ERR "sysfs registr    795                 printk(KERN_ERR "sysfs registration failed\n");
796                 goto out_unregister_filesystem    796                 goto out_unregister_filesystem;
797         }                                         797         }
798         rc = ecryptfs_init_messaging(ecryptfs_    798         rc = ecryptfs_init_messaging(ecryptfs_transport);
799         if (rc) {                                 799         if (rc) {
800                 ecryptfs_printk(KERN_ERR, "Fai    800                 ecryptfs_printk(KERN_ERR, "Failure occured while attempting to "
801                                 "initialize th    801                                 "initialize the eCryptfs netlink socket\n");
802                 goto out_do_sysfs_unregistrati    802                 goto out_do_sysfs_unregistration;
803         }                                         803         }
804         rc = ecryptfs_init_crypto();              804         rc = ecryptfs_init_crypto();
805         if (rc) {                                 805         if (rc) {
806                 printk(KERN_ERR "Failure whils    806                 printk(KERN_ERR "Failure whilst attempting to init crypto; "
807                        "rc = [%d]\n", rc);        807                        "rc = [%d]\n", rc);
808                 goto out_release_messaging;       808                 goto out_release_messaging;
809         }                                         809         }
810         if (ecryptfs_verbosity > 0)               810         if (ecryptfs_verbosity > 0)
811                 printk(KERN_CRIT "eCryptfs ver    811                 printk(KERN_CRIT "eCryptfs verbosity set to %d. Secret values "
812                         "will be written to th    812                         "will be written to the syslog!\n", ecryptfs_verbosity);
813                                                   813 
814         goto out;                                 814         goto out;
815 out_release_messaging:                            815 out_release_messaging:
816         ecryptfs_release_messaging(ecryptfs_tr    816         ecryptfs_release_messaging(ecryptfs_transport);
817 out_do_sysfs_unregistration:                      817 out_do_sysfs_unregistration:
818         do_sysfs_unregistration();                818         do_sysfs_unregistration();
819 out_unregister_filesystem:                        819 out_unregister_filesystem:
820         unregister_filesystem(&ecryptfs_fs_typ    820         unregister_filesystem(&ecryptfs_fs_type);
821 out_free_kmem_caches:                             821 out_free_kmem_caches:
822         ecryptfs_free_kmem_caches();              822         ecryptfs_free_kmem_caches();
823 out:                                              823 out:
824         return rc;                                824         return rc;
825 }                                                 825 }
826                                                   826 
827 static void __exit ecryptfs_exit(void)            827 static void __exit ecryptfs_exit(void)
828 {                                                 828 {
829         int rc;                                   829         int rc;
830                                                   830 
831         rc = ecryptfs_destroy_crypto();           831         rc = ecryptfs_destroy_crypto();
832         if (rc)                                   832         if (rc)
833                 printk(KERN_ERR "Failure whils    833                 printk(KERN_ERR "Failure whilst attempting to destroy crypto; "
834                        "rc = [%d]\n", rc);        834                        "rc = [%d]\n", rc);
835         ecryptfs_release_messaging(ecryptfs_tr    835         ecryptfs_release_messaging(ecryptfs_transport);
836         do_sysfs_unregistration();                836         do_sysfs_unregistration();
837         unregister_filesystem(&ecryptfs_fs_typ    837         unregister_filesystem(&ecryptfs_fs_type);
838         ecryptfs_free_kmem_caches();              838         ecryptfs_free_kmem_caches();
839 }                                                 839 }
840                                                   840 
841 MODULE_AUTHOR("Michael A. Halcrow <mhalcrow@us    841 MODULE_AUTHOR("Michael A. Halcrow <mhalcrow@us.ibm.com>");
842 MODULE_DESCRIPTION("eCryptfs");                   842 MODULE_DESCRIPTION("eCryptfs");
843                                                   843 
844 MODULE_LICENSE("GPL");                            844 MODULE_LICENSE("GPL");
845                                                   845 
846 module_init(ecryptfs_init)                        846 module_init(ecryptfs_init)
847 module_exit(ecryptfs_exit)                        847 module_exit(ecryptfs_exit)
848                                                   848 
  This page was automatically generated by the LXR engine.