aboutsummaryrefslogtreecommitdiffstats
path: root/fs/ecryptfs
diff options
context:
space:
mode:
authorMichael Halcrow <mhalcrow@us.ibm.com>2007-10-16 04:28:12 -0400
committerLinus Torvalds <torvalds@woody.linux-foundation.org>2007-10-16 12:43:12 -0400
commitd6a13c17164fccab8aa96ca435ddacbf428335ca (patch)
tree8995bb0b5c22a97c8f6c86eff797ff2de0421ee2 /fs/ecryptfs
parentbf12be1cc851cface331b0e74713a6bb1cb046b0 (diff)
eCryptfs: fix data types
Update data types and add casts in order to avoid potential overflow issues. Signed-off-by: Michael Halcrow <mhalcrow@us.ibm.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'fs/ecryptfs')
-rw-r--r--fs/ecryptfs/crypto.c21
-rw-r--r--fs/ecryptfs/mmap.c5
-rw-r--r--fs/ecryptfs/read_write.c11
3 files changed, 21 insertions, 16 deletions
diff --git a/fs/ecryptfs/crypto.c b/fs/ecryptfs/crypto.c
index 26070d69e59a..9408ea484164 100644
--- a/fs/ecryptfs/crypto.c
+++ b/fs/ecryptfs/crypto.c
@@ -149,7 +149,7 @@ out:
149 * ecryptfs_derive_iv 149 * ecryptfs_derive_iv
150 * @iv: destination for the derived iv vale 150 * @iv: destination for the derived iv vale
151 * @crypt_stat: Pointer to crypt_stat struct for the current inode 151 * @crypt_stat: Pointer to crypt_stat struct for the current inode
152 * @offset: Offset of the page whose's iv we are to derive 152 * @offset: Offset of the extent whose IV we are to derive
153 * 153 *
154 * Generate the initialization vector from the given root IV and page 154 * Generate the initialization vector from the given root IV and page
155 * offset. 155 * offset.
@@ -157,7 +157,7 @@ out:
157 * Returns zero on success; non-zero on error. 157 * Returns zero on success; non-zero on error.
158 */ 158 */
159static int ecryptfs_derive_iv(char *iv, struct ecryptfs_crypt_stat *crypt_stat, 159static int ecryptfs_derive_iv(char *iv, struct ecryptfs_crypt_stat *crypt_stat,
160 pgoff_t offset) 160 loff_t offset)
161{ 161{
162 int rc = 0; 162 int rc = 0;
163 char dst[MD5_DIGEST_SIZE]; 163 char dst[MD5_DIGEST_SIZE];
@@ -173,7 +173,7 @@ static int ecryptfs_derive_iv(char *iv, struct ecryptfs_crypt_stat *crypt_stat,
173 * hashing business. -Halcrow */ 173 * hashing business. -Halcrow */
174 memcpy(src, crypt_stat->root_iv, crypt_stat->iv_bytes); 174 memcpy(src, crypt_stat->root_iv, crypt_stat->iv_bytes);
175 memset((src + crypt_stat->iv_bytes), 0, 16); 175 memset((src + crypt_stat->iv_bytes), 0, 16);
176 snprintf((src + crypt_stat->iv_bytes), 16, "%ld", offset); 176 snprintf((src + crypt_stat->iv_bytes), 16, "%lld", offset);
177 if (unlikely(ecryptfs_verbosity > 0)) { 177 if (unlikely(ecryptfs_verbosity > 0)) {
178 ecryptfs_printk(KERN_DEBUG, "source:\n"); 178 ecryptfs_printk(KERN_DEBUG, "source:\n");
179 ecryptfs_dump_hex(src, (crypt_stat->iv_bytes + 16)); 179 ecryptfs_dump_hex(src, (crypt_stat->iv_bytes + 16));
@@ -497,11 +497,11 @@ static int ecryptfs_encrypt_extent(struct page *enc_extent_page,
497 struct page *page, 497 struct page *page,
498 unsigned long extent_offset) 498 unsigned long extent_offset)
499{ 499{
500 unsigned long extent_base; 500 loff_t extent_base;
501 char extent_iv[ECRYPTFS_MAX_IV_BYTES]; 501 char extent_iv[ECRYPTFS_MAX_IV_BYTES];
502 int rc; 502 int rc;
503 503
504 extent_base = (page->index 504 extent_base = (((loff_t)page->index)
505 * (PAGE_CACHE_SIZE / crypt_stat->extent_size)); 505 * (PAGE_CACHE_SIZE / crypt_stat->extent_size));
506 rc = ecryptfs_derive_iv(extent_iv, crypt_stat, 506 rc = ecryptfs_derive_iv(extent_iv, crypt_stat,
507 (extent_base + extent_offset)); 507 (extent_base + extent_offset));
@@ -605,8 +605,9 @@ int ecryptfs_encrypt_page(struct page *page)
605 goto out; 605 goto out;
606 } 606 }
607 ecryptfs_lower_offset_for_extent( 607 ecryptfs_lower_offset_for_extent(
608 &offset, ((page->index * (PAGE_CACHE_SIZE 608 &offset, ((((loff_t)page->index)
609 / crypt_stat->extent_size)) 609 * (PAGE_CACHE_SIZE
610 / crypt_stat->extent_size))
610 + extent_offset), crypt_stat); 611 + extent_offset), crypt_stat);
611 rc = ecryptfs_write_lower(ecryptfs_inode, enc_extent_virt, 612 rc = ecryptfs_write_lower(ecryptfs_inode, enc_extent_virt,
612 offset, crypt_stat->extent_size); 613 offset, crypt_stat->extent_size);
@@ -628,11 +629,11 @@ static int ecryptfs_decrypt_extent(struct page *page,
628 struct page *enc_extent_page, 629 struct page *enc_extent_page,
629 unsigned long extent_offset) 630 unsigned long extent_offset)
630{ 631{
631 unsigned long extent_base; 632 loff_t extent_base;
632 char extent_iv[ECRYPTFS_MAX_IV_BYTES]; 633 char extent_iv[ECRYPTFS_MAX_IV_BYTES];
633 int rc; 634 int rc;
634 635
635 extent_base = (page->index 636 extent_base = (((loff_t)page->index)
636 * (PAGE_CACHE_SIZE / crypt_stat->extent_size)); 637 * (PAGE_CACHE_SIZE / crypt_stat->extent_size));
637 rc = ecryptfs_derive_iv(extent_iv, crypt_stat, 638 rc = ecryptfs_derive_iv(extent_iv, crypt_stat,
638 (extent_base + extent_offset)); 639 (extent_base + extent_offset));
@@ -1471,7 +1472,7 @@ ecryptfs_write_metadata_to_contents(struct ecryptfs_crypt_stat *crypt_stat,
1471 while (current_header_page < header_pages) { 1472 while (current_header_page < header_pages) {
1472 loff_t offset; 1473 loff_t offset;
1473 1474
1474 offset = (current_header_page << PAGE_CACHE_SHIFT); 1475 offset = (((loff_t)current_header_page) << PAGE_CACHE_SHIFT);
1475 if ((rc = ecryptfs_write_lower(ecryptfs_dentry->d_inode, 1476 if ((rc = ecryptfs_write_lower(ecryptfs_dentry->d_inode,
1476 page_virt, offset, 1477 page_virt, offset,
1477 PAGE_CACHE_SIZE))) { 1478 PAGE_CACHE_SIZE))) {
diff --git a/fs/ecryptfs/mmap.c b/fs/ecryptfs/mmap.c
index 9bc707df3b60..6ae0afb238d1 100644
--- a/fs/ecryptfs/mmap.c
+++ b/fs/ecryptfs/mmap.c
@@ -286,7 +286,8 @@ ecryptfs_copy_up_encrypted_with_header(struct page *page,
286 int rc = 0; 286 int rc = 0;
287 287
288 while (extent_num_in_page < num_extents_per_page) { 288 while (extent_num_in_page < num_extents_per_page) {
289 loff_t view_extent_num = ((page->index * num_extents_per_page) 289 loff_t view_extent_num = ((((loff_t)page->index)
290 * num_extents_per_page)
290 + extent_num_in_page); 291 + extent_num_in_page);
291 292
292 if (view_extent_num < crypt_stat->num_header_extents_at_front) { 293 if (view_extent_num < crypt_stat->num_header_extents_at_front) {
@@ -706,7 +707,7 @@ static int ecryptfs_commit_write(struct file *file, struct page *page,
706 "index [0x%.16x])\n", page->index); 707 "index [0x%.16x])\n", page->index);
707 goto out; 708 goto out;
708 } 709 }
709 pos = (page->index << PAGE_CACHE_SHIFT) + to; 710 pos = (((loff_t)page->index) << PAGE_CACHE_SHIFT) + to;
710 if (pos > i_size_read(ecryptfs_inode)) { 711 if (pos > i_size_read(ecryptfs_inode)) {
711 i_size_write(ecryptfs_inode, pos); 712 i_size_write(ecryptfs_inode, pos);
712 ecryptfs_printk(KERN_DEBUG, "Expanded file size to " 713 ecryptfs_printk(KERN_DEBUG, "Expanded file size to "
diff --git a/fs/ecryptfs/read_write.c b/fs/ecryptfs/read_write.c
index ccd2599e0a4f..272eaeb9a738 100644
--- a/fs/ecryptfs/read_write.c
+++ b/fs/ecryptfs/read_write.c
@@ -87,7 +87,8 @@ int ecryptfs_write_lower_page_segment(struct inode *ecryptfs_inode,
87 loff_t offset; 87 loff_t offset;
88 int rc; 88 int rc;
89 89
90 offset = (page_for_lower->index << PAGE_CACHE_SHIFT) + offset_in_page; 90 offset = ((((off_t)page_for_lower->index) << PAGE_CACHE_SHIFT)
91 + offset_in_page);
91 virt = kmap(page_for_lower); 92 virt = kmap(page_for_lower);
92 rc = ecryptfs_write_lower(ecryptfs_inode, virt, offset, size); 93 rc = ecryptfs_write_lower(ecryptfs_inode, virt, offset, size);
93 kunmap(page_for_lower); 94 kunmap(page_for_lower);
@@ -117,7 +118,8 @@ int ecryptfs_write(struct file *ecryptfs_file, char *data, loff_t offset,
117{ 118{
118 struct page *ecryptfs_page; 119 struct page *ecryptfs_page;
119 char *ecryptfs_page_virt; 120 char *ecryptfs_page_virt;
120 u64 ecryptfs_file_size = i_size_read(ecryptfs_file->f_dentry->d_inode); 121 loff_t ecryptfs_file_size =
122 i_size_read(ecryptfs_file->f_dentry->d_inode);
121 loff_t data_offset = 0; 123 loff_t data_offset = 0;
122 loff_t pos; 124 loff_t pos;
123 int rc = 0; 125 int rc = 0;
@@ -277,7 +279,7 @@ int ecryptfs_read_lower_page_segment(struct page *page_for_ecryptfs,
277 loff_t offset; 279 loff_t offset;
278 int rc; 280 int rc;
279 281
280 offset = ((page_index << PAGE_CACHE_SHIFT) + offset_in_page); 282 offset = ((((loff_t)page_index) << PAGE_CACHE_SHIFT) + offset_in_page);
281 virt = kmap(page_for_ecryptfs); 283 virt = kmap(page_for_ecryptfs);
282 rc = ecryptfs_read_lower(virt, offset, size, ecryptfs_inode); 284 rc = ecryptfs_read_lower(virt, offset, size, ecryptfs_inode);
283 kunmap(page_for_ecryptfs); 285 kunmap(page_for_ecryptfs);
@@ -306,7 +308,8 @@ int ecryptfs_read(char *data, loff_t offset, size_t size,
306{ 308{
307 struct page *ecryptfs_page; 309 struct page *ecryptfs_page;
308 char *ecryptfs_page_virt; 310 char *ecryptfs_page_virt;
309 u64 ecryptfs_file_size = i_size_read(ecryptfs_file->f_dentry->d_inode); 311 loff_t ecryptfs_file_size =
312 i_size_read(ecryptfs_file->f_dentry->d_inode);
310 loff_t data_offset = 0; 313 loff_t data_offset = 0;
311 loff_t pos; 314 loff_t pos;
312 int rc = 0; 315 int rc = 0;