diff options
author | Andrea Bastoni <bastoni@cs.unc.edu> | 2010-05-30 19:16:45 -0400 |
---|---|---|
committer | Andrea Bastoni <bastoni@cs.unc.edu> | 2010-05-30 19:16:45 -0400 |
commit | ada47b5fe13d89735805b566185f4885f5a3f750 (patch) | |
tree | 644b88f8a71896307d71438e9b3af49126ffb22b /fs/ecryptfs | |
parent | 43e98717ad40a4ae64545b5ba047c7b86aa44f4f (diff) | |
parent | 3280f21d43ee541f97f8cda5792150d2dbec20d5 (diff) |
Merge branch 'wip-2.6.34' into old-private-masterarchived-private-master
Diffstat (limited to 'fs/ecryptfs')
-rw-r--r-- | fs/ecryptfs/crypto.c | 42 | ||||
-rw-r--r-- | fs/ecryptfs/dentry.c | 3 | ||||
-rw-r--r-- | fs/ecryptfs/ecryptfs_kernel.h | 15 | ||||
-rw-r--r-- | fs/ecryptfs/file.c | 18 | ||||
-rw-r--r-- | fs/ecryptfs/inode.c | 294 | ||||
-rw-r--r-- | fs/ecryptfs/keystore.c | 1 | ||||
-rw-r--r-- | fs/ecryptfs/kthread.c | 1 | ||||
-rw-r--r-- | fs/ecryptfs/main.c | 24 | ||||
-rw-r--r-- | fs/ecryptfs/messaging.c | 1 | ||||
-rw-r--r-- | fs/ecryptfs/miscdev.c | 1 | ||||
-rw-r--r-- | fs/ecryptfs/mmap.c | 39 | ||||
-rw-r--r-- | fs/ecryptfs/super.c | 3 |
12 files changed, 268 insertions, 174 deletions
diff --git a/fs/ecryptfs/crypto.c b/fs/ecryptfs/crypto.c index fbb6e5eed697..1cc087635a5e 100644 --- a/fs/ecryptfs/crypto.c +++ b/fs/ecryptfs/crypto.c | |||
@@ -33,6 +33,7 @@ | |||
33 | #include <linux/crypto.h> | 33 | #include <linux/crypto.h> |
34 | #include <linux/file.h> | 34 | #include <linux/file.h> |
35 | #include <linux/scatterlist.h> | 35 | #include <linux/scatterlist.h> |
36 | #include <linux/slab.h> | ||
36 | #include <asm/unaligned.h> | 37 | #include <asm/unaligned.h> |
37 | #include "ecryptfs_kernel.h" | 38 | #include "ecryptfs_kernel.h" |
38 | 39 | ||
@@ -381,8 +382,8 @@ out: | |||
381 | static void ecryptfs_lower_offset_for_extent(loff_t *offset, loff_t extent_num, | 382 | static void ecryptfs_lower_offset_for_extent(loff_t *offset, loff_t extent_num, |
382 | struct ecryptfs_crypt_stat *crypt_stat) | 383 | struct ecryptfs_crypt_stat *crypt_stat) |
383 | { | 384 | { |
384 | (*offset) = (crypt_stat->num_header_bytes_at_front | 385 | (*offset) = ecryptfs_lower_header_size(crypt_stat) |
385 | + (crypt_stat->extent_size * extent_num)); | 386 | + (crypt_stat->extent_size * extent_num); |
386 | } | 387 | } |
387 | 388 | ||
388 | /** | 389 | /** |
@@ -834,13 +835,13 @@ void ecryptfs_set_default_sizes(struct ecryptfs_crypt_stat *crypt_stat) | |||
834 | set_extent_mask_and_shift(crypt_stat); | 835 | set_extent_mask_and_shift(crypt_stat); |
835 | crypt_stat->iv_bytes = ECRYPTFS_DEFAULT_IV_BYTES; | 836 | crypt_stat->iv_bytes = ECRYPTFS_DEFAULT_IV_BYTES; |
836 | if (crypt_stat->flags & ECRYPTFS_METADATA_IN_XATTR) | 837 | if (crypt_stat->flags & ECRYPTFS_METADATA_IN_XATTR) |
837 | crypt_stat->num_header_bytes_at_front = 0; | 838 | crypt_stat->metadata_size = ECRYPTFS_MINIMUM_HEADER_EXTENT_SIZE; |
838 | else { | 839 | else { |
839 | if (PAGE_CACHE_SIZE <= ECRYPTFS_MINIMUM_HEADER_EXTENT_SIZE) | 840 | if (PAGE_CACHE_SIZE <= ECRYPTFS_MINIMUM_HEADER_EXTENT_SIZE) |
840 | crypt_stat->num_header_bytes_at_front = | 841 | crypt_stat->metadata_size = |
841 | ECRYPTFS_MINIMUM_HEADER_EXTENT_SIZE; | 842 | ECRYPTFS_MINIMUM_HEADER_EXTENT_SIZE; |
842 | else | 843 | else |
843 | crypt_stat->num_header_bytes_at_front = PAGE_CACHE_SIZE; | 844 | crypt_stat->metadata_size = PAGE_CACHE_SIZE; |
844 | } | 845 | } |
845 | } | 846 | } |
846 | 847 | ||
@@ -1107,9 +1108,9 @@ static void write_ecryptfs_marker(char *page_virt, size_t *written) | |||
1107 | (*written) = MAGIC_ECRYPTFS_MARKER_SIZE_BYTES; | 1108 | (*written) = MAGIC_ECRYPTFS_MARKER_SIZE_BYTES; |
1108 | } | 1109 | } |
1109 | 1110 | ||
1110 | static void | 1111 | void ecryptfs_write_crypt_stat_flags(char *page_virt, |
1111 | write_ecryptfs_flags(char *page_virt, struct ecryptfs_crypt_stat *crypt_stat, | 1112 | struct ecryptfs_crypt_stat *crypt_stat, |
1112 | size_t *written) | 1113 | size_t *written) |
1113 | { | 1114 | { |
1114 | u32 flags = 0; | 1115 | u32 flags = 0; |
1115 | int i; | 1116 | int i; |
@@ -1237,8 +1238,7 @@ ecryptfs_write_header_metadata(char *virt, | |||
1237 | 1238 | ||
1238 | header_extent_size = (u32)crypt_stat->extent_size; | 1239 | header_extent_size = (u32)crypt_stat->extent_size; |
1239 | num_header_extents_at_front = | 1240 | num_header_extents_at_front = |
1240 | (u16)(crypt_stat->num_header_bytes_at_front | 1241 | (u16)(crypt_stat->metadata_size / crypt_stat->extent_size); |
1241 | / crypt_stat->extent_size); | ||
1242 | put_unaligned_be32(header_extent_size, virt); | 1242 | put_unaligned_be32(header_extent_size, virt); |
1243 | virt += 4; | 1243 | virt += 4; |
1244 | put_unaligned_be16(num_header_extents_at_front, virt); | 1244 | put_unaligned_be16(num_header_extents_at_front, virt); |
@@ -1291,7 +1291,8 @@ static int ecryptfs_write_headers_virt(char *page_virt, size_t max, | |||
1291 | offset = ECRYPTFS_FILE_SIZE_BYTES; | 1291 | offset = ECRYPTFS_FILE_SIZE_BYTES; |
1292 | write_ecryptfs_marker((page_virt + offset), &written); | 1292 | write_ecryptfs_marker((page_virt + offset), &written); |
1293 | offset += written; | 1293 | offset += written; |
1294 | write_ecryptfs_flags((page_virt + offset), crypt_stat, &written); | 1294 | ecryptfs_write_crypt_stat_flags((page_virt + offset), crypt_stat, |
1295 | &written); | ||
1295 | offset += written; | 1296 | offset += written; |
1296 | ecryptfs_write_header_metadata((page_virt + offset), crypt_stat, | 1297 | ecryptfs_write_header_metadata((page_virt + offset), crypt_stat, |
1297 | &written); | 1298 | &written); |
@@ -1381,7 +1382,7 @@ int ecryptfs_write_metadata(struct dentry *ecryptfs_dentry) | |||
1381 | rc = -EINVAL; | 1382 | rc = -EINVAL; |
1382 | goto out; | 1383 | goto out; |
1383 | } | 1384 | } |
1384 | virt_len = crypt_stat->num_header_bytes_at_front; | 1385 | virt_len = crypt_stat->metadata_size; |
1385 | order = get_order(virt_len); | 1386 | order = get_order(virt_len); |
1386 | /* Released in this function */ | 1387 | /* Released in this function */ |
1387 | virt = (char *)ecryptfs_get_zeroed_pages(GFP_KERNEL, order); | 1388 | virt = (char *)ecryptfs_get_zeroed_pages(GFP_KERNEL, order); |
@@ -1427,16 +1428,15 @@ static int parse_header_metadata(struct ecryptfs_crypt_stat *crypt_stat, | |||
1427 | header_extent_size = get_unaligned_be32(virt); | 1428 | header_extent_size = get_unaligned_be32(virt); |
1428 | virt += sizeof(__be32); | 1429 | virt += sizeof(__be32); |
1429 | num_header_extents_at_front = get_unaligned_be16(virt); | 1430 | num_header_extents_at_front = get_unaligned_be16(virt); |
1430 | crypt_stat->num_header_bytes_at_front = | 1431 | crypt_stat->metadata_size = (((size_t)num_header_extents_at_front |
1431 | (((size_t)num_header_extents_at_front | 1432 | * (size_t)header_extent_size)); |
1432 | * (size_t)header_extent_size)); | ||
1433 | (*bytes_read) = (sizeof(__be32) + sizeof(__be16)); | 1433 | (*bytes_read) = (sizeof(__be32) + sizeof(__be16)); |
1434 | if ((validate_header_size == ECRYPTFS_VALIDATE_HEADER_SIZE) | 1434 | if ((validate_header_size == ECRYPTFS_VALIDATE_HEADER_SIZE) |
1435 | && (crypt_stat->num_header_bytes_at_front | 1435 | && (crypt_stat->metadata_size |
1436 | < ECRYPTFS_MINIMUM_HEADER_EXTENT_SIZE)) { | 1436 | < ECRYPTFS_MINIMUM_HEADER_EXTENT_SIZE)) { |
1437 | rc = -EINVAL; | 1437 | rc = -EINVAL; |
1438 | printk(KERN_WARNING "Invalid header size: [%zd]\n", | 1438 | printk(KERN_WARNING "Invalid header size: [%zd]\n", |
1439 | crypt_stat->num_header_bytes_at_front); | 1439 | crypt_stat->metadata_size); |
1440 | } | 1440 | } |
1441 | return rc; | 1441 | return rc; |
1442 | } | 1442 | } |
@@ -1451,8 +1451,7 @@ static int parse_header_metadata(struct ecryptfs_crypt_stat *crypt_stat, | |||
1451 | */ | 1451 | */ |
1452 | static void set_default_header_data(struct ecryptfs_crypt_stat *crypt_stat) | 1452 | static void set_default_header_data(struct ecryptfs_crypt_stat *crypt_stat) |
1453 | { | 1453 | { |
1454 | crypt_stat->num_header_bytes_at_front = | 1454 | crypt_stat->metadata_size = ECRYPTFS_MINIMUM_HEADER_EXTENT_SIZE; |
1455 | ECRYPTFS_MINIMUM_HEADER_EXTENT_SIZE; | ||
1456 | } | 1455 | } |
1457 | 1456 | ||
1458 | /** | 1457 | /** |
@@ -1606,6 +1605,7 @@ int ecryptfs_read_metadata(struct dentry *ecryptfs_dentry) | |||
1606 | ecryptfs_dentry, | 1605 | ecryptfs_dentry, |
1607 | ECRYPTFS_VALIDATE_HEADER_SIZE); | 1606 | ECRYPTFS_VALIDATE_HEADER_SIZE); |
1608 | if (rc) { | 1607 | if (rc) { |
1608 | memset(page_virt, 0, PAGE_CACHE_SIZE); | ||
1609 | rc = ecryptfs_read_xattr_region(page_virt, ecryptfs_inode); | 1609 | rc = ecryptfs_read_xattr_region(page_virt, ecryptfs_inode); |
1610 | if (rc) { | 1610 | if (rc) { |
1611 | printk(KERN_DEBUG "Valid eCryptfs headers not found in " | 1611 | printk(KERN_DEBUG "Valid eCryptfs headers not found in " |
@@ -1748,7 +1748,7 @@ ecryptfs_process_key_cipher(struct crypto_blkcipher **key_tfm, | |||
1748 | char *cipher_name, size_t *key_size) | 1748 | char *cipher_name, size_t *key_size) |
1749 | { | 1749 | { |
1750 | char dummy_key[ECRYPTFS_MAX_KEY_BYTES]; | 1750 | char dummy_key[ECRYPTFS_MAX_KEY_BYTES]; |
1751 | char *full_alg_name; | 1751 | char *full_alg_name = NULL; |
1752 | int rc; | 1752 | int rc; |
1753 | 1753 | ||
1754 | *key_tfm = NULL; | 1754 | *key_tfm = NULL; |
@@ -1763,7 +1763,6 @@ ecryptfs_process_key_cipher(struct crypto_blkcipher **key_tfm, | |||
1763 | if (rc) | 1763 | if (rc) |
1764 | goto out; | 1764 | goto out; |
1765 | *key_tfm = crypto_alloc_blkcipher(full_alg_name, 0, CRYPTO_ALG_ASYNC); | 1765 | *key_tfm = crypto_alloc_blkcipher(full_alg_name, 0, CRYPTO_ALG_ASYNC); |
1766 | kfree(full_alg_name); | ||
1767 | if (IS_ERR(*key_tfm)) { | 1766 | if (IS_ERR(*key_tfm)) { |
1768 | rc = PTR_ERR(*key_tfm); | 1767 | rc = PTR_ERR(*key_tfm); |
1769 | printk(KERN_ERR "Unable to allocate crypto cipher with name " | 1768 | printk(KERN_ERR "Unable to allocate crypto cipher with name " |
@@ -1786,6 +1785,7 @@ ecryptfs_process_key_cipher(struct crypto_blkcipher **key_tfm, | |||
1786 | goto out; | 1785 | goto out; |
1787 | } | 1786 | } |
1788 | out: | 1787 | out: |
1788 | kfree(full_alg_name); | ||
1789 | return rc; | 1789 | return rc; |
1790 | } | 1790 | } |
1791 | 1791 | ||
diff --git a/fs/ecryptfs/dentry.c b/fs/ecryptfs/dentry.c index 2dda5ade75bc..906e803f7f79 100644 --- a/fs/ecryptfs/dentry.c +++ b/fs/ecryptfs/dentry.c | |||
@@ -26,6 +26,7 @@ | |||
26 | #include <linux/namei.h> | 26 | #include <linux/namei.h> |
27 | #include <linux/mount.h> | 27 | #include <linux/mount.h> |
28 | #include <linux/fs_stack.h> | 28 | #include <linux/fs_stack.h> |
29 | #include <linux/slab.h> | ||
29 | #include "ecryptfs_kernel.h" | 30 | #include "ecryptfs_kernel.h" |
30 | 31 | ||
31 | /** | 32 | /** |
@@ -62,7 +63,7 @@ static int ecryptfs_d_revalidate(struct dentry *dentry, struct nameidata *nd) | |||
62 | struct inode *lower_inode = | 63 | struct inode *lower_inode = |
63 | ecryptfs_inode_to_lower(dentry->d_inode); | 64 | ecryptfs_inode_to_lower(dentry->d_inode); |
64 | 65 | ||
65 | fsstack_copy_attr_all(dentry->d_inode, lower_inode, NULL); | 66 | fsstack_copy_attr_all(dentry->d_inode, lower_inode); |
66 | } | 67 | } |
67 | out: | 68 | out: |
68 | return rc; | 69 | return rc; |
diff --git a/fs/ecryptfs/ecryptfs_kernel.h b/fs/ecryptfs/ecryptfs_kernel.h index 542f625312f3..bfc2e0f78f00 100644 --- a/fs/ecryptfs/ecryptfs_kernel.h +++ b/fs/ecryptfs/ecryptfs_kernel.h | |||
@@ -35,6 +35,7 @@ | |||
35 | #include <linux/scatterlist.h> | 35 | #include <linux/scatterlist.h> |
36 | #include <linux/hash.h> | 36 | #include <linux/hash.h> |
37 | #include <linux/nsproxy.h> | 37 | #include <linux/nsproxy.h> |
38 | #include <linux/backing-dev.h> | ||
38 | 39 | ||
39 | /* Version verification for shared data structures w/ userspace */ | 40 | /* Version verification for shared data structures w/ userspace */ |
40 | #define ECRYPTFS_VERSION_MAJOR 0x00 | 41 | #define ECRYPTFS_VERSION_MAJOR 0x00 |
@@ -273,7 +274,7 @@ struct ecryptfs_crypt_stat { | |||
273 | u32 flags; | 274 | u32 flags; |
274 | unsigned int file_version; | 275 | unsigned int file_version; |
275 | size_t iv_bytes; | 276 | size_t iv_bytes; |
276 | size_t num_header_bytes_at_front; | 277 | size_t metadata_size; |
277 | size_t extent_size; /* Data extent size; default is 4096 */ | 278 | size_t extent_size; /* Data extent size; default is 4096 */ |
278 | size_t key_size; | 279 | size_t key_size; |
279 | size_t extent_shift; | 280 | size_t extent_shift; |
@@ -393,6 +394,7 @@ struct ecryptfs_mount_crypt_stat { | |||
393 | struct ecryptfs_sb_info { | 394 | struct ecryptfs_sb_info { |
394 | struct super_block *wsi_sb; | 395 | struct super_block *wsi_sb; |
395 | struct ecryptfs_mount_crypt_stat mount_crypt_stat; | 396 | struct ecryptfs_mount_crypt_stat mount_crypt_stat; |
397 | struct backing_dev_info bdi; | ||
396 | }; | 398 | }; |
397 | 399 | ||
398 | /* file private data. */ | 400 | /* file private data. */ |
@@ -464,6 +466,14 @@ struct ecryptfs_daemon { | |||
464 | 466 | ||
465 | extern struct mutex ecryptfs_daemon_hash_mux; | 467 | extern struct mutex ecryptfs_daemon_hash_mux; |
466 | 468 | ||
469 | static inline size_t | ||
470 | ecryptfs_lower_header_size(struct ecryptfs_crypt_stat *crypt_stat) | ||
471 | { | ||
472 | if (crypt_stat->flags & ECRYPTFS_METADATA_IN_XATTR) | ||
473 | return 0; | ||
474 | return crypt_stat->metadata_size; | ||
475 | } | ||
476 | |||
467 | static inline struct ecryptfs_file_info * | 477 | static inline struct ecryptfs_file_info * |
468 | ecryptfs_file_to_private(struct file *file) | 478 | ecryptfs_file_to_private(struct file *file) |
469 | { | 479 | { |
@@ -651,6 +661,9 @@ int ecryptfs_decrypt_page(struct page *page); | |||
651 | int ecryptfs_write_metadata(struct dentry *ecryptfs_dentry); | 661 | int ecryptfs_write_metadata(struct dentry *ecryptfs_dentry); |
652 | int ecryptfs_read_metadata(struct dentry *ecryptfs_dentry); | 662 | int ecryptfs_read_metadata(struct dentry *ecryptfs_dentry); |
653 | int ecryptfs_new_file_context(struct dentry *ecryptfs_dentry); | 663 | int ecryptfs_new_file_context(struct dentry *ecryptfs_dentry); |
664 | void ecryptfs_write_crypt_stat_flags(char *page_virt, | ||
665 | struct ecryptfs_crypt_stat *crypt_stat, | ||
666 | size_t *written); | ||
654 | int ecryptfs_read_and_validate_header_region(char *data, | 667 | int ecryptfs_read_and_validate_header_region(char *data, |
655 | struct inode *ecryptfs_inode); | 668 | struct inode *ecryptfs_inode); |
656 | int ecryptfs_read_and_validate_xattr_region(char *page_virt, | 669 | int ecryptfs_read_and_validate_xattr_region(char *page_virt, |
diff --git a/fs/ecryptfs/file.c b/fs/ecryptfs/file.c index 9e944057001b..e7440a6f5ebf 100644 --- a/fs/ecryptfs/file.c +++ b/fs/ecryptfs/file.c | |||
@@ -25,6 +25,7 @@ | |||
25 | 25 | ||
26 | #include <linux/file.h> | 26 | #include <linux/file.h> |
27 | #include <linux/poll.h> | 27 | #include <linux/poll.h> |
28 | #include <linux/slab.h> | ||
28 | #include <linux/mount.h> | 29 | #include <linux/mount.h> |
29 | #include <linux/pagemap.h> | 30 | #include <linux/pagemap.h> |
30 | #include <linux/security.h> | 31 | #include <linux/security.h> |
@@ -158,7 +159,7 @@ static int ecryptfs_open(struct inode *inode, struct file *file) | |||
158 | struct dentry *ecryptfs_dentry = file->f_path.dentry; | 159 | struct dentry *ecryptfs_dentry = file->f_path.dentry; |
159 | /* Private value of ecryptfs_dentry allocated in | 160 | /* Private value of ecryptfs_dentry allocated in |
160 | * ecryptfs_lookup() */ | 161 | * ecryptfs_lookup() */ |
161 | struct dentry *lower_dentry = ecryptfs_dentry_to_lower(ecryptfs_dentry); | 162 | struct dentry *lower_dentry; |
162 | struct ecryptfs_file_info *file_info; | 163 | struct ecryptfs_file_info *file_info; |
163 | 164 | ||
164 | mount_crypt_stat = &ecryptfs_superblock_to_private( | 165 | mount_crypt_stat = &ecryptfs_superblock_to_private( |
@@ -191,13 +192,6 @@ static int ecryptfs_open(struct inode *inode, struct file *file) | |||
191 | | ECRYPTFS_ENCRYPTED); | 192 | | ECRYPTFS_ENCRYPTED); |
192 | } | 193 | } |
193 | mutex_unlock(&crypt_stat->cs_mutex); | 194 | mutex_unlock(&crypt_stat->cs_mutex); |
194 | if ((ecryptfs_inode_to_private(inode)->lower_file->f_flags & O_RDONLY) | ||
195 | && !(file->f_flags & O_RDONLY)) { | ||
196 | rc = -EPERM; | ||
197 | printk(KERN_WARNING "%s: Lower persistent file is RO; eCryptfs " | ||
198 | "file must hence be opened RO\n", __func__); | ||
199 | goto out; | ||
200 | } | ||
201 | if (!ecryptfs_inode_to_private(inode)->lower_file) { | 195 | if (!ecryptfs_inode_to_private(inode)->lower_file) { |
202 | rc = ecryptfs_init_persistent_file(ecryptfs_dentry); | 196 | rc = ecryptfs_init_persistent_file(ecryptfs_dentry); |
203 | if (rc) { | 197 | if (rc) { |
@@ -208,6 +202,13 @@ static int ecryptfs_open(struct inode *inode, struct file *file) | |||
208 | goto out; | 202 | goto out; |
209 | } | 203 | } |
210 | } | 204 | } |
205 | if ((ecryptfs_inode_to_private(inode)->lower_file->f_flags & O_RDONLY) | ||
206 | && !(file->f_flags & O_RDONLY)) { | ||
207 | rc = -EPERM; | ||
208 | printk(KERN_WARNING "%s: Lower persistent file is RO; eCryptfs " | ||
209 | "file must hence be opened RO\n", __func__); | ||
210 | goto out; | ||
211 | } | ||
211 | ecryptfs_set_file_lower( | 212 | ecryptfs_set_file_lower( |
212 | file, ecryptfs_inode_to_private(inode)->lower_file); | 213 | file, ecryptfs_inode_to_private(inode)->lower_file); |
213 | if (S_ISDIR(ecryptfs_dentry->d_inode->i_mode)) { | 214 | if (S_ISDIR(ecryptfs_dentry->d_inode->i_mode)) { |
@@ -299,7 +300,6 @@ static int ecryptfs_ioctl(struct inode *inode, struct file *file, | |||
299 | const struct file_operations ecryptfs_dir_fops = { | 300 | const struct file_operations ecryptfs_dir_fops = { |
300 | .readdir = ecryptfs_readdir, | 301 | .readdir = ecryptfs_readdir, |
301 | .ioctl = ecryptfs_ioctl, | 302 | .ioctl = ecryptfs_ioctl, |
302 | .mmap = generic_file_mmap, | ||
303 | .open = ecryptfs_open, | 303 | .open = ecryptfs_open, |
304 | .flush = ecryptfs_flush, | 304 | .flush = ecryptfs_flush, |
305 | .release = ecryptfs_release, | 305 | .release = ecryptfs_release, |
diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c index 056fed62d0de..e2d4418affac 100644 --- a/fs/ecryptfs/inode.c +++ b/fs/ecryptfs/inode.c | |||
@@ -31,6 +31,7 @@ | |||
31 | #include <linux/mount.h> | 31 | #include <linux/mount.h> |
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 <asm/unaligned.h> | 35 | #include <asm/unaligned.h> |
35 | #include "ecryptfs_kernel.h" | 36 | #include "ecryptfs_kernel.h" |
36 | 37 | ||
@@ -282,7 +283,8 @@ int ecryptfs_lookup_and_interpose_lower(struct dentry *ecryptfs_dentry, | |||
282 | goto out; | 283 | goto out; |
283 | } | 284 | } |
284 | rc = ecryptfs_interpose(lower_dentry, ecryptfs_dentry, | 285 | rc = ecryptfs_interpose(lower_dentry, ecryptfs_dentry, |
285 | ecryptfs_dir_inode->i_sb, 1); | 286 | ecryptfs_dir_inode->i_sb, |
287 | ECRYPTFS_INTERPOSE_FLAG_D_ADD); | ||
286 | if (rc) { | 288 | if (rc) { |
287 | printk(KERN_ERR "%s: Error interposing; rc = [%d]\n", | 289 | printk(KERN_ERR "%s: Error interposing; rc = [%d]\n", |
288 | __func__, rc); | 290 | __func__, rc); |
@@ -322,6 +324,7 @@ int ecryptfs_lookup_and_interpose_lower(struct dentry *ecryptfs_dentry, | |||
322 | rc = ecryptfs_read_and_validate_header_region(page_virt, | 324 | rc = ecryptfs_read_and_validate_header_region(page_virt, |
323 | ecryptfs_dentry->d_inode); | 325 | ecryptfs_dentry->d_inode); |
324 | if (rc) { | 326 | if (rc) { |
327 | memset(page_virt, 0, PAGE_CACHE_SIZE); | ||
325 | rc = ecryptfs_read_and_validate_xattr_region(page_virt, | 328 | rc = ecryptfs_read_and_validate_xattr_region(page_virt, |
326 | ecryptfs_dentry); | 329 | ecryptfs_dentry); |
327 | if (rc) { | 330 | if (rc) { |
@@ -334,7 +337,7 @@ int ecryptfs_lookup_and_interpose_lower(struct dentry *ecryptfs_dentry, | |||
334 | ecryptfs_dentry->d_sb)->mount_crypt_stat; | 337 | ecryptfs_dentry->d_sb)->mount_crypt_stat; |
335 | if (mount_crypt_stat->flags & ECRYPTFS_ENCRYPTED_VIEW_ENABLED) { | 338 | if (mount_crypt_stat->flags & ECRYPTFS_ENCRYPTED_VIEW_ENABLED) { |
336 | if (crypt_stat->flags & ECRYPTFS_METADATA_IN_XATTR) | 339 | if (crypt_stat->flags & ECRYPTFS_METADATA_IN_XATTR) |
337 | file_size = (crypt_stat->num_header_bytes_at_front | 340 | file_size = (crypt_stat->metadata_size |
338 | + i_size_read(lower_dentry->d_inode)); | 341 | + i_size_read(lower_dentry->d_inode)); |
339 | else | 342 | else |
340 | file_size = i_size_read(lower_dentry->d_inode); | 343 | file_size = i_size_read(lower_dentry->d_inode); |
@@ -386,9 +389,9 @@ static struct dentry *ecryptfs_lookup(struct inode *ecryptfs_dir_inode, | |||
386 | mutex_unlock(&lower_dir_dentry->d_inode->i_mutex); | 389 | mutex_unlock(&lower_dir_dentry->d_inode->i_mutex); |
387 | if (IS_ERR(lower_dentry)) { | 390 | if (IS_ERR(lower_dentry)) { |
388 | rc = PTR_ERR(lower_dentry); | 391 | rc = PTR_ERR(lower_dentry); |
389 | printk(KERN_ERR "%s: lookup_one_len() returned [%d] on " | 392 | ecryptfs_printk(KERN_DEBUG, "%s: lookup_one_len() returned " |
390 | "lower_dentry = [%s]\n", __func__, rc, | 393 | "[%d] on lower_dentry = [%s]\n", __func__, rc, |
391 | ecryptfs_dentry->d_name.name); | 394 | encrypted_and_encoded_name); |
392 | goto out_d_drop; | 395 | goto out_d_drop; |
393 | } | 396 | } |
394 | if (lower_dentry->d_inode) | 397 | if (lower_dentry->d_inode) |
@@ -415,9 +418,9 @@ static struct dentry *ecryptfs_lookup(struct inode *ecryptfs_dir_inode, | |||
415 | mutex_unlock(&lower_dir_dentry->d_inode->i_mutex); | 418 | mutex_unlock(&lower_dir_dentry->d_inode->i_mutex); |
416 | if (IS_ERR(lower_dentry)) { | 419 | if (IS_ERR(lower_dentry)) { |
417 | rc = PTR_ERR(lower_dentry); | 420 | rc = PTR_ERR(lower_dentry); |
418 | printk(KERN_ERR "%s: lookup_one_len() returned [%d] on " | 421 | ecryptfs_printk(KERN_DEBUG, "%s: lookup_one_len() returned " |
419 | "lower_dentry = [%s]\n", __func__, rc, | 422 | "[%d] on lower_dentry = [%s]\n", __func__, rc, |
420 | encrypted_and_encoded_name); | 423 | encrypted_and_encoded_name); |
421 | goto out_d_drop; | 424 | goto out_d_drop; |
422 | } | 425 | } |
423 | lookup_and_interpose: | 426 | lookup_and_interpose: |
@@ -454,8 +457,8 @@ static int ecryptfs_link(struct dentry *old_dentry, struct inode *dir, | |||
454 | rc = ecryptfs_interpose(lower_new_dentry, new_dentry, dir->i_sb, 0); | 457 | rc = ecryptfs_interpose(lower_new_dentry, new_dentry, dir->i_sb, 0); |
455 | if (rc) | 458 | if (rc) |
456 | goto out_lock; | 459 | goto out_lock; |
457 | fsstack_copy_attr_times(dir, lower_new_dentry->d_inode); | 460 | fsstack_copy_attr_times(dir, lower_dir_dentry->d_inode); |
458 | fsstack_copy_inode_size(dir, lower_new_dentry->d_inode); | 461 | fsstack_copy_inode_size(dir, lower_dir_dentry->d_inode); |
459 | old_dentry->d_inode->i_nlink = | 462 | old_dentry->d_inode->i_nlink = |
460 | ecryptfs_inode_to_lower(old_dentry->d_inode)->i_nlink; | 463 | ecryptfs_inode_to_lower(old_dentry->d_inode)->i_nlink; |
461 | i_size_write(new_dentry->d_inode, file_size_save); | 464 | i_size_write(new_dentry->d_inode, file_size_save); |
@@ -463,9 +466,6 @@ out_lock: | |||
463 | unlock_dir(lower_dir_dentry); | 466 | unlock_dir(lower_dir_dentry); |
464 | dput(lower_new_dentry); | 467 | dput(lower_new_dentry); |
465 | dput(lower_old_dentry); | 468 | dput(lower_old_dentry); |
466 | d_drop(lower_old_dentry); | ||
467 | d_drop(new_dentry); | ||
468 | d_drop(old_dentry); | ||
469 | return rc; | 469 | return rc; |
470 | } | 470 | } |
471 | 471 | ||
@@ -614,6 +614,7 @@ ecryptfs_rename(struct inode *old_dir, struct dentry *old_dentry, | |||
614 | struct dentry *lower_new_dentry; | 614 | struct dentry *lower_new_dentry; |
615 | struct dentry *lower_old_dir_dentry; | 615 | struct dentry *lower_old_dir_dentry; |
616 | struct dentry *lower_new_dir_dentry; | 616 | struct dentry *lower_new_dir_dentry; |
617 | struct dentry *trap = NULL; | ||
617 | 618 | ||
618 | lower_old_dentry = ecryptfs_dentry_to_lower(old_dentry); | 619 | lower_old_dentry = ecryptfs_dentry_to_lower(old_dentry); |
619 | lower_new_dentry = ecryptfs_dentry_to_lower(new_dentry); | 620 | lower_new_dentry = ecryptfs_dentry_to_lower(new_dentry); |
@@ -621,14 +622,24 @@ ecryptfs_rename(struct inode *old_dir, struct dentry *old_dentry, | |||
621 | dget(lower_new_dentry); | 622 | dget(lower_new_dentry); |
622 | lower_old_dir_dentry = dget_parent(lower_old_dentry); | 623 | lower_old_dir_dentry = dget_parent(lower_old_dentry); |
623 | lower_new_dir_dentry = dget_parent(lower_new_dentry); | 624 | lower_new_dir_dentry = dget_parent(lower_new_dentry); |
624 | lock_rename(lower_old_dir_dentry, lower_new_dir_dentry); | 625 | trap = lock_rename(lower_old_dir_dentry, lower_new_dir_dentry); |
626 | /* source should not be ancestor of target */ | ||
627 | if (trap == lower_old_dentry) { | ||
628 | rc = -EINVAL; | ||
629 | goto out_lock; | ||
630 | } | ||
631 | /* target should not be ancestor of source */ | ||
632 | if (trap == lower_new_dentry) { | ||
633 | rc = -ENOTEMPTY; | ||
634 | goto out_lock; | ||
635 | } | ||
625 | rc = vfs_rename(lower_old_dir_dentry->d_inode, lower_old_dentry, | 636 | rc = vfs_rename(lower_old_dir_dentry->d_inode, lower_old_dentry, |
626 | lower_new_dir_dentry->d_inode, lower_new_dentry); | 637 | lower_new_dir_dentry->d_inode, lower_new_dentry); |
627 | if (rc) | 638 | if (rc) |
628 | goto out_lock; | 639 | goto out_lock; |
629 | fsstack_copy_attr_all(new_dir, lower_new_dir_dentry->d_inode, NULL); | 640 | fsstack_copy_attr_all(new_dir, lower_new_dir_dentry->d_inode); |
630 | if (new_dir != old_dir) | 641 | if (new_dir != old_dir) |
631 | fsstack_copy_attr_all(old_dir, lower_old_dir_dentry->d_inode, NULL); | 642 | fsstack_copy_attr_all(old_dir, lower_old_dir_dentry->d_inode); |
632 | out_lock: | 643 | out_lock: |
633 | unlock_rename(lower_old_dir_dentry, lower_new_dir_dentry); | 644 | unlock_rename(lower_old_dir_dentry, lower_new_dir_dentry); |
634 | dput(lower_new_dentry->d_parent); | 645 | dput(lower_new_dentry->d_parent); |
@@ -638,38 +649,17 @@ out_lock: | |||
638 | return rc; | 649 | return rc; |
639 | } | 650 | } |
640 | 651 | ||
641 | static int | 652 | static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf, |
642 | ecryptfs_readlink(struct dentry *dentry, char __user *buf, int bufsiz) | 653 | size_t *bufsiz) |
643 | { | 654 | { |
655 | struct dentry *lower_dentry = ecryptfs_dentry_to_lower(dentry); | ||
644 | char *lower_buf; | 656 | char *lower_buf; |
645 | size_t lower_bufsiz; | 657 | size_t lower_bufsiz = PATH_MAX; |
646 | struct dentry *lower_dentry; | ||
647 | struct ecryptfs_mount_crypt_stat *mount_crypt_stat; | ||
648 | char *plaintext_name; | ||
649 | size_t plaintext_name_size; | ||
650 | mm_segment_t old_fs; | 658 | mm_segment_t old_fs; |
651 | int rc; | 659 | int rc; |
652 | 660 | ||
653 | lower_dentry = ecryptfs_dentry_to_lower(dentry); | ||
654 | if (!lower_dentry->d_inode->i_op->readlink) { | ||
655 | rc = -EINVAL; | ||
656 | goto out; | ||
657 | } | ||
658 | mount_crypt_stat = &ecryptfs_superblock_to_private( | ||
659 | dentry->d_sb)->mount_crypt_stat; | ||
660 | /* | ||
661 | * If the lower filename is encrypted, it will result in a significantly | ||
662 | * longer name. If needed, truncate the name after decode and decrypt. | ||
663 | */ | ||
664 | if (mount_crypt_stat->flags & ECRYPTFS_GLOBAL_ENCRYPT_FILENAMES) | ||
665 | lower_bufsiz = PATH_MAX; | ||
666 | else | ||
667 | lower_bufsiz = bufsiz; | ||
668 | /* Released in this function */ | ||
669 | lower_buf = kmalloc(lower_bufsiz, GFP_KERNEL); | 661 | lower_buf = kmalloc(lower_bufsiz, GFP_KERNEL); |
670 | if (lower_buf == NULL) { | 662 | if (!lower_buf) { |
671 | printk(KERN_ERR "%s: Out of memory whilst attempting to " | ||
672 | "kmalloc [%zd] bytes\n", __func__, lower_bufsiz); | ||
673 | rc = -ENOMEM; | 663 | rc = -ENOMEM; |
674 | goto out; | 664 | goto out; |
675 | } | 665 | } |
@@ -679,29 +669,31 @@ ecryptfs_readlink(struct dentry *dentry, char __user *buf, int bufsiz) | |||
679 | (char __user *)lower_buf, | 669 | (char __user *)lower_buf, |
680 | lower_bufsiz); | 670 | lower_bufsiz); |
681 | set_fs(old_fs); | 671 | set_fs(old_fs); |
682 | if (rc >= 0) { | 672 | if (rc < 0) |
683 | rc = ecryptfs_decode_and_decrypt_filename(&plaintext_name, | 673 | goto out; |
684 | &plaintext_name_size, | 674 | lower_bufsiz = rc; |
685 | dentry, lower_buf, | 675 | rc = ecryptfs_decode_and_decrypt_filename(buf, bufsiz, dentry, |
686 | rc); | 676 | lower_buf, lower_bufsiz); |
687 | if (rc) { | 677 | out: |
688 | printk(KERN_ERR "%s: Error attempting to decode and " | ||
689 | "decrypt filename; rc = [%d]\n", __func__, | ||
690 | rc); | ||
691 | goto out_free_lower_buf; | ||
692 | } | ||
693 | /* Check for bufsiz <= 0 done in sys_readlinkat() */ | ||
694 | rc = copy_to_user(buf, plaintext_name, | ||
695 | min((size_t) bufsiz, plaintext_name_size)); | ||
696 | if (rc) | ||
697 | rc = -EFAULT; | ||
698 | else | ||
699 | rc = plaintext_name_size; | ||
700 | kfree(plaintext_name); | ||
701 | fsstack_copy_attr_atime(dentry->d_inode, lower_dentry->d_inode); | ||
702 | } | ||
703 | out_free_lower_buf: | ||
704 | kfree(lower_buf); | 678 | kfree(lower_buf); |
679 | return rc; | ||
680 | } | ||
681 | |||
682 | static int | ||
683 | ecryptfs_readlink(struct dentry *dentry, char __user *buf, int bufsiz) | ||
684 | { | ||
685 | char *kbuf; | ||
686 | size_t kbufsiz, copied; | ||
687 | int rc; | ||
688 | |||
689 | rc = ecryptfs_readlink_lower(dentry, &kbuf, &kbufsiz); | ||
690 | if (rc) | ||
691 | goto out; | ||
692 | copied = min_t(size_t, bufsiz, kbufsiz); | ||
693 | rc = copy_to_user(buf, kbuf, copied) ? -EFAULT : copied; | ||
694 | kfree(kbuf); | ||
695 | fsstack_copy_attr_atime(dentry->d_inode, | ||
696 | ecryptfs_dentry_to_lower(dentry)->d_inode); | ||
705 | out: | 697 | out: |
706 | return rc; | 698 | return rc; |
707 | } | 699 | } |
@@ -715,31 +707,31 @@ static void *ecryptfs_follow_link(struct dentry *dentry, struct nameidata *nd) | |||
715 | /* Released in ecryptfs_put_link(); only release here on error */ | 707 | /* Released in ecryptfs_put_link(); only release here on error */ |
716 | buf = kmalloc(len, GFP_KERNEL); | 708 | buf = kmalloc(len, GFP_KERNEL); |
717 | if (!buf) { | 709 | if (!buf) { |
718 | rc = -ENOMEM; | 710 | buf = ERR_PTR(-ENOMEM); |
719 | goto out; | 711 | goto out; |
720 | } | 712 | } |
721 | old_fs = get_fs(); | 713 | old_fs = get_fs(); |
722 | set_fs(get_ds()); | 714 | set_fs(get_ds()); |
723 | rc = dentry->d_inode->i_op->readlink(dentry, (char __user *)buf, len); | 715 | rc = dentry->d_inode->i_op->readlink(dentry, (char __user *)buf, len); |
724 | set_fs(old_fs); | 716 | set_fs(old_fs); |
725 | if (rc < 0) | 717 | if (rc < 0) { |
726 | goto out_free; | 718 | kfree(buf); |
727 | else | 719 | buf = ERR_PTR(rc); |
720 | } else | ||
728 | buf[rc] = '\0'; | 721 | buf[rc] = '\0'; |
729 | rc = 0; | ||
730 | nd_set_link(nd, buf); | ||
731 | goto out; | ||
732 | out_free: | ||
733 | kfree(buf); | ||
734 | out: | 722 | out: |
735 | return ERR_PTR(rc); | 723 | nd_set_link(nd, buf); |
724 | return NULL; | ||
736 | } | 725 | } |
737 | 726 | ||
738 | static void | 727 | static void |
739 | ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr) | 728 | ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr) |
740 | { | 729 | { |
741 | /* Free the char* */ | 730 | char *buf = nd_get_link(nd); |
742 | kfree(nd_get_link(nd)); | 731 | if (!IS_ERR(buf)) { |
732 | /* Free the char* */ | ||
733 | kfree(buf); | ||
734 | } | ||
743 | } | 735 | } |
744 | 736 | ||
745 | /** | 737 | /** |
@@ -759,7 +751,7 @@ upper_size_to_lower_size(struct ecryptfs_crypt_stat *crypt_stat, | |||
759 | { | 751 | { |
760 | loff_t lower_size; | 752 | loff_t lower_size; |
761 | 753 | ||
762 | lower_size = crypt_stat->num_header_bytes_at_front; | 754 | lower_size = ecryptfs_lower_header_size(crypt_stat); |
763 | if (upper_size != 0) { | 755 | if (upper_size != 0) { |
764 | loff_t num_extents; | 756 | loff_t num_extents; |
765 | 757 | ||
@@ -772,18 +764,23 @@ upper_size_to_lower_size(struct ecryptfs_crypt_stat *crypt_stat, | |||
772 | } | 764 | } |
773 | 765 | ||
774 | /** | 766 | /** |
775 | * ecryptfs_truncate | 767 | * truncate_upper |
776 | * @dentry: The ecryptfs layer dentry | 768 | * @dentry: The ecryptfs layer dentry |
777 | * @new_length: The length to expand the file to | 769 | * @ia: Address of the ecryptfs inode's attributes |
770 | * @lower_ia: Address of the lower inode's attributes | ||
778 | * | 771 | * |
779 | * Function to handle truncations modifying the size of the file. Note | 772 | * Function to handle truncations modifying the size of the file. Note |
780 | * that the file sizes are interpolated. When expanding, we are simply | 773 | * that the file sizes are interpolated. When expanding, we are simply |
781 | * writing strings of 0's out. When truncating, we need to modify the | 774 | * writing strings of 0's out. When truncating, we truncate the upper |
782 | * underlying file size according to the page index interpolations. | 775 | * inode and update the lower_ia according to the page index |
776 | * interpolations. If ATTR_SIZE is set in lower_ia->ia_valid upon return, | ||
777 | * the caller must use lower_ia in a call to notify_change() to perform | ||
778 | * the truncation of the lower inode. | ||
783 | * | 779 | * |
784 | * Returns zero on success; non-zero otherwise | 780 | * Returns zero on success; non-zero otherwise |
785 | */ | 781 | */ |
786 | int ecryptfs_truncate(struct dentry *dentry, loff_t new_length) | 782 | static int truncate_upper(struct dentry *dentry, struct iattr *ia, |
783 | struct iattr *lower_ia) | ||
787 | { | 784 | { |
788 | int rc = 0; | 785 | int rc = 0; |
789 | struct inode *inode = dentry->d_inode; | 786 | struct inode *inode = dentry->d_inode; |
@@ -794,8 +791,10 @@ int ecryptfs_truncate(struct dentry *dentry, loff_t new_length) | |||
794 | loff_t lower_size_before_truncate; | 791 | loff_t lower_size_before_truncate; |
795 | loff_t lower_size_after_truncate; | 792 | loff_t lower_size_after_truncate; |
796 | 793 | ||
797 | if (unlikely((new_length == i_size))) | 794 | if (unlikely((ia->ia_size == i_size))) { |
795 | lower_ia->ia_valid &= ~ATTR_SIZE; | ||
798 | goto out; | 796 | goto out; |
797 | } | ||
799 | crypt_stat = &ecryptfs_inode_to_private(dentry->d_inode)->crypt_stat; | 798 | crypt_stat = &ecryptfs_inode_to_private(dentry->d_inode)->crypt_stat; |
800 | /* Set up a fake ecryptfs file, this is used to interface with | 799 | /* Set up a fake ecryptfs file, this is used to interface with |
801 | * the file in the underlying filesystem so that the | 800 | * the file in the underlying filesystem so that the |
@@ -815,28 +814,30 @@ int ecryptfs_truncate(struct dentry *dentry, loff_t new_length) | |||
815 | &fake_ecryptfs_file, | 814 | &fake_ecryptfs_file, |
816 | ecryptfs_inode_to_private(dentry->d_inode)->lower_file); | 815 | ecryptfs_inode_to_private(dentry->d_inode)->lower_file); |
817 | /* Switch on growing or shrinking file */ | 816 | /* Switch on growing or shrinking file */ |
818 | if (new_length > i_size) { | 817 | if (ia->ia_size > i_size) { |
819 | char zero[] = { 0x00 }; | 818 | char zero[] = { 0x00 }; |
820 | 819 | ||
820 | lower_ia->ia_valid &= ~ATTR_SIZE; | ||
821 | /* Write a single 0 at the last position of the file; | 821 | /* Write a single 0 at the last position of the file; |
822 | * this triggers code that will fill in 0's throughout | 822 | * this triggers code that will fill in 0's throughout |
823 | * the intermediate portion of the previous end of the | 823 | * the intermediate portion of the previous end of the |
824 | * file and the new and of the file */ | 824 | * file and the new and of the file */ |
825 | rc = ecryptfs_write(&fake_ecryptfs_file, zero, | 825 | rc = ecryptfs_write(&fake_ecryptfs_file, zero, |
826 | (new_length - 1), 1); | 826 | (ia->ia_size - 1), 1); |
827 | } else { /* new_length < i_size_read(inode) */ | 827 | } else { /* ia->ia_size < i_size_read(inode) */ |
828 | /* We're chopping off all the pages down do the page | 828 | /* We're chopping off all the pages down to the page |
829 | * in which new_length is located. Fill in the end of | 829 | * in which ia->ia_size is located. Fill in the end of |
830 | * that page from (new_length & ~PAGE_CACHE_MASK) to | 830 | * that page from (ia->ia_size & ~PAGE_CACHE_MASK) to |
831 | * PAGE_CACHE_SIZE with zeros. */ | 831 | * PAGE_CACHE_SIZE with zeros. */ |
832 | size_t num_zeros = (PAGE_CACHE_SIZE | 832 | size_t num_zeros = (PAGE_CACHE_SIZE |
833 | - (new_length & ~PAGE_CACHE_MASK)); | 833 | - (ia->ia_size & ~PAGE_CACHE_MASK)); |
834 | 834 | ||
835 | if (!(crypt_stat->flags & ECRYPTFS_ENCRYPTED)) { | 835 | if (!(crypt_stat->flags & ECRYPTFS_ENCRYPTED)) { |
836 | rc = vmtruncate(inode, new_length); | 836 | rc = vmtruncate(inode, ia->ia_size); |
837 | if (rc) | 837 | if (rc) |
838 | goto out_free; | 838 | goto out_free; |
839 | rc = vmtruncate(lower_dentry->d_inode, new_length); | 839 | lower_ia->ia_size = ia->ia_size; |
840 | lower_ia->ia_valid |= ATTR_SIZE; | ||
840 | goto out_free; | 841 | goto out_free; |
841 | } | 842 | } |
842 | if (num_zeros) { | 843 | if (num_zeros) { |
@@ -848,7 +849,7 @@ int ecryptfs_truncate(struct dentry *dentry, loff_t new_length) | |||
848 | goto out_free; | 849 | goto out_free; |
849 | } | 850 | } |
850 | rc = ecryptfs_write(&fake_ecryptfs_file, zeros_virt, | 851 | rc = ecryptfs_write(&fake_ecryptfs_file, zeros_virt, |
851 | new_length, num_zeros); | 852 | ia->ia_size, num_zeros); |
852 | kfree(zeros_virt); | 853 | kfree(zeros_virt); |
853 | if (rc) { | 854 | if (rc) { |
854 | printk(KERN_ERR "Error attempting to zero out " | 855 | printk(KERN_ERR "Error attempting to zero out " |
@@ -857,7 +858,7 @@ int ecryptfs_truncate(struct dentry *dentry, loff_t new_length) | |||
857 | goto out_free; | 858 | goto out_free; |
858 | } | 859 | } |
859 | } | 860 | } |
860 | vmtruncate(inode, new_length); | 861 | vmtruncate(inode, ia->ia_size); |
861 | rc = ecryptfs_write_inode_size_to_metadata(inode); | 862 | rc = ecryptfs_write_inode_size_to_metadata(inode); |
862 | if (rc) { | 863 | if (rc) { |
863 | printk(KERN_ERR "Problem with " | 864 | printk(KERN_ERR "Problem with " |
@@ -870,10 +871,12 @@ int ecryptfs_truncate(struct dentry *dentry, loff_t new_length) | |||
870 | lower_size_before_truncate = | 871 | lower_size_before_truncate = |
871 | upper_size_to_lower_size(crypt_stat, i_size); | 872 | upper_size_to_lower_size(crypt_stat, i_size); |
872 | lower_size_after_truncate = | 873 | lower_size_after_truncate = |
873 | upper_size_to_lower_size(crypt_stat, new_length); | 874 | upper_size_to_lower_size(crypt_stat, ia->ia_size); |
874 | if (lower_size_after_truncate < lower_size_before_truncate) | 875 | if (lower_size_after_truncate < lower_size_before_truncate) { |
875 | vmtruncate(lower_dentry->d_inode, | 876 | lower_ia->ia_size = lower_size_after_truncate; |
876 | lower_size_after_truncate); | 877 | lower_ia->ia_valid |= ATTR_SIZE; |
878 | } else | ||
879 | lower_ia->ia_valid &= ~ATTR_SIZE; | ||
877 | } | 880 | } |
878 | out_free: | 881 | out_free: |
879 | if (ecryptfs_file_to_private(&fake_ecryptfs_file)) | 882 | if (ecryptfs_file_to_private(&fake_ecryptfs_file)) |
@@ -883,6 +886,33 @@ out: | |||
883 | return rc; | 886 | return rc; |
884 | } | 887 | } |
885 | 888 | ||
889 | /** | ||
890 | * ecryptfs_truncate | ||
891 | * @dentry: The ecryptfs layer dentry | ||
892 | * @new_length: The length to expand the file to | ||
893 | * | ||
894 | * Simple function that handles the truncation of an eCryptfs inode and | ||
895 | * its corresponding lower inode. | ||
896 | * | ||
897 | * Returns zero on success; non-zero otherwise | ||
898 | */ | ||
899 | int ecryptfs_truncate(struct dentry *dentry, loff_t new_length) | ||
900 | { | ||
901 | struct iattr ia = { .ia_valid = ATTR_SIZE, .ia_size = new_length }; | ||
902 | struct iattr lower_ia = { .ia_valid = 0 }; | ||
903 | int rc; | ||
904 | |||
905 | rc = truncate_upper(dentry, &ia, &lower_ia); | ||
906 | if (!rc && lower_ia.ia_valid & ATTR_SIZE) { | ||
907 | struct dentry *lower_dentry = ecryptfs_dentry_to_lower(dentry); | ||
908 | |||
909 | mutex_lock(&lower_dentry->d_inode->i_mutex); | ||
910 | rc = notify_change(lower_dentry, &lower_ia); | ||
911 | mutex_unlock(&lower_dentry->d_inode->i_mutex); | ||
912 | } | ||
913 | return rc; | ||
914 | } | ||
915 | |||
886 | static int | 916 | static int |
887 | ecryptfs_permission(struct inode *inode, int mask) | 917 | ecryptfs_permission(struct inode *inode, int mask) |
888 | { | 918 | { |
@@ -905,6 +935,7 @@ static int ecryptfs_setattr(struct dentry *dentry, struct iattr *ia) | |||
905 | { | 935 | { |
906 | int rc = 0; | 936 | int rc = 0; |
907 | struct dentry *lower_dentry; | 937 | struct dentry *lower_dentry; |
938 | struct iattr lower_ia; | ||
908 | struct inode *inode; | 939 | struct inode *inode; |
909 | struct inode *lower_inode; | 940 | struct inode *lower_inode; |
910 | struct ecryptfs_crypt_stat *crypt_stat; | 941 | struct ecryptfs_crypt_stat *crypt_stat; |
@@ -943,15 +974,11 @@ static int ecryptfs_setattr(struct dentry *dentry, struct iattr *ia) | |||
943 | } | 974 | } |
944 | } | 975 | } |
945 | mutex_unlock(&crypt_stat->cs_mutex); | 976 | mutex_unlock(&crypt_stat->cs_mutex); |
977 | memcpy(&lower_ia, ia, sizeof(lower_ia)); | ||
978 | if (ia->ia_valid & ATTR_FILE) | ||
979 | lower_ia.ia_file = ecryptfs_file_to_lower(ia->ia_file); | ||
946 | if (ia->ia_valid & ATTR_SIZE) { | 980 | if (ia->ia_valid & ATTR_SIZE) { |
947 | ecryptfs_printk(KERN_DEBUG, | 981 | rc = truncate_upper(dentry, ia, &lower_ia); |
948 | "ia->ia_valid = [0x%x] ATTR_SIZE" " = [0x%x]\n", | ||
949 | ia->ia_valid, ATTR_SIZE); | ||
950 | rc = ecryptfs_truncate(dentry, ia->ia_size); | ||
951 | /* ecryptfs_truncate handles resizing of the lower file */ | ||
952 | ia->ia_valid &= ~ATTR_SIZE; | ||
953 | ecryptfs_printk(KERN_DEBUG, "ia->ia_valid = [%x]\n", | ||
954 | ia->ia_valid); | ||
955 | if (rc < 0) | 982 | if (rc < 0) |
956 | goto out; | 983 | goto out; |
957 | } | 984 | } |
@@ -960,14 +987,51 @@ static int ecryptfs_setattr(struct dentry *dentry, struct iattr *ia) | |||
960 | * mode change is for clearing setuid/setgid bits. Allow lower fs | 987 | * mode change is for clearing setuid/setgid bits. Allow lower fs |
961 | * to interpret this in its own way. | 988 | * to interpret this in its own way. |
962 | */ | 989 | */ |
963 | if (ia->ia_valid & (ATTR_KILL_SUID | ATTR_KILL_SGID)) | 990 | if (lower_ia.ia_valid & (ATTR_KILL_SUID | ATTR_KILL_SGID)) |
964 | ia->ia_valid &= ~ATTR_MODE; | 991 | lower_ia.ia_valid &= ~ATTR_MODE; |
965 | 992 | ||
966 | mutex_lock(&lower_dentry->d_inode->i_mutex); | 993 | mutex_lock(&lower_dentry->d_inode->i_mutex); |
967 | rc = notify_change(lower_dentry, ia); | 994 | rc = notify_change(lower_dentry, &lower_ia); |
968 | mutex_unlock(&lower_dentry->d_inode->i_mutex); | 995 | mutex_unlock(&lower_dentry->d_inode->i_mutex); |
969 | out: | 996 | out: |
970 | fsstack_copy_attr_all(inode, lower_inode, NULL); | 997 | fsstack_copy_attr_all(inode, lower_inode); |
998 | return rc; | ||
999 | } | ||
1000 | |||
1001 | int ecryptfs_getattr_link(struct vfsmount *mnt, struct dentry *dentry, | ||
1002 | struct kstat *stat) | ||
1003 | { | ||
1004 | struct ecryptfs_mount_crypt_stat *mount_crypt_stat; | ||
1005 | int rc = 0; | ||
1006 | |||
1007 | mount_crypt_stat = &ecryptfs_superblock_to_private( | ||
1008 | dentry->d_sb)->mount_crypt_stat; | ||
1009 | generic_fillattr(dentry->d_inode, stat); | ||
1010 | if (mount_crypt_stat->flags & ECRYPTFS_GLOBAL_ENCRYPT_FILENAMES) { | ||
1011 | char *target; | ||
1012 | size_t targetsiz; | ||
1013 | |||
1014 | rc = ecryptfs_readlink_lower(dentry, &target, &targetsiz); | ||
1015 | if (!rc) { | ||
1016 | kfree(target); | ||
1017 | stat->size = targetsiz; | ||
1018 | } | ||
1019 | } | ||
1020 | return rc; | ||
1021 | } | ||
1022 | |||
1023 | int ecryptfs_getattr(struct vfsmount *mnt, struct dentry *dentry, | ||
1024 | struct kstat *stat) | ||
1025 | { | ||
1026 | struct kstat lower_stat; | ||
1027 | int rc; | ||
1028 | |||
1029 | rc = vfs_getattr(ecryptfs_dentry_to_lower_mnt(dentry), | ||
1030 | ecryptfs_dentry_to_lower(dentry), &lower_stat); | ||
1031 | if (!rc) { | ||
1032 | generic_fillattr(dentry->d_inode, stat); | ||
1033 | stat->blocks = lower_stat.blocks; | ||
1034 | } | ||
971 | return rc; | 1035 | return rc; |
972 | } | 1036 | } |
973 | 1037 | ||
@@ -980,7 +1044,7 @@ ecryptfs_setxattr(struct dentry *dentry, const char *name, const void *value, | |||
980 | 1044 | ||
981 | lower_dentry = ecryptfs_dentry_to_lower(dentry); | 1045 | lower_dentry = ecryptfs_dentry_to_lower(dentry); |
982 | if (!lower_dentry->d_inode->i_op->setxattr) { | 1046 | if (!lower_dentry->d_inode->i_op->setxattr) { |
983 | rc = -ENOSYS; | 1047 | rc = -EOPNOTSUPP; |
984 | goto out; | 1048 | goto out; |
985 | } | 1049 | } |
986 | mutex_lock(&lower_dentry->d_inode->i_mutex); | 1050 | mutex_lock(&lower_dentry->d_inode->i_mutex); |
@@ -998,7 +1062,7 @@ ecryptfs_getxattr_lower(struct dentry *lower_dentry, const char *name, | |||
998 | int rc = 0; | 1062 | int rc = 0; |
999 | 1063 | ||
1000 | if (!lower_dentry->d_inode->i_op->getxattr) { | 1064 | if (!lower_dentry->d_inode->i_op->getxattr) { |
1001 | rc = -ENOSYS; | 1065 | rc = -EOPNOTSUPP; |
1002 | goto out; | 1066 | goto out; |
1003 | } | 1067 | } |
1004 | mutex_lock(&lower_dentry->d_inode->i_mutex); | 1068 | mutex_lock(&lower_dentry->d_inode->i_mutex); |
@@ -1025,7 +1089,7 @@ ecryptfs_listxattr(struct dentry *dentry, char *list, size_t size) | |||
1025 | 1089 | ||
1026 | lower_dentry = ecryptfs_dentry_to_lower(dentry); | 1090 | lower_dentry = ecryptfs_dentry_to_lower(dentry); |
1027 | if (!lower_dentry->d_inode->i_op->listxattr) { | 1091 | if (!lower_dentry->d_inode->i_op->listxattr) { |
1028 | rc = -ENOSYS; | 1092 | rc = -EOPNOTSUPP; |
1029 | goto out; | 1093 | goto out; |
1030 | } | 1094 | } |
1031 | mutex_lock(&lower_dentry->d_inode->i_mutex); | 1095 | mutex_lock(&lower_dentry->d_inode->i_mutex); |
@@ -1042,7 +1106,7 @@ static int ecryptfs_removexattr(struct dentry *dentry, const char *name) | |||
1042 | 1106 | ||
1043 | lower_dentry = ecryptfs_dentry_to_lower(dentry); | 1107 | lower_dentry = ecryptfs_dentry_to_lower(dentry); |
1044 | if (!lower_dentry->d_inode->i_op->removexattr) { | 1108 | if (!lower_dentry->d_inode->i_op->removexattr) { |
1045 | rc = -ENOSYS; | 1109 | rc = -EOPNOTSUPP; |
1046 | goto out; | 1110 | goto out; |
1047 | } | 1111 | } |
1048 | mutex_lock(&lower_dentry->d_inode->i_mutex); | 1112 | mutex_lock(&lower_dentry->d_inode->i_mutex); |
@@ -1073,6 +1137,7 @@ const struct inode_operations ecryptfs_symlink_iops = { | |||
1073 | .put_link = ecryptfs_put_link, | 1137 | .put_link = ecryptfs_put_link, |
1074 | .permission = ecryptfs_permission, | 1138 | .permission = ecryptfs_permission, |
1075 | .setattr = ecryptfs_setattr, | 1139 | .setattr = ecryptfs_setattr, |
1140 | .getattr = ecryptfs_getattr_link, | ||
1076 | .setxattr = ecryptfs_setxattr, | 1141 | .setxattr = ecryptfs_setxattr, |
1077 | .getxattr = ecryptfs_getxattr, | 1142 | .getxattr = ecryptfs_getxattr, |
1078 | .listxattr = ecryptfs_listxattr, | 1143 | .listxattr = ecryptfs_listxattr, |
@@ -1100,6 +1165,7 @@ const struct inode_operations ecryptfs_dir_iops = { | |||
1100 | const struct inode_operations ecryptfs_main_iops = { | 1165 | const struct inode_operations ecryptfs_main_iops = { |
1101 | .permission = ecryptfs_permission, | 1166 | .permission = ecryptfs_permission, |
1102 | .setattr = ecryptfs_setattr, | 1167 | .setattr = ecryptfs_setattr, |
1168 | .getattr = ecryptfs_getattr, | ||
1103 | .setxattr = ecryptfs_setxattr, | 1169 | .setxattr = ecryptfs_setxattr, |
1104 | .getxattr = ecryptfs_getxattr, | 1170 | .getxattr = ecryptfs_getxattr, |
1105 | .listxattr = ecryptfs_listxattr, | 1171 | .listxattr = ecryptfs_listxattr, |
diff --git a/fs/ecryptfs/keystore.c b/fs/ecryptfs/keystore.c index a0a7847567e9..89c5476506ef 100644 --- a/fs/ecryptfs/keystore.c +++ b/fs/ecryptfs/keystore.c | |||
@@ -32,6 +32,7 @@ | |||
32 | #include <linux/random.h> | 32 | #include <linux/random.h> |
33 | #include <linux/crypto.h> | 33 | #include <linux/crypto.h> |
34 | #include <linux/scatterlist.h> | 34 | #include <linux/scatterlist.h> |
35 | #include <linux/slab.h> | ||
35 | #include "ecryptfs_kernel.h" | 36 | #include "ecryptfs_kernel.h" |
36 | 37 | ||
37 | /** | 38 | /** |
diff --git a/fs/ecryptfs/kthread.c b/fs/ecryptfs/kthread.c index e14cf7e588db..d8c3a373aafa 100644 --- a/fs/ecryptfs/kthread.c +++ b/fs/ecryptfs/kthread.c | |||
@@ -22,6 +22,7 @@ | |||
22 | 22 | ||
23 | #include <linux/kthread.h> | 23 | #include <linux/kthread.h> |
24 | #include <linux/freezer.h> | 24 | #include <linux/freezer.h> |
25 | #include <linux/slab.h> | ||
25 | #include <linux/wait.h> | 26 | #include <linux/wait.h> |
26 | #include <linux/mount.h> | 27 | #include <linux/mount.h> |
27 | #include "ecryptfs_kernel.h" | 28 | #include "ecryptfs_kernel.h" |
diff --git a/fs/ecryptfs/main.c b/fs/ecryptfs/main.c index c6ac85d6c701..760983d0f25e 100644 --- a/fs/ecryptfs/main.c +++ b/fs/ecryptfs/main.c | |||
@@ -35,7 +35,7 @@ | |||
35 | #include <linux/key.h> | 35 | #include <linux/key.h> |
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/ima.h> | 38 | #include <linux/slab.h> |
39 | #include "ecryptfs_kernel.h" | 39 | #include "ecryptfs_kernel.h" |
40 | 40 | ||
41 | /** | 41 | /** |
@@ -119,7 +119,6 @@ int ecryptfs_init_persistent_file(struct dentry *ecryptfs_dentry) | |||
119 | const struct cred *cred = current_cred(); | 119 | const struct cred *cred = current_cred(); |
120 | struct ecryptfs_inode_info *inode_info = | 120 | struct ecryptfs_inode_info *inode_info = |
121 | ecryptfs_inode_to_private(ecryptfs_dentry->d_inode); | 121 | ecryptfs_inode_to_private(ecryptfs_dentry->d_inode); |
122 | int opened_lower_file = 0; | ||
123 | int rc = 0; | 122 | int rc = 0; |
124 | 123 | ||
125 | mutex_lock(&inode_info->lower_file_mutex); | 124 | mutex_lock(&inode_info->lower_file_mutex); |
@@ -136,12 +135,9 @@ int ecryptfs_init_persistent_file(struct dentry *ecryptfs_dentry) | |||
136 | "for lower_dentry [0x%p] and lower_mnt [0x%p]; " | 135 | "for lower_dentry [0x%p] and lower_mnt [0x%p]; " |
137 | "rc = [%d]\n", lower_dentry, lower_mnt, rc); | 136 | "rc = [%d]\n", lower_dentry, lower_mnt, rc); |
138 | inode_info->lower_file = NULL; | 137 | inode_info->lower_file = NULL; |
139 | } else | 138 | } |
140 | opened_lower_file = 1; | ||
141 | } | 139 | } |
142 | mutex_unlock(&inode_info->lower_file_mutex); | 140 | mutex_unlock(&inode_info->lower_file_mutex); |
143 | if (opened_lower_file) | ||
144 | ima_counts_get(inode_info->lower_file); | ||
145 | return rc; | 141 | return rc; |
146 | } | 142 | } |
147 | 143 | ||
@@ -194,7 +190,7 @@ int ecryptfs_interpose(struct dentry *lower_dentry, struct dentry *dentry, | |||
194 | init_special_inode(inode, lower_inode->i_mode, | 190 | init_special_inode(inode, lower_inode->i_mode, |
195 | lower_inode->i_rdev); | 191 | lower_inode->i_rdev); |
196 | dentry->d_op = &ecryptfs_dops; | 192 | dentry->d_op = &ecryptfs_dops; |
197 | fsstack_copy_attr_all(inode, lower_inode, NULL); | 193 | fsstack_copy_attr_all(inode, lower_inode); |
198 | /* This size will be overwritten for real files w/ headers and | 194 | /* This size will be overwritten for real files w/ headers and |
199 | * other metadata */ | 195 | * other metadata */ |
200 | fsstack_copy_inode_size(inode, lower_inode); | 196 | fsstack_copy_inode_size(inode, lower_inode); |
@@ -501,17 +497,25 @@ struct kmem_cache *ecryptfs_sb_info_cache; | |||
501 | static int | 497 | static int |
502 | ecryptfs_fill_super(struct super_block *sb, void *raw_data, int silent) | 498 | ecryptfs_fill_super(struct super_block *sb, void *raw_data, int silent) |
503 | { | 499 | { |
500 | struct ecryptfs_sb_info *esi; | ||
504 | int rc = 0; | 501 | int rc = 0; |
505 | 502 | ||
506 | /* Released in ecryptfs_put_super() */ | 503 | /* Released in ecryptfs_put_super() */ |
507 | ecryptfs_set_superblock_private(sb, | 504 | ecryptfs_set_superblock_private(sb, |
508 | kmem_cache_zalloc(ecryptfs_sb_info_cache, | 505 | kmem_cache_zalloc(ecryptfs_sb_info_cache, |
509 | GFP_KERNEL)); | 506 | GFP_KERNEL)); |
510 | if (!ecryptfs_superblock_to_private(sb)) { | 507 | esi = ecryptfs_superblock_to_private(sb); |
508 | if (!esi) { | ||
511 | ecryptfs_printk(KERN_WARNING, "Out of memory\n"); | 509 | ecryptfs_printk(KERN_WARNING, "Out of memory\n"); |
512 | rc = -ENOMEM; | 510 | rc = -ENOMEM; |
513 | goto out; | 511 | goto out; |
514 | } | 512 | } |
513 | |||
514 | rc = bdi_setup_and_register(&esi->bdi, "ecryptfs", BDI_CAP_MAP_COPY); | ||
515 | if (rc) | ||
516 | goto out; | ||
517 | |||
518 | sb->s_bdi = &esi->bdi; | ||
515 | sb->s_op = &ecryptfs_sops; | 519 | sb->s_op = &ecryptfs_sops; |
516 | /* Released through deactivate_super(sb) from get_sb_nodev */ | 520 | /* Released through deactivate_super(sb) from get_sb_nodev */ |
517 | sb->s_root = d_alloc(NULL, &(const struct qstr) { | 521 | sb->s_root = d_alloc(NULL, &(const struct qstr) { |
@@ -590,8 +594,8 @@ out: | |||
590 | * with as much information as it can before needing | 594 | * with as much information as it can before needing |
591 | * the lower filesystem. | 595 | * the lower filesystem. |
592 | * ecryptfs_read_super(): this accesses the lower filesystem and uses | 596 | * ecryptfs_read_super(): this accesses the lower filesystem and uses |
593 | * ecryptfs_interpolate to perform most of the linking | 597 | * ecryptfs_interpose to perform most of the linking |
594 | * ecryptfs_interpolate(): links the lower filesystem into ecryptfs | 598 | * ecryptfs_interpose(): links the lower filesystem into ecryptfs (inode.c) |
595 | */ | 599 | */ |
596 | static int ecryptfs_get_sb(struct file_system_type *fs_type, int flags, | 600 | static int ecryptfs_get_sb(struct file_system_type *fs_type, int flags, |
597 | const char *dev_name, void *raw_data, | 601 | const char *dev_name, void *raw_data, |
diff --git a/fs/ecryptfs/messaging.c b/fs/ecryptfs/messaging.c index f1c17e87c5fb..2d8dbce9d485 100644 --- a/fs/ecryptfs/messaging.c +++ b/fs/ecryptfs/messaging.c | |||
@@ -20,6 +20,7 @@ | |||
20 | * 02111-1307, USA. | 20 | * 02111-1307, USA. |
21 | */ | 21 | */ |
22 | #include <linux/sched.h> | 22 | #include <linux/sched.h> |
23 | #include <linux/slab.h> | ||
23 | #include <linux/user_namespace.h> | 24 | #include <linux/user_namespace.h> |
24 | #include <linux/nsproxy.h> | 25 | #include <linux/nsproxy.h> |
25 | #include "ecryptfs_kernel.h" | 26 | #include "ecryptfs_kernel.h" |
diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c index 4ec8f61ccf5a..3745f612bcd4 100644 --- a/fs/ecryptfs/miscdev.c +++ b/fs/ecryptfs/miscdev.c | |||
@@ -24,6 +24,7 @@ | |||
24 | #include <linux/random.h> | 24 | #include <linux/random.h> |
25 | #include <linux/miscdevice.h> | 25 | #include <linux/miscdevice.h> |
26 | #include <linux/poll.h> | 26 | #include <linux/poll.h> |
27 | #include <linux/slab.h> | ||
27 | #include <linux/wait.h> | 28 | #include <linux/wait.h> |
28 | #include <linux/module.h> | 29 | #include <linux/module.h> |
29 | #include "ecryptfs_kernel.h" | 30 | #include "ecryptfs_kernel.h" |
diff --git a/fs/ecryptfs/mmap.c b/fs/ecryptfs/mmap.c index df4ce99d0597..2ee9a3a7b68c 100644 --- a/fs/ecryptfs/mmap.c +++ b/fs/ecryptfs/mmap.c | |||
@@ -32,6 +32,7 @@ | |||
32 | #include <linux/file.h> | 32 | #include <linux/file.h> |
33 | #include <linux/crypto.h> | 33 | #include <linux/crypto.h> |
34 | #include <linux/scatterlist.h> | 34 | #include <linux/scatterlist.h> |
35 | #include <linux/slab.h> | ||
35 | #include <asm/unaligned.h> | 36 | #include <asm/unaligned.h> |
36 | #include "ecryptfs_kernel.h" | 37 | #include "ecryptfs_kernel.h" |
37 | 38 | ||
@@ -82,6 +83,19 @@ out: | |||
82 | return rc; | 83 | return rc; |
83 | } | 84 | } |
84 | 85 | ||
86 | static void strip_xattr_flag(char *page_virt, | ||
87 | struct ecryptfs_crypt_stat *crypt_stat) | ||
88 | { | ||
89 | if (crypt_stat->flags & ECRYPTFS_METADATA_IN_XATTR) { | ||
90 | size_t written; | ||
91 | |||
92 | crypt_stat->flags &= ~ECRYPTFS_METADATA_IN_XATTR; | ||
93 | ecryptfs_write_crypt_stat_flags(page_virt, crypt_stat, | ||
94 | &written); | ||
95 | crypt_stat->flags |= ECRYPTFS_METADATA_IN_XATTR; | ||
96 | } | ||
97 | } | ||
98 | |||
85 | /** | 99 | /** |
86 | * Header Extent: | 100 | * Header Extent: |
87 | * Octets 0-7: Unencrypted file size (big-endian) | 101 | * Octets 0-7: Unencrypted file size (big-endian) |
@@ -97,19 +111,6 @@ out: | |||
97 | * (big-endian) | 111 | * (big-endian) |
98 | * Octet 26: Begin RFC 2440 authentication token packet set | 112 | * Octet 26: Begin RFC 2440 authentication token packet set |
99 | */ | 113 | */ |
100 | static void set_header_info(char *page_virt, | ||
101 | struct ecryptfs_crypt_stat *crypt_stat) | ||
102 | { | ||
103 | size_t written; | ||
104 | size_t save_num_header_bytes_at_front = | ||
105 | crypt_stat->num_header_bytes_at_front; | ||
106 | |||
107 | crypt_stat->num_header_bytes_at_front = | ||
108 | ECRYPTFS_MINIMUM_HEADER_EXTENT_SIZE; | ||
109 | ecryptfs_write_header_metadata(page_virt + 20, crypt_stat, &written); | ||
110 | crypt_stat->num_header_bytes_at_front = | ||
111 | save_num_header_bytes_at_front; | ||
112 | } | ||
113 | 114 | ||
114 | /** | 115 | /** |
115 | * ecryptfs_copy_up_encrypted_with_header | 116 | * ecryptfs_copy_up_encrypted_with_header |
@@ -135,8 +136,7 @@ ecryptfs_copy_up_encrypted_with_header(struct page *page, | |||
135 | * num_extents_per_page) | 136 | * num_extents_per_page) |
136 | + extent_num_in_page); | 137 | + extent_num_in_page); |
137 | size_t num_header_extents_at_front = | 138 | size_t num_header_extents_at_front = |
138 | (crypt_stat->num_header_bytes_at_front | 139 | (crypt_stat->metadata_size / crypt_stat->extent_size); |
139 | / crypt_stat->extent_size); | ||
140 | 140 | ||
141 | if (view_extent_num < num_header_extents_at_front) { | 141 | if (view_extent_num < num_header_extents_at_front) { |
142 | /* This is a header extent */ | 142 | /* This is a header extent */ |
@@ -146,9 +146,14 @@ ecryptfs_copy_up_encrypted_with_header(struct page *page, | |||
146 | memset(page_virt, 0, PAGE_CACHE_SIZE); | 146 | memset(page_virt, 0, PAGE_CACHE_SIZE); |
147 | /* TODO: Support more than one header extent */ | 147 | /* TODO: Support more than one header extent */ |
148 | if (view_extent_num == 0) { | 148 | if (view_extent_num == 0) { |
149 | size_t written; | ||
150 | |||
149 | rc = ecryptfs_read_xattr_region( | 151 | rc = ecryptfs_read_xattr_region( |
150 | page_virt, page->mapping->host); | 152 | page_virt, page->mapping->host); |
151 | set_header_info(page_virt, crypt_stat); | 153 | strip_xattr_flag(page_virt + 16, crypt_stat); |
154 | ecryptfs_write_header_metadata(page_virt + 20, | ||
155 | crypt_stat, | ||
156 | &written); | ||
152 | } | 157 | } |
153 | kunmap_atomic(page_virt, KM_USER0); | 158 | kunmap_atomic(page_virt, KM_USER0); |
154 | flush_dcache_page(page); | 159 | flush_dcache_page(page); |
@@ -161,7 +166,7 @@ ecryptfs_copy_up_encrypted_with_header(struct page *page, | |||
161 | /* This is an encrypted data extent */ | 166 | /* This is an encrypted data extent */ |
162 | loff_t lower_offset = | 167 | loff_t lower_offset = |
163 | ((view_extent_num * crypt_stat->extent_size) | 168 | ((view_extent_num * crypt_stat->extent_size) |
164 | - crypt_stat->num_header_bytes_at_front); | 169 | - crypt_stat->metadata_size); |
165 | 170 | ||
166 | rc = ecryptfs_read_lower_page_segment( | 171 | rc = ecryptfs_read_lower_page_segment( |
167 | page, (lower_offset >> PAGE_CACHE_SHIFT), | 172 | page, (lower_offset >> PAGE_CACHE_SHIFT), |
diff --git a/fs/ecryptfs/super.c b/fs/ecryptfs/super.c index b15a43a80ab7..0c0ae491d231 100644 --- a/fs/ecryptfs/super.c +++ b/fs/ecryptfs/super.c | |||
@@ -26,6 +26,7 @@ | |||
26 | #include <linux/fs.h> | 26 | #include <linux/fs.h> |
27 | #include <linux/mount.h> | 27 | #include <linux/mount.h> |
28 | #include <linux/key.h> | 28 | #include <linux/key.h> |
29 | #include <linux/slab.h> | ||
29 | #include <linux/seq_file.h> | 30 | #include <linux/seq_file.h> |
30 | #include <linux/smp_lock.h> | 31 | #include <linux/smp_lock.h> |
31 | #include <linux/file.h> | 32 | #include <linux/file.h> |
@@ -85,7 +86,6 @@ static void ecryptfs_destroy_inode(struct inode *inode) | |||
85 | if (lower_dentry->d_inode) { | 86 | if (lower_dentry->d_inode) { |
86 | fput(inode_info->lower_file); | 87 | fput(inode_info->lower_file); |
87 | inode_info->lower_file = NULL; | 88 | inode_info->lower_file = NULL; |
88 | d_drop(lower_dentry); | ||
89 | } | 89 | } |
90 | } | 90 | } |
91 | ecryptfs_destroy_crypt_stat(&inode_info->crypt_stat); | 91 | ecryptfs_destroy_crypt_stat(&inode_info->crypt_stat); |
@@ -122,6 +122,7 @@ static void ecryptfs_put_super(struct super_block *sb) | |||
122 | lock_kernel(); | 122 | lock_kernel(); |
123 | 123 | ||
124 | ecryptfs_destroy_mount_crypt_stat(&sb_info->mount_crypt_stat); | 124 | ecryptfs_destroy_mount_crypt_stat(&sb_info->mount_crypt_stat); |
125 | bdi_destroy(&sb_info->bdi); | ||
125 | kmem_cache_free(ecryptfs_sb_info_cache, sb_info); | 126 | kmem_cache_free(ecryptfs_sb_info_cache, sb_info); |
126 | ecryptfs_set_superblock_private(sb, NULL); | 127 | ecryptfs_set_superblock_private(sb, NULL); |
127 | 128 | ||