diff options
Diffstat (limited to 'fs/ecryptfs/mmap.c')
-rw-r--r-- | fs/ecryptfs/mmap.c | 39 |
1 files changed, 22 insertions, 17 deletions
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), |