diff options
Diffstat (limited to 'fs/ecryptfs')
-rw-r--r-- | fs/ecryptfs/crypto.c | 30 | ||||
-rw-r--r-- | fs/ecryptfs/dentry.c | 9 | ||||
-rw-r--r-- | fs/ecryptfs/ecryptfs_kernel.h | 5 | ||||
-rw-r--r-- | fs/ecryptfs/file.c | 32 | ||||
-rw-r--r-- | fs/ecryptfs/inode.c | 54 | ||||
-rw-r--r-- | fs/ecryptfs/keystore.c | 71 | ||||
-rw-r--r-- | fs/ecryptfs/main.c | 185 | ||||
-rw-r--r-- | fs/ecryptfs/miscdev.c | 1 | ||||
-rw-r--r-- | fs/ecryptfs/mmap.c | 35 | ||||
-rw-r--r-- | fs/ecryptfs/super.c | 15 |
10 files changed, 237 insertions, 200 deletions
diff --git a/fs/ecryptfs/crypto.c b/fs/ecryptfs/crypto.c index cbadc1bee6e7..bfd8b680e648 100644 --- a/fs/ecryptfs/crypto.c +++ b/fs/ecryptfs/crypto.c | |||
@@ -348,7 +348,7 @@ static int encrypt_scatterlist(struct ecryptfs_crypt_stat *crypt_stat, | |||
348 | BUG_ON(!crypt_stat || !crypt_stat->tfm | 348 | BUG_ON(!crypt_stat || !crypt_stat->tfm |
349 | || !(crypt_stat->flags & ECRYPTFS_STRUCT_INITIALIZED)); | 349 | || !(crypt_stat->flags & ECRYPTFS_STRUCT_INITIALIZED)); |
350 | if (unlikely(ecryptfs_verbosity > 0)) { | 350 | if (unlikely(ecryptfs_verbosity > 0)) { |
351 | ecryptfs_printk(KERN_DEBUG, "Key size [%d]; key:\n", | 351 | ecryptfs_printk(KERN_DEBUG, "Key size [%zd]; key:\n", |
352 | crypt_stat->key_size); | 352 | crypt_stat->key_size); |
353 | ecryptfs_dump_hex(crypt_stat->key, | 353 | ecryptfs_dump_hex(crypt_stat->key, |
354 | crypt_stat->key_size); | 354 | crypt_stat->key_size); |
@@ -413,10 +413,9 @@ static int ecryptfs_encrypt_extent(struct page *enc_extent_page, | |||
413 | rc = ecryptfs_derive_iv(extent_iv, crypt_stat, | 413 | rc = ecryptfs_derive_iv(extent_iv, crypt_stat, |
414 | (extent_base + extent_offset)); | 414 | (extent_base + extent_offset)); |
415 | if (rc) { | 415 | if (rc) { |
416 | ecryptfs_printk(KERN_ERR, "Error attempting to " | 416 | ecryptfs_printk(KERN_ERR, "Error attempting to derive IV for " |
417 | "derive IV for extent [0x%.16x]; " | 417 | "extent [0x%.16llx]; rc = [%d]\n", |
418 | "rc = [%d]\n", (extent_base + extent_offset), | 418 | (unsigned long long)(extent_base + extent_offset), rc); |
419 | rc); | ||
420 | goto out; | 419 | goto out; |
421 | } | 420 | } |
422 | if (unlikely(ecryptfs_verbosity > 0)) { | 421 | if (unlikely(ecryptfs_verbosity > 0)) { |
@@ -443,9 +442,9 @@ static int ecryptfs_encrypt_extent(struct page *enc_extent_page, | |||
443 | } | 442 | } |
444 | rc = 0; | 443 | rc = 0; |
445 | if (unlikely(ecryptfs_verbosity > 0)) { | 444 | if (unlikely(ecryptfs_verbosity > 0)) { |
446 | ecryptfs_printk(KERN_DEBUG, "Encrypt extent [0x%.16x]; " | 445 | ecryptfs_printk(KERN_DEBUG, "Encrypt extent [0x%.16llx]; " |
447 | "rc = [%d]\n", (extent_base + extent_offset), | 446 | "rc = [%d]\n", |
448 | rc); | 447 | (unsigned long long)(extent_base + extent_offset), rc); |
449 | ecryptfs_printk(KERN_DEBUG, "First 8 bytes after " | 448 | ecryptfs_printk(KERN_DEBUG, "First 8 bytes after " |
450 | "encryption:\n"); | 449 | "encryption:\n"); |
451 | ecryptfs_dump_hex((char *)(page_address(enc_extent_page)), 8); | 450 | ecryptfs_dump_hex((char *)(page_address(enc_extent_page)), 8); |
@@ -540,10 +539,9 @@ static int ecryptfs_decrypt_extent(struct page *page, | |||
540 | rc = ecryptfs_derive_iv(extent_iv, crypt_stat, | 539 | rc = ecryptfs_derive_iv(extent_iv, crypt_stat, |
541 | (extent_base + extent_offset)); | 540 | (extent_base + extent_offset)); |
542 | if (rc) { | 541 | if (rc) { |
543 | ecryptfs_printk(KERN_ERR, "Error attempting to " | 542 | ecryptfs_printk(KERN_ERR, "Error attempting to derive IV for " |
544 | "derive IV for extent [0x%.16x]; " | 543 | "extent [0x%.16llx]; rc = [%d]\n", |
545 | "rc = [%d]\n", (extent_base + extent_offset), | 544 | (unsigned long long)(extent_base + extent_offset), rc); |
546 | rc); | ||
547 | goto out; | 545 | goto out; |
548 | } | 546 | } |
549 | if (unlikely(ecryptfs_verbosity > 0)) { | 547 | if (unlikely(ecryptfs_verbosity > 0)) { |
@@ -571,9 +569,9 @@ static int ecryptfs_decrypt_extent(struct page *page, | |||
571 | } | 569 | } |
572 | rc = 0; | 570 | rc = 0; |
573 | if (unlikely(ecryptfs_verbosity > 0)) { | 571 | if (unlikely(ecryptfs_verbosity > 0)) { |
574 | ecryptfs_printk(KERN_DEBUG, "Decrypt extent [0x%.16x]; " | 572 | ecryptfs_printk(KERN_DEBUG, "Decrypt extent [0x%.16llx]; " |
575 | "rc = [%d]\n", (extent_base + extent_offset), | 573 | "rc = [%d]\n", |
576 | rc); | 574 | (unsigned long long)(extent_base + extent_offset), rc); |
577 | ecryptfs_printk(KERN_DEBUG, "First 8 bytes after " | 575 | ecryptfs_printk(KERN_DEBUG, "First 8 bytes after " |
578 | "decryption:\n"); | 576 | "decryption:\n"); |
579 | ecryptfs_dump_hex((char *)(page_address(page) | 577 | ecryptfs_dump_hex((char *)(page_address(page) |
@@ -780,7 +778,7 @@ int ecryptfs_init_crypt_ctx(struct ecryptfs_crypt_stat *crypt_stat) | |||
780 | } | 778 | } |
781 | ecryptfs_printk(KERN_DEBUG, | 779 | ecryptfs_printk(KERN_DEBUG, |
782 | "Initializing cipher [%s]; strlen = [%d]; " | 780 | "Initializing cipher [%s]; strlen = [%d]; " |
783 | "key_size_bits = [%d]\n", | 781 | "key_size_bits = [%zd]\n", |
784 | crypt_stat->cipher, (int)strlen(crypt_stat->cipher), | 782 | crypt_stat->cipher, (int)strlen(crypt_stat->cipher), |
785 | crypt_stat->key_size << 3); | 783 | crypt_stat->key_size << 3); |
786 | if (crypt_stat->tfm) { | 784 | if (crypt_stat->tfm) { |
diff --git a/fs/ecryptfs/dentry.c b/fs/ecryptfs/dentry.c index 906e803f7f79..6fc4f319b550 100644 --- a/fs/ecryptfs/dentry.c +++ b/fs/ecryptfs/dentry.c | |||
@@ -44,12 +44,17 @@ | |||
44 | */ | 44 | */ |
45 | static int ecryptfs_d_revalidate(struct dentry *dentry, struct nameidata *nd) | 45 | static int ecryptfs_d_revalidate(struct dentry *dentry, struct nameidata *nd) |
46 | { | 46 | { |
47 | struct dentry *lower_dentry = ecryptfs_dentry_to_lower(dentry); | 47 | struct dentry *lower_dentry; |
48 | struct vfsmount *lower_mnt = ecryptfs_dentry_to_lower_mnt(dentry); | 48 | struct vfsmount *lower_mnt; |
49 | struct dentry *dentry_save; | 49 | struct dentry *dentry_save; |
50 | struct vfsmount *vfsmount_save; | 50 | struct vfsmount *vfsmount_save; |
51 | int rc = 1; | 51 | int rc = 1; |
52 | 52 | ||
53 | if (nd->flags & LOOKUP_RCU) | ||
54 | return -ECHILD; | ||
55 | |||
56 | lower_dentry = ecryptfs_dentry_to_lower(dentry); | ||
57 | lower_mnt = ecryptfs_dentry_to_lower_mnt(dentry); | ||
53 | if (!lower_dentry->d_op || !lower_dentry->d_op->d_revalidate) | 58 | if (!lower_dentry->d_op || !lower_dentry->d_op->d_revalidate) |
54 | goto out; | 59 | goto out; |
55 | dentry_save = nd->path.dentry; | 60 | dentry_save = nd->path.dentry; |
diff --git a/fs/ecryptfs/ecryptfs_kernel.h b/fs/ecryptfs/ecryptfs_kernel.h index 0032a9f5a3a9..dbc84ed96336 100644 --- a/fs/ecryptfs/ecryptfs_kernel.h +++ b/fs/ecryptfs/ecryptfs_kernel.h | |||
@@ -192,7 +192,6 @@ ecryptfs_get_key_payload_data(struct key *key) | |||
192 | (((struct user_key_payload*)key->payload.data)->data); | 192 | (((struct user_key_payload*)key->payload.data)->data); |
193 | } | 193 | } |
194 | 194 | ||
195 | #define ECRYPTFS_SUPER_MAGIC 0xf15f | ||
196 | #define ECRYPTFS_MAX_KEYSET_SIZE 1024 | 195 | #define ECRYPTFS_MAX_KEYSET_SIZE 1024 |
197 | #define ECRYPTFS_MAX_CIPHER_NAME_SIZE 32 | 196 | #define ECRYPTFS_MAX_CIPHER_NAME_SIZE 32 |
198 | #define ECRYPTFS_MAX_NUM_ENC_KEYS 64 | 197 | #define ECRYPTFS_MAX_NUM_ENC_KEYS 64 |
@@ -377,6 +376,7 @@ struct ecryptfs_mount_crypt_stat { | |||
377 | #define ECRYPTFS_GLOBAL_ENCRYPT_FILENAMES 0x00000010 | 376 | #define ECRYPTFS_GLOBAL_ENCRYPT_FILENAMES 0x00000010 |
378 | #define ECRYPTFS_GLOBAL_ENCFN_USE_MOUNT_FNEK 0x00000020 | 377 | #define ECRYPTFS_GLOBAL_ENCFN_USE_MOUNT_FNEK 0x00000020 |
379 | #define ECRYPTFS_GLOBAL_ENCFN_USE_FEK 0x00000040 | 378 | #define ECRYPTFS_GLOBAL_ENCFN_USE_FEK 0x00000040 |
379 | #define ECRYPTFS_GLOBAL_MOUNT_AUTH_TOK_ONLY 0x00000080 | ||
380 | u32 flags; | 380 | u32 flags; |
381 | struct list_head global_auth_tok_list; | 381 | struct list_head global_auth_tok_list; |
382 | struct mutex global_auth_tok_list_mutex; | 382 | struct mutex global_auth_tok_list_mutex; |
@@ -477,7 +477,7 @@ ecryptfs_lower_header_size(struct ecryptfs_crypt_stat *crypt_stat) | |||
477 | static inline struct ecryptfs_file_info * | 477 | static inline struct ecryptfs_file_info * |
478 | ecryptfs_file_to_private(struct file *file) | 478 | ecryptfs_file_to_private(struct file *file) |
479 | { | 479 | { |
480 | return (struct ecryptfs_file_info *)file->private_data; | 480 | return file->private_data; |
481 | } | 481 | } |
482 | 482 | ||
483 | static inline void | 483 | static inline void |
@@ -583,6 +583,7 @@ ecryptfs_set_dentry_lower_mnt(struct dentry *dentry, struct vfsmount *lower_mnt) | |||
583 | 583 | ||
584 | #define ecryptfs_printk(type, fmt, arg...) \ | 584 | #define ecryptfs_printk(type, fmt, arg...) \ |
585 | __ecryptfs_printk(type "%s: " fmt, __func__, ## arg); | 585 | __ecryptfs_printk(type "%s: " fmt, __func__, ## arg); |
586 | __attribute__ ((format(printf, 1, 2))) | ||
586 | void __ecryptfs_printk(const char *fmt, ...); | 587 | void __ecryptfs_printk(const char *fmt, ...); |
587 | 588 | ||
588 | extern const struct file_operations ecryptfs_main_fops; | 589 | extern const struct file_operations ecryptfs_main_fops; |
diff --git a/fs/ecryptfs/file.c b/fs/ecryptfs/file.c index 622c95140802..81e10e6a9443 100644 --- a/fs/ecryptfs/file.c +++ b/fs/ecryptfs/file.c | |||
@@ -31,7 +31,6 @@ | |||
31 | #include <linux/security.h> | 31 | #include <linux/security.h> |
32 | #include <linux/compat.h> | 32 | #include <linux/compat.h> |
33 | #include <linux/fs_stack.h> | 33 | #include <linux/fs_stack.h> |
34 | #include <linux/smp_lock.h> | ||
35 | #include "ecryptfs_kernel.h" | 34 | #include "ecryptfs_kernel.h" |
36 | 35 | ||
37 | /** | 36 | /** |
@@ -48,7 +47,7 @@ static ssize_t ecryptfs_read_update_atime(struct kiocb *iocb, | |||
48 | const struct iovec *iov, | 47 | const struct iovec *iov, |
49 | unsigned long nr_segs, loff_t pos) | 48 | unsigned long nr_segs, loff_t pos) |
50 | { | 49 | { |
51 | int rc; | 50 | ssize_t rc; |
52 | struct dentry *lower_dentry; | 51 | struct dentry *lower_dentry; |
53 | struct vfsmount *lower_vfsmount; | 52 | struct vfsmount *lower_vfsmount; |
54 | struct file *file = iocb->ki_filp; | 53 | struct file *file = iocb->ki_filp; |
@@ -192,18 +191,16 @@ static int ecryptfs_open(struct inode *inode, struct file *file) | |||
192 | | ECRYPTFS_ENCRYPTED); | 191 | | ECRYPTFS_ENCRYPTED); |
193 | } | 192 | } |
194 | mutex_unlock(&crypt_stat->cs_mutex); | 193 | mutex_unlock(&crypt_stat->cs_mutex); |
195 | if (!ecryptfs_inode_to_private(inode)->lower_file) { | 194 | rc = ecryptfs_init_persistent_file(ecryptfs_dentry); |
196 | rc = ecryptfs_init_persistent_file(ecryptfs_dentry); | 195 | if (rc) { |
197 | if (rc) { | 196 | printk(KERN_ERR "%s: Error attempting to initialize " |
198 | printk(KERN_ERR "%s: Error attempting to initialize " | 197 | "the persistent file for the dentry with name " |
199 | "the persistent file for the dentry with name " | 198 | "[%s]; rc = [%d]\n", __func__, |
200 | "[%s]; rc = [%d]\n", __func__, | 199 | ecryptfs_dentry->d_name.name, rc); |
201 | ecryptfs_dentry->d_name.name, rc); | 200 | goto out_free; |
202 | goto out_free; | ||
203 | } | ||
204 | } | 201 | } |
205 | if ((ecryptfs_inode_to_private(inode)->lower_file->f_flags & O_RDONLY) | 202 | if ((ecryptfs_inode_to_private(inode)->lower_file->f_flags & O_ACCMODE) |
206 | && !(file->f_flags & O_RDONLY)) { | 203 | == O_RDONLY && (file->f_flags & O_ACCMODE) != O_RDONLY) { |
207 | rc = -EPERM; | 204 | rc = -EPERM; |
208 | printk(KERN_WARNING "%s: Lower persistent file is RO; eCryptfs " | 205 | printk(KERN_WARNING "%s: Lower persistent file is RO; eCryptfs " |
209 | "file must hence be opened RO\n", __func__); | 206 | "file must hence be opened RO\n", __func__); |
@@ -244,9 +241,9 @@ static int ecryptfs_open(struct inode *inode, struct file *file) | |||
244 | } | 241 | } |
245 | } | 242 | } |
246 | mutex_unlock(&crypt_stat->cs_mutex); | 243 | mutex_unlock(&crypt_stat->cs_mutex); |
247 | ecryptfs_printk(KERN_DEBUG, "inode w/ addr = [0x%p], i_ino = [0x%.16x] " | 244 | ecryptfs_printk(KERN_DEBUG, "inode w/ addr = [0x%p], i_ino = " |
248 | "size: [0x%.16x]\n", inode, inode->i_ino, | 245 | "[0x%.16lx] size: [0x%.16llx]\n", inode, inode->i_ino, |
249 | i_size_read(inode)); | 246 | (unsigned long long)i_size_read(inode)); |
250 | goto out; | 247 | goto out; |
251 | out_free: | 248 | out_free: |
252 | kmem_cache_free(ecryptfs_file_info_cache, | 249 | kmem_cache_free(ecryptfs_file_info_cache, |
@@ -284,11 +281,9 @@ static int ecryptfs_fasync(int fd, struct file *file, int flag) | |||
284 | int rc = 0; | 281 | int rc = 0; |
285 | struct file *lower_file = NULL; | 282 | struct file *lower_file = NULL; |
286 | 283 | ||
287 | lock_kernel(); | ||
288 | lower_file = ecryptfs_file_to_lower(file); | 284 | lower_file = ecryptfs_file_to_lower(file); |
289 | if (lower_file->f_op && lower_file->f_op->fasync) | 285 | if (lower_file->f_op && lower_file->f_op->fasync) |
290 | rc = lower_file->f_op->fasync(fd, lower_file, flag); | 286 | rc = lower_file->f_op->fasync(fd, lower_file, flag); |
291 | unlock_kernel(); | ||
292 | return rc; | 287 | return rc; |
293 | } | 288 | } |
294 | 289 | ||
@@ -332,6 +327,7 @@ const struct file_operations ecryptfs_dir_fops = { | |||
332 | .fsync = ecryptfs_fsync, | 327 | .fsync = ecryptfs_fsync, |
333 | .fasync = ecryptfs_fasync, | 328 | .fasync = ecryptfs_fasync, |
334 | .splice_read = generic_file_splice_read, | 329 | .splice_read = generic_file_splice_read, |
330 | .llseek = default_llseek, | ||
335 | }; | 331 | }; |
336 | 332 | ||
337 | const struct file_operations ecryptfs_main_fops = { | 333 | const struct file_operations ecryptfs_main_fops = { |
diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c index 3fbc94203380..bd33f87a1907 100644 --- a/fs/ecryptfs/inode.c +++ b/fs/ecryptfs/inode.c | |||
@@ -32,6 +32,7 @@ | |||
32 | #include <linux/crypto.h> | 32 | #include <linux/crypto.h> |
33 | #include <linux/fs_stack.h> | 33 | #include <linux/fs_stack.h> |
34 | #include <linux/slab.h> | 34 | #include <linux/slab.h> |
35 | #include <linux/xattr.h> | ||
35 | #include <asm/unaligned.h> | 36 | #include <asm/unaligned.h> |
36 | #include "ecryptfs_kernel.h" | 37 | #include "ecryptfs_kernel.h" |
37 | 38 | ||
@@ -70,15 +71,19 @@ ecryptfs_create_underlying_file(struct inode *lower_dir_inode, | |||
70 | struct vfsmount *lower_mnt = ecryptfs_dentry_to_lower_mnt(dentry); | 71 | struct vfsmount *lower_mnt = ecryptfs_dentry_to_lower_mnt(dentry); |
71 | struct dentry *dentry_save; | 72 | struct dentry *dentry_save; |
72 | struct vfsmount *vfsmount_save; | 73 | struct vfsmount *vfsmount_save; |
74 | unsigned int flags_save; | ||
73 | int rc; | 75 | int rc; |
74 | 76 | ||
75 | dentry_save = nd->path.dentry; | 77 | dentry_save = nd->path.dentry; |
76 | vfsmount_save = nd->path.mnt; | 78 | vfsmount_save = nd->path.mnt; |
79 | flags_save = nd->flags; | ||
77 | nd->path.dentry = lower_dentry; | 80 | nd->path.dentry = lower_dentry; |
78 | nd->path.mnt = lower_mnt; | 81 | nd->path.mnt = lower_mnt; |
82 | nd->flags &= ~LOOKUP_OPEN; | ||
79 | rc = vfs_create(lower_dir_inode, lower_dentry, mode, nd); | 83 | rc = vfs_create(lower_dir_inode, lower_dentry, mode, nd); |
80 | nd->path.dentry = dentry_save; | 84 | nd->path.dentry = dentry_save; |
81 | nd->path.mnt = vfsmount_save; | 85 | nd->path.mnt = vfsmount_save; |
86 | nd->flags = flags_save; | ||
82 | return rc; | 87 | return rc; |
83 | } | 88 | } |
84 | 89 | ||
@@ -180,15 +185,13 @@ static int ecryptfs_initialize_file(struct dentry *ecryptfs_dentry) | |||
180 | "context; rc = [%d]\n", rc); | 185 | "context; rc = [%d]\n", rc); |
181 | goto out; | 186 | goto out; |
182 | } | 187 | } |
183 | if (!ecryptfs_inode_to_private(ecryptfs_dentry->d_inode)->lower_file) { | 188 | rc = ecryptfs_init_persistent_file(ecryptfs_dentry); |
184 | rc = ecryptfs_init_persistent_file(ecryptfs_dentry); | 189 | if (rc) { |
185 | if (rc) { | 190 | printk(KERN_ERR "%s: Error attempting to initialize " |
186 | printk(KERN_ERR "%s: Error attempting to initialize " | 191 | "the persistent file for the dentry with name " |
187 | "the persistent file for the dentry with name " | 192 | "[%s]; rc = [%d]\n", __func__, |
188 | "[%s]; rc = [%d]\n", __func__, | 193 | ecryptfs_dentry->d_name.name, rc); |
189 | ecryptfs_dentry->d_name.name, rc); | 194 | goto out; |
190 | goto out; | ||
191 | } | ||
192 | } | 195 | } |
193 | rc = ecryptfs_write_metadata(ecryptfs_dentry); | 196 | rc = ecryptfs_write_metadata(ecryptfs_dentry); |
194 | if (rc) { | 197 | if (rc) { |
@@ -255,7 +258,7 @@ int ecryptfs_lookup_and_interpose_lower(struct dentry *ecryptfs_dentry, | |||
255 | ecryptfs_dentry->d_parent)); | 258 | ecryptfs_dentry->d_parent)); |
256 | lower_inode = lower_dentry->d_inode; | 259 | lower_inode = lower_dentry->d_inode; |
257 | fsstack_copy_attr_atime(ecryptfs_dir_inode, lower_dir_dentry->d_inode); | 260 | fsstack_copy_attr_atime(ecryptfs_dir_inode, lower_dir_dentry->d_inode); |
258 | BUG_ON(!atomic_read(&lower_dentry->d_count)); | 261 | BUG_ON(!lower_dentry->d_count); |
259 | ecryptfs_set_dentry_private(ecryptfs_dentry, | 262 | ecryptfs_set_dentry_private(ecryptfs_dentry, |
260 | kmem_cache_alloc(ecryptfs_dentry_info_cache, | 263 | kmem_cache_alloc(ecryptfs_dentry_info_cache, |
261 | GFP_KERNEL)); | 264 | GFP_KERNEL)); |
@@ -297,15 +300,13 @@ int ecryptfs_lookup_and_interpose_lower(struct dentry *ecryptfs_dentry, | |||
297 | rc = -ENOMEM; | 300 | rc = -ENOMEM; |
298 | goto out; | 301 | goto out; |
299 | } | 302 | } |
300 | if (!ecryptfs_inode_to_private(ecryptfs_dentry->d_inode)->lower_file) { | 303 | rc = ecryptfs_init_persistent_file(ecryptfs_dentry); |
301 | rc = ecryptfs_init_persistent_file(ecryptfs_dentry); | 304 | if (rc) { |
302 | if (rc) { | 305 | printk(KERN_ERR "%s: Error attempting to initialize " |
303 | printk(KERN_ERR "%s: Error attempting to initialize " | 306 | "the persistent file for the dentry with name " |
304 | "the persistent file for the dentry with name " | 307 | "[%s]; rc = [%d]\n", __func__, |
305 | "[%s]; rc = [%d]\n", __func__, | 308 | ecryptfs_dentry->d_name.name, rc); |
306 | ecryptfs_dentry->d_name.name, rc); | 309 | goto out_free_kmem; |
307 | goto out_free_kmem; | ||
308 | } | ||
309 | } | 310 | } |
310 | crypt_stat = &ecryptfs_inode_to_private( | 311 | crypt_stat = &ecryptfs_inode_to_private( |
311 | ecryptfs_dentry->d_inode)->crypt_stat; | 312 | ecryptfs_dentry->d_inode)->crypt_stat; |
@@ -436,7 +437,6 @@ static struct dentry *ecryptfs_lookup(struct inode *ecryptfs_dir_inode, | |||
436 | struct qstr lower_name; | 437 | struct qstr lower_name; |
437 | int rc = 0; | 438 | int rc = 0; |
438 | 439 | ||
439 | ecryptfs_dentry->d_op = &ecryptfs_dops; | ||
440 | if ((ecryptfs_dentry->d_name.len == 1 | 440 | if ((ecryptfs_dentry->d_name.len == 1 |
441 | && !strcmp(ecryptfs_dentry->d_name.name, ".")) | 441 | && !strcmp(ecryptfs_dentry->d_name.name, ".")) |
442 | || (ecryptfs_dentry->d_name.len == 2 | 442 | || (ecryptfs_dentry->d_name.len == 2 |
@@ -449,7 +449,7 @@ static struct dentry *ecryptfs_lookup(struct inode *ecryptfs_dir_inode, | |||
449 | lower_name.hash = ecryptfs_dentry->d_name.hash; | 449 | lower_name.hash = ecryptfs_dentry->d_name.hash; |
450 | if (lower_dir_dentry->d_op && lower_dir_dentry->d_op->d_hash) { | 450 | if (lower_dir_dentry->d_op && lower_dir_dentry->d_op->d_hash) { |
451 | rc = lower_dir_dentry->d_op->d_hash(lower_dir_dentry, | 451 | rc = lower_dir_dentry->d_op->d_hash(lower_dir_dentry, |
452 | &lower_name); | 452 | lower_dir_dentry->d_inode, &lower_name); |
453 | if (rc < 0) | 453 | if (rc < 0) |
454 | goto out_d_drop; | 454 | goto out_d_drop; |
455 | } | 455 | } |
@@ -484,7 +484,7 @@ static struct dentry *ecryptfs_lookup(struct inode *ecryptfs_dir_inode, | |||
484 | lower_name.hash = full_name_hash(lower_name.name, lower_name.len); | 484 | lower_name.hash = full_name_hash(lower_name.name, lower_name.len); |
485 | if (lower_dir_dentry->d_op && lower_dir_dentry->d_op->d_hash) { | 485 | if (lower_dir_dentry->d_op && lower_dir_dentry->d_op->d_hash) { |
486 | rc = lower_dir_dentry->d_op->d_hash(lower_dir_dentry, | 486 | rc = lower_dir_dentry->d_op->d_hash(lower_dir_dentry, |
487 | &lower_name); | 487 | lower_dir_dentry->d_inode, &lower_name); |
488 | if (rc < 0) | 488 | if (rc < 0) |
489 | goto out_d_drop; | 489 | goto out_d_drop; |
490 | } | 490 | } |
@@ -975,8 +975,10 @@ int ecryptfs_truncate(struct dentry *dentry, loff_t new_length) | |||
975 | } | 975 | } |
976 | 976 | ||
977 | static int | 977 | static int |
978 | ecryptfs_permission(struct inode *inode, int mask) | 978 | ecryptfs_permission(struct inode *inode, int mask, unsigned int flags) |
979 | { | 979 | { |
980 | if (flags & IPERM_FLAG_RCU) | ||
981 | return -ECHILD; | ||
980 | return inode_permission(ecryptfs_inode_to_lower(inode), mask); | 982 | return inode_permission(ecryptfs_inode_to_lower(inode), mask); |
981 | } | 983 | } |
982 | 984 | ||
@@ -1108,10 +1110,8 @@ ecryptfs_setxattr(struct dentry *dentry, const char *name, const void *value, | |||
1108 | rc = -EOPNOTSUPP; | 1110 | rc = -EOPNOTSUPP; |
1109 | goto out; | 1111 | goto out; |
1110 | } | 1112 | } |
1111 | mutex_lock(&lower_dentry->d_inode->i_mutex); | 1113 | |
1112 | rc = lower_dentry->d_inode->i_op->setxattr(lower_dentry, name, value, | 1114 | rc = vfs_setxattr(lower_dentry, name, value, size, flags); |
1113 | size, flags); | ||
1114 | mutex_unlock(&lower_dentry->d_inode->i_mutex); | ||
1115 | out: | 1115 | out: |
1116 | return rc; | 1116 | return rc; |
1117 | } | 1117 | } |
diff --git a/fs/ecryptfs/keystore.c b/fs/ecryptfs/keystore.c index 73811cfa2ea4..c1436cff6f2d 100644 --- a/fs/ecryptfs/keystore.c +++ b/fs/ecryptfs/keystore.c | |||
@@ -59,7 +59,7 @@ static int process_request_key_err(long err_code) | |||
59 | break; | 59 | break; |
60 | default: | 60 | default: |
61 | ecryptfs_printk(KERN_WARNING, "Unknown error code: " | 61 | ecryptfs_printk(KERN_WARNING, "Unknown error code: " |
62 | "[0x%.16x]\n", err_code); | 62 | "[0x%.16lx]\n", err_code); |
63 | rc = -EINVAL; | 63 | rc = -EINVAL; |
64 | } | 64 | } |
65 | return rc; | 65 | return rc; |
@@ -130,7 +130,7 @@ int ecryptfs_write_packet_length(char *dest, size_t size, | |||
130 | } else { | 130 | } else { |
131 | rc = -EINVAL; | 131 | rc = -EINVAL; |
132 | ecryptfs_printk(KERN_WARNING, | 132 | ecryptfs_printk(KERN_WARNING, |
133 | "Unsupported packet size: [%d]\n", size); | 133 | "Unsupported packet size: [%zd]\n", size); |
134 | } | 134 | } |
135 | return rc; | 135 | return rc; |
136 | } | 136 | } |
@@ -446,6 +446,7 @@ out: | |||
446 | */ | 446 | */ |
447 | static int | 447 | static int |
448 | ecryptfs_find_auth_tok_for_sig( | 448 | ecryptfs_find_auth_tok_for_sig( |
449 | struct key **auth_tok_key, | ||
449 | struct ecryptfs_auth_tok **auth_tok, | 450 | struct ecryptfs_auth_tok **auth_tok, |
450 | struct ecryptfs_mount_crypt_stat *mount_crypt_stat, | 451 | struct ecryptfs_mount_crypt_stat *mount_crypt_stat, |
451 | char *sig) | 452 | char *sig) |
@@ -453,12 +454,21 @@ ecryptfs_find_auth_tok_for_sig( | |||
453 | struct ecryptfs_global_auth_tok *global_auth_tok; | 454 | struct ecryptfs_global_auth_tok *global_auth_tok; |
454 | int rc = 0; | 455 | int rc = 0; |
455 | 456 | ||
457 | (*auth_tok_key) = NULL; | ||
456 | (*auth_tok) = NULL; | 458 | (*auth_tok) = NULL; |
457 | if (ecryptfs_find_global_auth_tok_for_sig(&global_auth_tok, | 459 | if (ecryptfs_find_global_auth_tok_for_sig(&global_auth_tok, |
458 | mount_crypt_stat, sig)) { | 460 | mount_crypt_stat, sig)) { |
459 | struct key *auth_tok_key; | ||
460 | 461 | ||
461 | rc = ecryptfs_keyring_auth_tok_for_sig(&auth_tok_key, auth_tok, | 462 | /* if the flag ECRYPTFS_GLOBAL_MOUNT_AUTH_TOK_ONLY is set in the |
463 | * mount_crypt_stat structure, we prevent to use auth toks that | ||
464 | * are not inserted through the ecryptfs_add_global_auth_tok | ||
465 | * function. | ||
466 | */ | ||
467 | if (mount_crypt_stat->flags | ||
468 | & ECRYPTFS_GLOBAL_MOUNT_AUTH_TOK_ONLY) | ||
469 | return -EINVAL; | ||
470 | |||
471 | rc = ecryptfs_keyring_auth_tok_for_sig(auth_tok_key, auth_tok, | ||
462 | sig); | 472 | sig); |
463 | } else | 473 | } else |
464 | (*auth_tok) = global_auth_tok->global_auth_tok; | 474 | (*auth_tok) = global_auth_tok->global_auth_tok; |
@@ -509,6 +519,7 @@ ecryptfs_write_tag_70_packet(char *dest, size_t *remaining_bytes, | |||
509 | char *filename, size_t filename_size) | 519 | char *filename, size_t filename_size) |
510 | { | 520 | { |
511 | struct ecryptfs_write_tag_70_packet_silly_stack *s; | 521 | struct ecryptfs_write_tag_70_packet_silly_stack *s; |
522 | struct key *auth_tok_key = NULL; | ||
512 | int rc = 0; | 523 | int rc = 0; |
513 | 524 | ||
514 | s = kmalloc(sizeof(*s), GFP_KERNEL); | 525 | s = kmalloc(sizeof(*s), GFP_KERNEL); |
@@ -606,6 +617,7 @@ ecryptfs_write_tag_70_packet(char *dest, size_t *remaining_bytes, | |||
606 | } | 617 | } |
607 | dest[s->i++] = s->cipher_code; | 618 | dest[s->i++] = s->cipher_code; |
608 | rc = ecryptfs_find_auth_tok_for_sig( | 619 | rc = ecryptfs_find_auth_tok_for_sig( |
620 | &auth_tok_key, | ||
609 | &s->auth_tok, mount_crypt_stat, | 621 | &s->auth_tok, mount_crypt_stat, |
610 | mount_crypt_stat->global_default_fnek_sig); | 622 | mount_crypt_stat->global_default_fnek_sig); |
611 | if (rc) { | 623 | if (rc) { |
@@ -753,6 +765,8 @@ out_free_unlock: | |||
753 | out_unlock: | 765 | out_unlock: |
754 | mutex_unlock(s->tfm_mutex); | 766 | mutex_unlock(s->tfm_mutex); |
755 | out: | 767 | out: |
768 | if (auth_tok_key) | ||
769 | key_put(auth_tok_key); | ||
756 | kfree(s); | 770 | kfree(s); |
757 | return rc; | 771 | return rc; |
758 | } | 772 | } |
@@ -798,6 +812,7 @@ ecryptfs_parse_tag_70_packet(char **filename, size_t *filename_size, | |||
798 | char *data, size_t max_packet_size) | 812 | char *data, size_t max_packet_size) |
799 | { | 813 | { |
800 | struct ecryptfs_parse_tag_70_packet_silly_stack *s; | 814 | struct ecryptfs_parse_tag_70_packet_silly_stack *s; |
815 | struct key *auth_tok_key = NULL; | ||
801 | int rc = 0; | 816 | int rc = 0; |
802 | 817 | ||
803 | (*packet_size) = 0; | 818 | (*packet_size) = 0; |
@@ -910,7 +925,8 @@ ecryptfs_parse_tag_70_packet(char **filename, size_t *filename_size, | |||
910 | * >= ECRYPTFS_MAX_IV_BYTES. */ | 925 | * >= ECRYPTFS_MAX_IV_BYTES. */ |
911 | memset(s->iv, 0, ECRYPTFS_MAX_IV_BYTES); | 926 | memset(s->iv, 0, ECRYPTFS_MAX_IV_BYTES); |
912 | s->desc.info = s->iv; | 927 | s->desc.info = s->iv; |
913 | rc = ecryptfs_find_auth_tok_for_sig(&s->auth_tok, mount_crypt_stat, | 928 | rc = ecryptfs_find_auth_tok_for_sig(&auth_tok_key, |
929 | &s->auth_tok, mount_crypt_stat, | ||
914 | s->fnek_sig_hex); | 930 | s->fnek_sig_hex); |
915 | if (rc) { | 931 | if (rc) { |
916 | printk(KERN_ERR "%s: Error attempting to find auth tok for " | 932 | printk(KERN_ERR "%s: Error attempting to find auth tok for " |
@@ -986,6 +1002,8 @@ out: | |||
986 | (*filename_size) = 0; | 1002 | (*filename_size) = 0; |
987 | (*filename) = NULL; | 1003 | (*filename) = NULL; |
988 | } | 1004 | } |
1005 | if (auth_tok_key) | ||
1006 | key_put(auth_tok_key); | ||
989 | kfree(s); | 1007 | kfree(s); |
990 | return rc; | 1008 | return rc; |
991 | } | 1009 | } |
@@ -1557,14 +1575,19 @@ int ecryptfs_keyring_auth_tok_for_sig(struct key **auth_tok_key, | |||
1557 | ECRYPTFS_VERSION_MAJOR, | 1575 | ECRYPTFS_VERSION_MAJOR, |
1558 | ECRYPTFS_VERSION_MINOR); | 1576 | ECRYPTFS_VERSION_MINOR); |
1559 | rc = -EINVAL; | 1577 | rc = -EINVAL; |
1560 | goto out; | 1578 | goto out_release_key; |
1561 | } | 1579 | } |
1562 | if ((*auth_tok)->token_type != ECRYPTFS_PASSWORD | 1580 | if ((*auth_tok)->token_type != ECRYPTFS_PASSWORD |
1563 | && (*auth_tok)->token_type != ECRYPTFS_PRIVATE_KEY) { | 1581 | && (*auth_tok)->token_type != ECRYPTFS_PRIVATE_KEY) { |
1564 | printk(KERN_ERR "Invalid auth_tok structure " | 1582 | printk(KERN_ERR "Invalid auth_tok structure " |
1565 | "returned from key query\n"); | 1583 | "returned from key query\n"); |
1566 | rc = -EINVAL; | 1584 | rc = -EINVAL; |
1567 | goto out; | 1585 | goto out_release_key; |
1586 | } | ||
1587 | out_release_key: | ||
1588 | if (rc) { | ||
1589 | key_put(*auth_tok_key); | ||
1590 | (*auth_tok_key) = NULL; | ||
1568 | } | 1591 | } |
1569 | out: | 1592 | out: |
1570 | return rc; | 1593 | return rc; |
@@ -1649,7 +1672,7 @@ decrypt_passphrase_encrypted_session_key(struct ecryptfs_auth_tok *auth_tok, | |||
1649 | auth_tok->session_key.decrypted_key_size); | 1672 | auth_tok->session_key.decrypted_key_size); |
1650 | crypt_stat->flags |= ECRYPTFS_KEY_VALID; | 1673 | crypt_stat->flags |= ECRYPTFS_KEY_VALID; |
1651 | if (unlikely(ecryptfs_verbosity > 0)) { | 1674 | if (unlikely(ecryptfs_verbosity > 0)) { |
1652 | ecryptfs_printk(KERN_DEBUG, "FEK of size [%d]:\n", | 1675 | ecryptfs_printk(KERN_DEBUG, "FEK of size [%zd]:\n", |
1653 | crypt_stat->key_size); | 1676 | crypt_stat->key_size); |
1654 | ecryptfs_dump_hex(crypt_stat->key, | 1677 | ecryptfs_dump_hex(crypt_stat->key, |
1655 | crypt_stat->key_size); | 1678 | crypt_stat->key_size); |
@@ -1688,6 +1711,7 @@ int ecryptfs_parse_packet_set(struct ecryptfs_crypt_stat *crypt_stat, | |||
1688 | struct ecryptfs_auth_tok_list_item *auth_tok_list_item; | 1711 | struct ecryptfs_auth_tok_list_item *auth_tok_list_item; |
1689 | size_t tag_11_contents_size; | 1712 | size_t tag_11_contents_size; |
1690 | size_t tag_11_packet_size; | 1713 | size_t tag_11_packet_size; |
1714 | struct key *auth_tok_key = NULL; | ||
1691 | int rc = 0; | 1715 | int rc = 0; |
1692 | 1716 | ||
1693 | INIT_LIST_HEAD(&auth_tok_list); | 1717 | INIT_LIST_HEAD(&auth_tok_list); |
@@ -1730,7 +1754,7 @@ int ecryptfs_parse_packet_set(struct ecryptfs_crypt_stat *crypt_stat, | |||
1730 | if (ECRYPTFS_SIG_SIZE != tag_11_contents_size) { | 1754 | if (ECRYPTFS_SIG_SIZE != tag_11_contents_size) { |
1731 | ecryptfs_printk(KERN_ERR, "Expected " | 1755 | ecryptfs_printk(KERN_ERR, "Expected " |
1732 | "signature of size [%d]; " | 1756 | "signature of size [%d]; " |
1733 | "read size [%d]\n", | 1757 | "read size [%zd]\n", |
1734 | ECRYPTFS_SIG_SIZE, | 1758 | ECRYPTFS_SIG_SIZE, |
1735 | tag_11_contents_size); | 1759 | tag_11_contents_size); |
1736 | rc = -EIO; | 1760 | rc = -EIO; |
@@ -1763,8 +1787,8 @@ int ecryptfs_parse_packet_set(struct ecryptfs_crypt_stat *crypt_stat, | |||
1763 | goto out_wipe_list; | 1787 | goto out_wipe_list; |
1764 | break; | 1788 | break; |
1765 | default: | 1789 | default: |
1766 | ecryptfs_printk(KERN_DEBUG, "No packet at offset " | 1790 | ecryptfs_printk(KERN_DEBUG, "No packet at offset [%zd] " |
1767 | "[%d] of the file header; hex value of " | 1791 | "of the file header; hex value of " |
1768 | "character is [0x%.2x]\n", i, src[i]); | 1792 | "character is [0x%.2x]\n", i, src[i]); |
1769 | next_packet_is_auth_tok_packet = 0; | 1793 | next_packet_is_auth_tok_packet = 0; |
1770 | } | 1794 | } |
@@ -1784,6 +1808,10 @@ int ecryptfs_parse_packet_set(struct ecryptfs_crypt_stat *crypt_stat, | |||
1784 | * just one will be sufficient to decrypt to get the FEK. */ | 1808 | * just one will be sufficient to decrypt to get the FEK. */ |
1785 | find_next_matching_auth_tok: | 1809 | find_next_matching_auth_tok: |
1786 | found_auth_tok = 0; | 1810 | found_auth_tok = 0; |
1811 | if (auth_tok_key) { | ||
1812 | key_put(auth_tok_key); | ||
1813 | auth_tok_key = NULL; | ||
1814 | } | ||
1787 | list_for_each_entry(auth_tok_list_item, &auth_tok_list, list) { | 1815 | list_for_each_entry(auth_tok_list_item, &auth_tok_list, list) { |
1788 | candidate_auth_tok = &auth_tok_list_item->auth_tok; | 1816 | candidate_auth_tok = &auth_tok_list_item->auth_tok; |
1789 | if (unlikely(ecryptfs_verbosity > 0)) { | 1817 | if (unlikely(ecryptfs_verbosity > 0)) { |
@@ -1800,10 +1828,11 @@ find_next_matching_auth_tok: | |||
1800 | rc = -EINVAL; | 1828 | rc = -EINVAL; |
1801 | goto out_wipe_list; | 1829 | goto out_wipe_list; |
1802 | } | 1830 | } |
1803 | ecryptfs_find_auth_tok_for_sig(&matching_auth_tok, | 1831 | rc = ecryptfs_find_auth_tok_for_sig(&auth_tok_key, |
1832 | &matching_auth_tok, | ||
1804 | crypt_stat->mount_crypt_stat, | 1833 | crypt_stat->mount_crypt_stat, |
1805 | candidate_auth_tok_sig); | 1834 | candidate_auth_tok_sig); |
1806 | if (matching_auth_tok) { | 1835 | if (!rc) { |
1807 | found_auth_tok = 1; | 1836 | found_auth_tok = 1; |
1808 | goto found_matching_auth_tok; | 1837 | goto found_matching_auth_tok; |
1809 | } | 1838 | } |
@@ -1835,8 +1864,8 @@ found_matching_auth_tok: | |||
1835 | "session key for authentication token with sig " | 1864 | "session key for authentication token with sig " |
1836 | "[%.*s]; rc = [%d]. Removing auth tok " | 1865 | "[%.*s]; rc = [%d]. Removing auth tok " |
1837 | "candidate from the list and searching for " | 1866 | "candidate from the list and searching for " |
1838 | "the next match.\n", candidate_auth_tok_sig, | 1867 | "the next match.\n", ECRYPTFS_SIG_SIZE_HEX, |
1839 | ECRYPTFS_SIG_SIZE_HEX, rc); | 1868 | candidate_auth_tok_sig, rc); |
1840 | list_for_each_entry_safe(auth_tok_list_item, | 1869 | list_for_each_entry_safe(auth_tok_list_item, |
1841 | auth_tok_list_item_tmp, | 1870 | auth_tok_list_item_tmp, |
1842 | &auth_tok_list, list) { | 1871 | &auth_tok_list, list) { |
@@ -1866,6 +1895,8 @@ found_matching_auth_tok: | |||
1866 | out_wipe_list: | 1895 | out_wipe_list: |
1867 | wipe_auth_tok_list(&auth_tok_list); | 1896 | wipe_auth_tok_list(&auth_tok_list); |
1868 | out: | 1897 | out: |
1898 | if (auth_tok_key) | ||
1899 | key_put(auth_tok_key); | ||
1869 | return rc; | 1900 | return rc; |
1870 | } | 1901 | } |
1871 | 1902 | ||
@@ -2137,7 +2168,7 @@ write_tag_3_packet(char *dest, size_t *remaining_bytes, | |||
2137 | if (encrypted_session_key_valid) { | 2168 | if (encrypted_session_key_valid) { |
2138 | ecryptfs_printk(KERN_DEBUG, "encrypted_session_key_valid != 0; " | 2169 | ecryptfs_printk(KERN_DEBUG, "encrypted_session_key_valid != 0; " |
2139 | "using auth_tok->session_key.encrypted_key, " | 2170 | "using auth_tok->session_key.encrypted_key, " |
2140 | "where key_rec->enc_key_size = [%d]\n", | 2171 | "where key_rec->enc_key_size = [%zd]\n", |
2141 | key_rec->enc_key_size); | 2172 | key_rec->enc_key_size); |
2142 | memcpy(key_rec->enc_key, | 2173 | memcpy(key_rec->enc_key, |
2143 | auth_tok->session_key.encrypted_key, | 2174 | auth_tok->session_key.encrypted_key, |
@@ -2167,7 +2198,7 @@ write_tag_3_packet(char *dest, size_t *remaining_bytes, | |||
2167 | if (rc < 1 || rc > 2) { | 2198 | if (rc < 1 || rc > 2) { |
2168 | ecryptfs_printk(KERN_ERR, "Error generating scatterlist " | 2199 | ecryptfs_printk(KERN_ERR, "Error generating scatterlist " |
2169 | "for crypt_stat session key; expected rc = 1; " | 2200 | "for crypt_stat session key; expected rc = 1; " |
2170 | "got rc = [%d]. key_rec->enc_key_size = [%d]\n", | 2201 | "got rc = [%d]. key_rec->enc_key_size = [%zd]\n", |
2171 | rc, key_rec->enc_key_size); | 2202 | rc, key_rec->enc_key_size); |
2172 | rc = -ENOMEM; | 2203 | rc = -ENOMEM; |
2173 | goto out; | 2204 | goto out; |
@@ -2178,7 +2209,7 @@ write_tag_3_packet(char *dest, size_t *remaining_bytes, | |||
2178 | ecryptfs_printk(KERN_ERR, "Error generating scatterlist " | 2209 | ecryptfs_printk(KERN_ERR, "Error generating scatterlist " |
2179 | "for crypt_stat encrypted session key; " | 2210 | "for crypt_stat encrypted session key; " |
2180 | "expected rc = 1; got rc = [%d]. " | 2211 | "expected rc = 1; got rc = [%d]. " |
2181 | "key_rec->enc_key_size = [%d]\n", rc, | 2212 | "key_rec->enc_key_size = [%zd]\n", rc, |
2182 | key_rec->enc_key_size); | 2213 | key_rec->enc_key_size); |
2183 | rc = -ENOMEM; | 2214 | rc = -ENOMEM; |
2184 | goto out; | 2215 | goto out; |
@@ -2193,7 +2224,7 @@ write_tag_3_packet(char *dest, size_t *remaining_bytes, | |||
2193 | goto out; | 2224 | goto out; |
2194 | } | 2225 | } |
2195 | rc = 0; | 2226 | rc = 0; |
2196 | ecryptfs_printk(KERN_DEBUG, "Encrypting [%d] bytes of the key\n", | 2227 | ecryptfs_printk(KERN_DEBUG, "Encrypting [%zd] bytes of the key\n", |
2197 | crypt_stat->key_size); | 2228 | crypt_stat->key_size); |
2198 | rc = crypto_blkcipher_encrypt(&desc, dst_sg, src_sg, | 2229 | rc = crypto_blkcipher_encrypt(&desc, dst_sg, src_sg, |
2199 | (*key_rec).enc_key_size); | 2230 | (*key_rec).enc_key_size); |
@@ -2204,7 +2235,7 @@ write_tag_3_packet(char *dest, size_t *remaining_bytes, | |||
2204 | } | 2235 | } |
2205 | ecryptfs_printk(KERN_DEBUG, "This should be the encrypted key:\n"); | 2236 | ecryptfs_printk(KERN_DEBUG, "This should be the encrypted key:\n"); |
2206 | if (ecryptfs_verbosity > 0) { | 2237 | if (ecryptfs_verbosity > 0) { |
2207 | ecryptfs_printk(KERN_DEBUG, "EFEK of size [%d]:\n", | 2238 | ecryptfs_printk(KERN_DEBUG, "EFEK of size [%zd]:\n", |
2208 | key_rec->enc_key_size); | 2239 | key_rec->enc_key_size); |
2209 | ecryptfs_dump_hex(key_rec->enc_key, | 2240 | ecryptfs_dump_hex(key_rec->enc_key, |
2210 | key_rec->enc_key_size); | 2241 | key_rec->enc_key_size); |
diff --git a/fs/ecryptfs/main.c b/fs/ecryptfs/main.c index cbd4e18adb20..758323a0f09a 100644 --- a/fs/ecryptfs/main.c +++ b/fs/ecryptfs/main.c | |||
@@ -36,6 +36,7 @@ | |||
36 | #include <linux/parser.h> | 36 | #include <linux/parser.h> |
37 | #include <linux/fs_stack.h> | 37 | #include <linux/fs_stack.h> |
38 | #include <linux/slab.h> | 38 | #include <linux/slab.h> |
39 | #include <linux/magic.h> | ||
39 | #include "ecryptfs_kernel.h" | 40 | #include "ecryptfs_kernel.h" |
40 | 41 | ||
41 | /** | 42 | /** |
@@ -141,25 +142,12 @@ int ecryptfs_init_persistent_file(struct dentry *ecryptfs_dentry) | |||
141 | return rc; | 142 | return rc; |
142 | } | 143 | } |
143 | 144 | ||
144 | /** | 145 | static struct inode *ecryptfs_get_inode(struct inode *lower_inode, |
145 | * ecryptfs_interpose | 146 | struct super_block *sb) |
146 | * @lower_dentry: Existing dentry in the lower filesystem | ||
147 | * @dentry: ecryptfs' dentry | ||
148 | * @sb: ecryptfs's super_block | ||
149 | * @flags: flags to govern behavior of interpose procedure | ||
150 | * | ||
151 | * Interposes upper and lower dentries. | ||
152 | * | ||
153 | * Returns zero on success; non-zero otherwise | ||
154 | */ | ||
155 | int ecryptfs_interpose(struct dentry *lower_dentry, struct dentry *dentry, | ||
156 | struct super_block *sb, u32 flags) | ||
157 | { | 147 | { |
158 | struct inode *lower_inode; | ||
159 | struct inode *inode; | 148 | struct inode *inode; |
160 | int rc = 0; | 149 | int rc = 0; |
161 | 150 | ||
162 | lower_inode = lower_dentry->d_inode; | ||
163 | if (lower_inode->i_sb != ecryptfs_superblock_to_lower(sb)) { | 151 | if (lower_inode->i_sb != ecryptfs_superblock_to_lower(sb)) { |
164 | rc = -EXDEV; | 152 | rc = -EXDEV; |
165 | goto out; | 153 | goto out; |
@@ -189,17 +177,38 @@ int ecryptfs_interpose(struct dentry *lower_dentry, struct dentry *dentry, | |||
189 | if (special_file(lower_inode->i_mode)) | 177 | if (special_file(lower_inode->i_mode)) |
190 | init_special_inode(inode, lower_inode->i_mode, | 178 | init_special_inode(inode, lower_inode->i_mode, |
191 | lower_inode->i_rdev); | 179 | lower_inode->i_rdev); |
192 | dentry->d_op = &ecryptfs_dops; | ||
193 | fsstack_copy_attr_all(inode, lower_inode); | 180 | fsstack_copy_attr_all(inode, lower_inode); |
194 | /* This size will be overwritten for real files w/ headers and | 181 | /* This size will be overwritten for real files w/ headers and |
195 | * other metadata */ | 182 | * other metadata */ |
196 | fsstack_copy_inode_size(inode, lower_inode); | 183 | fsstack_copy_inode_size(inode, lower_inode); |
184 | return inode; | ||
185 | out: | ||
186 | return ERR_PTR(rc); | ||
187 | } | ||
188 | |||
189 | /** | ||
190 | * ecryptfs_interpose | ||
191 | * @lower_dentry: Existing dentry in the lower filesystem | ||
192 | * @dentry: ecryptfs' dentry | ||
193 | * @sb: ecryptfs's super_block | ||
194 | * @flags: flags to govern behavior of interpose procedure | ||
195 | * | ||
196 | * Interposes upper and lower dentries. | ||
197 | * | ||
198 | * Returns zero on success; non-zero otherwise | ||
199 | */ | ||
200 | int ecryptfs_interpose(struct dentry *lower_dentry, struct dentry *dentry, | ||
201 | struct super_block *sb, u32 flags) | ||
202 | { | ||
203 | struct inode *lower_inode = lower_dentry->d_inode; | ||
204 | struct inode *inode = ecryptfs_get_inode(lower_inode, sb); | ||
205 | if (IS_ERR(inode)) | ||
206 | return PTR_ERR(inode); | ||
197 | if (flags & ECRYPTFS_INTERPOSE_FLAG_D_ADD) | 207 | if (flags & ECRYPTFS_INTERPOSE_FLAG_D_ADD) |
198 | d_add(dentry, inode); | 208 | d_add(dentry, inode); |
199 | else | 209 | else |
200 | d_instantiate(dentry, inode); | 210 | d_instantiate(dentry, inode); |
201 | out: | 211 | return 0; |
202 | return rc; | ||
203 | } | 212 | } |
204 | 213 | ||
205 | enum { ecryptfs_opt_sig, ecryptfs_opt_ecryptfs_sig, | 214 | enum { ecryptfs_opt_sig, ecryptfs_opt_ecryptfs_sig, |
@@ -208,7 +217,8 @@ enum { ecryptfs_opt_sig, ecryptfs_opt_ecryptfs_sig, | |||
208 | ecryptfs_opt_passthrough, ecryptfs_opt_xattr_metadata, | 217 | ecryptfs_opt_passthrough, ecryptfs_opt_xattr_metadata, |
209 | ecryptfs_opt_encrypted_view, ecryptfs_opt_fnek_sig, | 218 | ecryptfs_opt_encrypted_view, ecryptfs_opt_fnek_sig, |
210 | ecryptfs_opt_fn_cipher, ecryptfs_opt_fn_cipher_key_bytes, | 219 | ecryptfs_opt_fn_cipher, ecryptfs_opt_fn_cipher_key_bytes, |
211 | ecryptfs_opt_unlink_sigs, ecryptfs_opt_err }; | 220 | ecryptfs_opt_unlink_sigs, ecryptfs_opt_mount_auth_tok_only, |
221 | ecryptfs_opt_err }; | ||
212 | 222 | ||
213 | static const match_table_t tokens = { | 223 | static const match_table_t tokens = { |
214 | {ecryptfs_opt_sig, "sig=%s"}, | 224 | {ecryptfs_opt_sig, "sig=%s"}, |
@@ -223,6 +233,7 @@ static const match_table_t tokens = { | |||
223 | {ecryptfs_opt_fn_cipher, "ecryptfs_fn_cipher=%s"}, | 233 | {ecryptfs_opt_fn_cipher, "ecryptfs_fn_cipher=%s"}, |
224 | {ecryptfs_opt_fn_cipher_key_bytes, "ecryptfs_fn_key_bytes=%u"}, | 234 | {ecryptfs_opt_fn_cipher_key_bytes, "ecryptfs_fn_key_bytes=%u"}, |
225 | {ecryptfs_opt_unlink_sigs, "ecryptfs_unlink_sigs"}, | 235 | {ecryptfs_opt_unlink_sigs, "ecryptfs_unlink_sigs"}, |
236 | {ecryptfs_opt_mount_auth_tok_only, "ecryptfs_mount_auth_tok_only"}, | ||
226 | {ecryptfs_opt_err, NULL} | 237 | {ecryptfs_opt_err, NULL} |
227 | }; | 238 | }; |
228 | 239 | ||
@@ -406,6 +417,10 @@ static int ecryptfs_parse_options(struct ecryptfs_sb_info *sbi, char *options) | |||
406 | case ecryptfs_opt_unlink_sigs: | 417 | case ecryptfs_opt_unlink_sigs: |
407 | mount_crypt_stat->flags |= ECRYPTFS_UNLINK_SIGS; | 418 | mount_crypt_stat->flags |= ECRYPTFS_UNLINK_SIGS; |
408 | break; | 419 | break; |
420 | case ecryptfs_opt_mount_auth_tok_only: | ||
421 | mount_crypt_stat->flags |= | ||
422 | ECRYPTFS_GLOBAL_MOUNT_AUTH_TOK_ONLY; | ||
423 | break; | ||
409 | case ecryptfs_opt_err: | 424 | case ecryptfs_opt_err: |
410 | default: | 425 | default: |
411 | printk(KERN_WARNING | 426 | printk(KERN_WARNING |
@@ -486,68 +501,21 @@ struct kmem_cache *ecryptfs_sb_info_cache; | |||
486 | static struct file_system_type ecryptfs_fs_type; | 501 | static struct file_system_type ecryptfs_fs_type; |
487 | 502 | ||
488 | /** | 503 | /** |
489 | * ecryptfs_read_super | ||
490 | * @sb: The ecryptfs super block | ||
491 | * @dev_name: The path to mount over | ||
492 | * | ||
493 | * Read the super block of the lower filesystem, and use | ||
494 | * ecryptfs_interpose to create our initial inode and super block | ||
495 | * struct. | ||
496 | */ | ||
497 | static int ecryptfs_read_super(struct super_block *sb, const char *dev_name) | ||
498 | { | ||
499 | struct path path; | ||
500 | int rc; | ||
501 | |||
502 | rc = kern_path(dev_name, LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &path); | ||
503 | if (rc) { | ||
504 | ecryptfs_printk(KERN_WARNING, "path_lookup() failed\n"); | ||
505 | goto out; | ||
506 | } | ||
507 | if (path.dentry->d_sb->s_type == &ecryptfs_fs_type) { | ||
508 | rc = -EINVAL; | ||
509 | printk(KERN_ERR "Mount on filesystem of type " | ||
510 | "eCryptfs explicitly disallowed due to " | ||
511 | "known incompatibilities\n"); | ||
512 | goto out_free; | ||
513 | } | ||
514 | ecryptfs_set_superblock_lower(sb, path.dentry->d_sb); | ||
515 | sb->s_maxbytes = path.dentry->d_sb->s_maxbytes; | ||
516 | sb->s_blocksize = path.dentry->d_sb->s_blocksize; | ||
517 | ecryptfs_set_dentry_lower(sb->s_root, path.dentry); | ||
518 | ecryptfs_set_dentry_lower_mnt(sb->s_root, path.mnt); | ||
519 | rc = ecryptfs_interpose(path.dentry, sb->s_root, sb, 0); | ||
520 | if (rc) | ||
521 | goto out_free; | ||
522 | rc = 0; | ||
523 | goto out; | ||
524 | out_free: | ||
525 | path_put(&path); | ||
526 | out: | ||
527 | return rc; | ||
528 | } | ||
529 | |||
530 | /** | ||
531 | * ecryptfs_get_sb | 504 | * ecryptfs_get_sb |
532 | * @fs_type | 505 | * @fs_type |
533 | * @flags | 506 | * @flags |
534 | * @dev_name: The path to mount over | 507 | * @dev_name: The path to mount over |
535 | * @raw_data: The options passed into the kernel | 508 | * @raw_data: The options passed into the kernel |
536 | * | ||
537 | * The whole ecryptfs_get_sb process is broken into 3 functions: | ||
538 | * ecryptfs_parse_options(): handle options passed to ecryptfs, if any | ||
539 | * ecryptfs_read_super(): this accesses the lower filesystem and uses | ||
540 | * ecryptfs_interpose to perform most of the linking | ||
541 | * ecryptfs_interpose(): links the lower filesystem into ecryptfs (inode.c) | ||
542 | */ | 509 | */ |
543 | static int ecryptfs_get_sb(struct file_system_type *fs_type, int flags, | 510 | static struct dentry *ecryptfs_mount(struct file_system_type *fs_type, int flags, |
544 | const char *dev_name, void *raw_data, | 511 | const char *dev_name, void *raw_data) |
545 | struct vfsmount *mnt) | ||
546 | { | 512 | { |
547 | struct super_block *s; | 513 | struct super_block *s; |
548 | struct ecryptfs_sb_info *sbi; | 514 | struct ecryptfs_sb_info *sbi; |
549 | struct ecryptfs_dentry_info *root_info; | 515 | struct ecryptfs_dentry_info *root_info; |
550 | const char *err = "Getting sb failed"; | 516 | const char *err = "Getting sb failed"; |
517 | struct inode *inode; | ||
518 | struct path path; | ||
551 | int rc; | 519 | int rc; |
552 | 520 | ||
553 | sbi = kmem_cache_zalloc(ecryptfs_sb_info_cache, GFP_KERNEL); | 521 | sbi = kmem_cache_zalloc(ecryptfs_sb_info_cache, GFP_KERNEL); |
@@ -570,10 +538,8 @@ static int ecryptfs_get_sb(struct file_system_type *fs_type, int flags, | |||
570 | 538 | ||
571 | s->s_flags = flags; | 539 | s->s_flags = flags; |
572 | rc = bdi_setup_and_register(&sbi->bdi, "ecryptfs", BDI_CAP_MAP_COPY); | 540 | rc = bdi_setup_and_register(&sbi->bdi, "ecryptfs", BDI_CAP_MAP_COPY); |
573 | if (rc) { | 541 | if (rc) |
574 | deactivate_locked_super(s); | 542 | goto out1; |
575 | goto out; | ||
576 | } | ||
577 | 543 | ||
578 | ecryptfs_set_superblock_private(s, sbi); | 544 | ecryptfs_set_superblock_private(s, sbi); |
579 | s->s_bdi = &sbi->bdi; | 545 | s->s_bdi = &sbi->bdi; |
@@ -581,42 +547,62 @@ static int ecryptfs_get_sb(struct file_system_type *fs_type, int flags, | |||
581 | /* ->kill_sb() will take care of sbi after that point */ | 547 | /* ->kill_sb() will take care of sbi after that point */ |
582 | sbi = NULL; | 548 | sbi = NULL; |
583 | s->s_op = &ecryptfs_sops; | 549 | s->s_op = &ecryptfs_sops; |
550 | s->s_d_op = &ecryptfs_dops; | ||
584 | 551 | ||
585 | rc = -ENOMEM; | 552 | err = "Reading sb failed"; |
586 | s->s_root = d_alloc(NULL, &(const struct qstr) { | 553 | rc = kern_path(dev_name, LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &path); |
587 | .hash = 0,.name = "/",.len = 1}); | 554 | if (rc) { |
555 | ecryptfs_printk(KERN_WARNING, "kern_path() failed\n"); | ||
556 | goto out1; | ||
557 | } | ||
558 | if (path.dentry->d_sb->s_type == &ecryptfs_fs_type) { | ||
559 | rc = -EINVAL; | ||
560 | printk(KERN_ERR "Mount on filesystem of type " | ||
561 | "eCryptfs explicitly disallowed due to " | ||
562 | "known incompatibilities\n"); | ||
563 | goto out_free; | ||
564 | } | ||
565 | ecryptfs_set_superblock_lower(s, path.dentry->d_sb); | ||
566 | s->s_maxbytes = path.dentry->d_sb->s_maxbytes; | ||
567 | s->s_blocksize = path.dentry->d_sb->s_blocksize; | ||
568 | s->s_magic = ECRYPTFS_SUPER_MAGIC; | ||
569 | |||
570 | inode = ecryptfs_get_inode(path.dentry->d_inode, s); | ||
571 | rc = PTR_ERR(inode); | ||
572 | if (IS_ERR(inode)) | ||
573 | goto out_free; | ||
574 | |||
575 | s->s_root = d_alloc_root(inode); | ||
588 | if (!s->s_root) { | 576 | if (!s->s_root) { |
589 | deactivate_locked_super(s); | 577 | iput(inode); |
590 | goto out; | 578 | rc = -ENOMEM; |
579 | goto out_free; | ||
591 | } | 580 | } |
592 | s->s_root->d_op = &ecryptfs_dops; | ||
593 | s->s_root->d_sb = s; | ||
594 | s->s_root->d_parent = s->s_root; | ||
595 | 581 | ||
582 | rc = -ENOMEM; | ||
596 | root_info = kmem_cache_zalloc(ecryptfs_dentry_info_cache, GFP_KERNEL); | 583 | root_info = kmem_cache_zalloc(ecryptfs_dentry_info_cache, GFP_KERNEL); |
597 | if (!root_info) { | 584 | if (!root_info) |
598 | deactivate_locked_super(s); | 585 | goto out_free; |
599 | goto out; | 586 | |
600 | } | ||
601 | /* ->kill_sb() will take care of root_info */ | 587 | /* ->kill_sb() will take care of root_info */ |
602 | ecryptfs_set_dentry_private(s->s_root, root_info); | 588 | ecryptfs_set_dentry_private(s->s_root, root_info); |
589 | ecryptfs_set_dentry_lower(s->s_root, path.dentry); | ||
590 | ecryptfs_set_dentry_lower_mnt(s->s_root, path.mnt); | ||
591 | |||
603 | s->s_flags |= MS_ACTIVE; | 592 | s->s_flags |= MS_ACTIVE; |
604 | rc = ecryptfs_read_super(s, dev_name); | 593 | return dget(s->s_root); |
605 | if (rc) { | ||
606 | deactivate_locked_super(s); | ||
607 | err = "Reading sb failed"; | ||
608 | goto out; | ||
609 | } | ||
610 | simple_set_mnt(mnt, s); | ||
611 | return 0; | ||
612 | 594 | ||
595 | out_free: | ||
596 | path_put(&path); | ||
597 | out1: | ||
598 | deactivate_locked_super(s); | ||
613 | out: | 599 | out: |
614 | if (sbi) { | 600 | if (sbi) { |
615 | ecryptfs_destroy_mount_crypt_stat(&sbi->mount_crypt_stat); | 601 | ecryptfs_destroy_mount_crypt_stat(&sbi->mount_crypt_stat); |
616 | kmem_cache_free(ecryptfs_sb_info_cache, sbi); | 602 | kmem_cache_free(ecryptfs_sb_info_cache, sbi); |
617 | } | 603 | } |
618 | printk(KERN_ERR "%s; rc = [%d]\n", err, rc); | 604 | printk(KERN_ERR "%s; rc = [%d]\n", err, rc); |
619 | return rc; | 605 | return ERR_PTR(rc); |
620 | } | 606 | } |
621 | 607 | ||
622 | /** | 608 | /** |
@@ -639,7 +625,7 @@ static void ecryptfs_kill_block_super(struct super_block *sb) | |||
639 | static struct file_system_type ecryptfs_fs_type = { | 625 | static struct file_system_type ecryptfs_fs_type = { |
640 | .owner = THIS_MODULE, | 626 | .owner = THIS_MODULE, |
641 | .name = "ecryptfs", | 627 | .name = "ecryptfs", |
642 | .get_sb = ecryptfs_get_sb, | 628 | .mount = ecryptfs_mount, |
643 | .kill_sb = ecryptfs_kill_block_super, | 629 | .kill_sb = ecryptfs_kill_block_super, |
644 | .fs_flags = 0 | 630 | .fs_flags = 0 |
645 | }; | 631 | }; |
@@ -824,9 +810,10 @@ static int __init ecryptfs_init(void) | |||
824 | ecryptfs_printk(KERN_ERR, "The eCryptfs extent size is " | 810 | ecryptfs_printk(KERN_ERR, "The eCryptfs extent size is " |
825 | "larger than the host's page size, and so " | 811 | "larger than the host's page size, and so " |
826 | "eCryptfs cannot run on this system. The " | 812 | "eCryptfs cannot run on this system. The " |
827 | "default eCryptfs extent size is [%d] bytes; " | 813 | "default eCryptfs extent size is [%u] bytes; " |
828 | "the page size is [%d] bytes.\n", | 814 | "the page size is [%lu] bytes.\n", |
829 | ECRYPTFS_DEFAULT_EXTENT_SIZE, PAGE_CACHE_SIZE); | 815 | ECRYPTFS_DEFAULT_EXTENT_SIZE, |
816 | (unsigned long)PAGE_CACHE_SIZE); | ||
830 | goto out; | 817 | goto out; |
831 | } | 818 | } |
832 | rc = ecryptfs_init_kmem_caches(); | 819 | rc = ecryptfs_init_kmem_caches(); |
diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c index 00208c3d7e92..940a82e63dc3 100644 --- a/fs/ecryptfs/miscdev.c +++ b/fs/ecryptfs/miscdev.c | |||
@@ -482,6 +482,7 @@ static const struct file_operations ecryptfs_miscdev_fops = { | |||
482 | .read = ecryptfs_miscdev_read, | 482 | .read = ecryptfs_miscdev_read, |
483 | .write = ecryptfs_miscdev_write, | 483 | .write = ecryptfs_miscdev_write, |
484 | .release = ecryptfs_miscdev_release, | 484 | .release = ecryptfs_miscdev_release, |
485 | .llseek = noop_llseek, | ||
485 | }; | 486 | }; |
486 | 487 | ||
487 | static struct miscdevice ecryptfs_miscdev = { | 488 | static struct miscdevice ecryptfs_miscdev = { |
diff --git a/fs/ecryptfs/mmap.c b/fs/ecryptfs/mmap.c index b1d82756544b..cc64fca89f8d 100644 --- a/fs/ecryptfs/mmap.c +++ b/fs/ecryptfs/mmap.c | |||
@@ -65,7 +65,7 @@ static int ecryptfs_writepage(struct page *page, struct writeback_control *wbc) | |||
65 | rc = ecryptfs_encrypt_page(page); | 65 | rc = ecryptfs_encrypt_page(page); |
66 | if (rc) { | 66 | if (rc) { |
67 | ecryptfs_printk(KERN_WARNING, "Error encrypting " | 67 | ecryptfs_printk(KERN_WARNING, "Error encrypting " |
68 | "page (upper index [0x%.16x])\n", page->index); | 68 | "page (upper index [0x%.16lx])\n", page->index); |
69 | ClearPageUptodate(page); | 69 | ClearPageUptodate(page); |
70 | goto out; | 70 | goto out; |
71 | } | 71 | } |
@@ -237,7 +237,7 @@ out: | |||
237 | ClearPageUptodate(page); | 237 | ClearPageUptodate(page); |
238 | else | 238 | else |
239 | SetPageUptodate(page); | 239 | SetPageUptodate(page); |
240 | ecryptfs_printk(KERN_DEBUG, "Unlocking page with index = [0x%.16x]\n", | 240 | ecryptfs_printk(KERN_DEBUG, "Unlocking page with index = [0x%.16lx]\n", |
241 | page->index); | 241 | page->index); |
242 | unlock_page(page); | 242 | unlock_page(page); |
243 | return rc; | 243 | return rc; |
@@ -290,6 +290,7 @@ static int ecryptfs_write_begin(struct file *file, | |||
290 | return -ENOMEM; | 290 | return -ENOMEM; |
291 | *pagep = page; | 291 | *pagep = page; |
292 | 292 | ||
293 | prev_page_end_size = ((loff_t)index << PAGE_CACHE_SHIFT); | ||
293 | if (!PageUptodate(page)) { | 294 | if (!PageUptodate(page)) { |
294 | struct ecryptfs_crypt_stat *crypt_stat = | 295 | struct ecryptfs_crypt_stat *crypt_stat = |
295 | &ecryptfs_inode_to_private(mapping->host)->crypt_stat; | 296 | &ecryptfs_inode_to_private(mapping->host)->crypt_stat; |
@@ -335,18 +336,23 @@ static int ecryptfs_write_begin(struct file *file, | |||
335 | SetPageUptodate(page); | 336 | SetPageUptodate(page); |
336 | } | 337 | } |
337 | } else { | 338 | } else { |
338 | rc = ecryptfs_decrypt_page(page); | 339 | if (prev_page_end_size |
339 | if (rc) { | 340 | >= i_size_read(page->mapping->host)) { |
340 | printk(KERN_ERR "%s: Error decrypting page " | 341 | zero_user(page, 0, PAGE_CACHE_SIZE); |
341 | "at index [%ld]; rc = [%d]\n", | 342 | } else { |
342 | __func__, page->index, rc); | 343 | rc = ecryptfs_decrypt_page(page); |
343 | ClearPageUptodate(page); | 344 | if (rc) { |
344 | goto out; | 345 | printk(KERN_ERR "%s: Error decrypting " |
346 | "page at index [%ld]; " | ||
347 | "rc = [%d]\n", | ||
348 | __func__, page->index, rc); | ||
349 | ClearPageUptodate(page); | ||
350 | goto out; | ||
351 | } | ||
345 | } | 352 | } |
346 | SetPageUptodate(page); | 353 | SetPageUptodate(page); |
347 | } | 354 | } |
348 | } | 355 | } |
349 | prev_page_end_size = ((loff_t)index << PAGE_CACHE_SHIFT); | ||
350 | /* If creating a page or more of holes, zero them out via truncate. | 356 | /* If creating a page or more of holes, zero them out via truncate. |
351 | * Note, this will increase i_size. */ | 357 | * Note, this will increase i_size. */ |
352 | if (index != 0) { | 358 | if (index != 0) { |
@@ -488,7 +494,7 @@ static int ecryptfs_write_end(struct file *file, | |||
488 | } else | 494 | } else |
489 | ecryptfs_printk(KERN_DEBUG, "Not a new file\n"); | 495 | ecryptfs_printk(KERN_DEBUG, "Not a new file\n"); |
490 | ecryptfs_printk(KERN_DEBUG, "Calling fill_zeros_to_end_of_page" | 496 | ecryptfs_printk(KERN_DEBUG, "Calling fill_zeros_to_end_of_page" |
491 | "(page w/ index = [0x%.16x], to = [%d])\n", index, to); | 497 | "(page w/ index = [0x%.16lx], to = [%d])\n", index, to); |
492 | if (!(crypt_stat->flags & ECRYPTFS_ENCRYPTED)) { | 498 | if (!(crypt_stat->flags & ECRYPTFS_ENCRYPTED)) { |
493 | rc = ecryptfs_write_lower_page_segment(ecryptfs_inode, page, 0, | 499 | rc = ecryptfs_write_lower_page_segment(ecryptfs_inode, page, 0, |
494 | to); | 500 | to); |
@@ -503,19 +509,20 @@ static int ecryptfs_write_end(struct file *file, | |||
503 | rc = fill_zeros_to_end_of_page(page, to); | 509 | rc = fill_zeros_to_end_of_page(page, to); |
504 | if (rc) { | 510 | if (rc) { |
505 | ecryptfs_printk(KERN_WARNING, "Error attempting to fill " | 511 | ecryptfs_printk(KERN_WARNING, "Error attempting to fill " |
506 | "zeros in page with index = [0x%.16x]\n", index); | 512 | "zeros in page with index = [0x%.16lx]\n", index); |
507 | goto out; | 513 | goto out; |
508 | } | 514 | } |
509 | rc = ecryptfs_encrypt_page(page); | 515 | rc = ecryptfs_encrypt_page(page); |
510 | if (rc) { | 516 | if (rc) { |
511 | ecryptfs_printk(KERN_WARNING, "Error encrypting page (upper " | 517 | ecryptfs_printk(KERN_WARNING, "Error encrypting page (upper " |
512 | "index [0x%.16x])\n", index); | 518 | "index [0x%.16lx])\n", index); |
513 | goto out; | 519 | goto out; |
514 | } | 520 | } |
515 | if (pos + copied > i_size_read(ecryptfs_inode)) { | 521 | if (pos + copied > i_size_read(ecryptfs_inode)) { |
516 | i_size_write(ecryptfs_inode, pos + copied); | 522 | i_size_write(ecryptfs_inode, pos + copied); |
517 | ecryptfs_printk(KERN_DEBUG, "Expanded file size to " | 523 | ecryptfs_printk(KERN_DEBUG, "Expanded file size to " |
518 | "[0x%.16x]\n", i_size_read(ecryptfs_inode)); | 524 | "[0x%.16llx]\n", |
525 | (unsigned long long)i_size_read(ecryptfs_inode)); | ||
519 | } | 526 | } |
520 | rc = ecryptfs_write_inode_size_to_metadata(ecryptfs_inode); | 527 | rc = ecryptfs_write_inode_size_to_metadata(ecryptfs_inode); |
521 | if (rc) | 528 | if (rc) |
diff --git a/fs/ecryptfs/super.c b/fs/ecryptfs/super.c index f7fc286a3aa9..3042fe123a34 100644 --- a/fs/ecryptfs/super.c +++ b/fs/ecryptfs/super.c | |||
@@ -28,7 +28,6 @@ | |||
28 | #include <linux/key.h> | 28 | #include <linux/key.h> |
29 | #include <linux/slab.h> | 29 | #include <linux/slab.h> |
30 | #include <linux/seq_file.h> | 30 | #include <linux/seq_file.h> |
31 | #include <linux/smp_lock.h> | ||
32 | #include <linux/file.h> | 31 | #include <linux/file.h> |
33 | #include <linux/crypto.h> | 32 | #include <linux/crypto.h> |
34 | #include "ecryptfs_kernel.h" | 33 | #include "ecryptfs_kernel.h" |
@@ -63,6 +62,16 @@ out: | |||
63 | return inode; | 62 | return inode; |
64 | } | 63 | } |
65 | 64 | ||
65 | static void ecryptfs_i_callback(struct rcu_head *head) | ||
66 | { | ||
67 | struct inode *inode = container_of(head, struct inode, i_rcu); | ||
68 | struct ecryptfs_inode_info *inode_info; | ||
69 | inode_info = ecryptfs_inode_to_private(inode); | ||
70 | |||
71 | INIT_LIST_HEAD(&inode->i_dentry); | ||
72 | kmem_cache_free(ecryptfs_inode_info_cache, inode_info); | ||
73 | } | ||
74 | |||
66 | /** | 75 | /** |
67 | * ecryptfs_destroy_inode | 76 | * ecryptfs_destroy_inode |
68 | * @inode: The ecryptfs inode | 77 | * @inode: The ecryptfs inode |
@@ -89,7 +98,7 @@ static void ecryptfs_destroy_inode(struct inode *inode) | |||
89 | } | 98 | } |
90 | } | 99 | } |
91 | ecryptfs_destroy_crypt_stat(&inode_info->crypt_stat); | 100 | ecryptfs_destroy_crypt_stat(&inode_info->crypt_stat); |
92 | kmem_cache_free(ecryptfs_inode_info_cache, inode_info); | 101 | call_rcu(&inode->i_rcu, ecryptfs_i_callback); |
93 | } | 102 | } |
94 | 103 | ||
95 | /** | 104 | /** |
@@ -180,6 +189,8 @@ static int ecryptfs_show_options(struct seq_file *m, struct vfsmount *mnt) | |||
180 | seq_printf(m, ",ecryptfs_encrypted_view"); | 189 | seq_printf(m, ",ecryptfs_encrypted_view"); |
181 | if (mount_crypt_stat->flags & ECRYPTFS_UNLINK_SIGS) | 190 | if (mount_crypt_stat->flags & ECRYPTFS_UNLINK_SIGS) |
182 | seq_printf(m, ",ecryptfs_unlink_sigs"); | 191 | seq_printf(m, ",ecryptfs_unlink_sigs"); |
192 | if (mount_crypt_stat->flags & ECRYPTFS_GLOBAL_MOUNT_AUTH_TOK_ONLY) | ||
193 | seq_printf(m, ",ecryptfs_mount_auth_tok_only"); | ||
183 | 194 | ||
184 | return 0; | 195 | return 0; |
185 | } | 196 | } |