aboutsummaryrefslogtreecommitdiffstats
path: root/fs/ecryptfs
diff options
context:
space:
mode:
authorTyler Hicks <tyhicks@linux.vnet.ibm.com>2010-02-11 08:10:38 -0500
committerTyler Hicks <tyhicks@linux.vnet.ibm.com>2010-03-23 13:29:49 -0400
commit157f1071354db1aed885816094888e0e257c9d0a (patch)
tree711d00d7dce97f846342db0a27b4a61c6b1966a4 /fs/ecryptfs
parent220bf991b0366cc50a94feede3d7341fa5710ee4 (diff)
eCryptfs: Fix metadata in xattr feature regression
Fixes regression in 8faece5f906725c10e7a1f6caf84452abadbdc7b When using the ecryptfs_xattr_metadata mount option, eCryptfs stores the metadata (normally stored at the front of the file) in the user.ecryptfs xattr. This causes ecryptfs_crypt_stat.num_header_bytes_at_front to be 0, since there is no header data at the front of the file. This results in too much memory being requested and ENOMEM being returned from ecryptfs_write_metadata(). This patch fixes the problem by using the num_header_bytes_at_front variable for specifying the max size of the metadata, despite whether it is stored in the header or xattr. Reviewed-by: Eric Sandeen <sandeen@redhat.com> Signed-off-by: Tyler Hicks <tyhicks@linux.vnet.ibm.com>
Diffstat (limited to 'fs/ecryptfs')
-rw-r--r--fs/ecryptfs/crypto.c7
-rw-r--r--fs/ecryptfs/ecryptfs_kernel.h8
-rw-r--r--fs/ecryptfs/inode.c2
-rw-r--r--fs/ecryptfs/mmap.c19
4 files changed, 18 insertions, 18 deletions
diff --git a/fs/ecryptfs/crypto.c b/fs/ecryptfs/crypto.c
index 7cb0a59f4b9d..c907f6f49351 100644
--- a/fs/ecryptfs/crypto.c
+++ b/fs/ecryptfs/crypto.c
@@ -381,8 +381,8 @@ out:
381static void ecryptfs_lower_offset_for_extent(loff_t *offset, loff_t extent_num, 381static void ecryptfs_lower_offset_for_extent(loff_t *offset, loff_t extent_num,
382 struct ecryptfs_crypt_stat *crypt_stat) 382 struct ecryptfs_crypt_stat *crypt_stat)
383{ 383{
384 (*offset) = (crypt_stat->num_header_bytes_at_front 384 (*offset) = ecryptfs_lower_header_size(crypt_stat)
385 + (crypt_stat->extent_size * extent_num)); 385 + (crypt_stat->extent_size * extent_num);
386} 386}
387 387
388/** 388/**
@@ -834,7 +834,8 @@ void ecryptfs_set_default_sizes(struct ecryptfs_crypt_stat *crypt_stat)
834 set_extent_mask_and_shift(crypt_stat); 834 set_extent_mask_and_shift(crypt_stat);
835 crypt_stat->iv_bytes = ECRYPTFS_DEFAULT_IV_BYTES; 835 crypt_stat->iv_bytes = ECRYPTFS_DEFAULT_IV_BYTES;
836 if (crypt_stat->flags & ECRYPTFS_METADATA_IN_XATTR) 836 if (crypt_stat->flags & ECRYPTFS_METADATA_IN_XATTR)
837 crypt_stat->num_header_bytes_at_front = 0; 837 crypt_stat->num_header_bytes_at_front =
838 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->num_header_bytes_at_front =
diff --git a/fs/ecryptfs/ecryptfs_kernel.h b/fs/ecryptfs/ecryptfs_kernel.h
index 542f625312f3..8456f70606ad 100644
--- a/fs/ecryptfs/ecryptfs_kernel.h
+++ b/fs/ecryptfs/ecryptfs_kernel.h
@@ -464,6 +464,14 @@ struct ecryptfs_daemon {
464 464
465extern struct mutex ecryptfs_daemon_hash_mux; 465extern struct mutex ecryptfs_daemon_hash_mux;
466 466
467static inline size_t
468ecryptfs_lower_header_size(struct ecryptfs_crypt_stat *crypt_stat)
469{
470 if (crypt_stat->flags & ECRYPTFS_METADATA_IN_XATTR)
471 return 0;
472 return crypt_stat->num_header_bytes_at_front;
473}
474
467static inline struct ecryptfs_file_info * 475static inline struct ecryptfs_file_info *
468ecryptfs_file_to_private(struct file *file) 476ecryptfs_file_to_private(struct file *file)
469{ 477{
diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
index 4a430ab4115c..1a739531b0dd 100644
--- a/fs/ecryptfs/inode.c
+++ b/fs/ecryptfs/inode.c
@@ -768,7 +768,7 @@ upper_size_to_lower_size(struct ecryptfs_crypt_stat *crypt_stat,
768{ 768{
769 loff_t lower_size; 769 loff_t lower_size;
770 770
771 lower_size = crypt_stat->num_header_bytes_at_front; 771 lower_size = ecryptfs_lower_header_size(crypt_stat);
772 if (upper_size != 0) { 772 if (upper_size != 0) {
773 loff_t num_extents; 773 loff_t num_extents;
774 774
diff --git a/fs/ecryptfs/mmap.c b/fs/ecryptfs/mmap.c
index df4ce99d0597..5a30e01547f1 100644
--- a/fs/ecryptfs/mmap.c
+++ b/fs/ecryptfs/mmap.c
@@ -97,19 +97,6 @@ out:
97 * (big-endian) 97 * (big-endian)
98 * Octet 26: Begin RFC 2440 authentication token packet set 98 * Octet 26: Begin RFC 2440 authentication token packet set
99 */ 99 */
100static 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 100
114/** 101/**
115 * ecryptfs_copy_up_encrypted_with_header 102 * ecryptfs_copy_up_encrypted_with_header
@@ -146,9 +133,13 @@ ecryptfs_copy_up_encrypted_with_header(struct page *page,
146 memset(page_virt, 0, PAGE_CACHE_SIZE); 133 memset(page_virt, 0, PAGE_CACHE_SIZE);
147 /* TODO: Support more than one header extent */ 134 /* TODO: Support more than one header extent */
148 if (view_extent_num == 0) { 135 if (view_extent_num == 0) {
136 size_t written;
137
149 rc = ecryptfs_read_xattr_region( 138 rc = ecryptfs_read_xattr_region(
150 page_virt, page->mapping->host); 139 page_virt, page->mapping->host);
151 set_header_info(page_virt, crypt_stat); 140 ecryptfs_write_header_metadata(page_virt + 20,
141 crypt_stat,
142 &written);
152 } 143 }
153 kunmap_atomic(page_virt, KM_USER0); 144 kunmap_atomic(page_virt, KM_USER0);
154 flush_dcache_page(page); 145 flush_dcache_page(page);