aboutsummaryrefslogtreecommitdiffstats
path: root/fs/ecryptfs/mmap.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/ecryptfs/mmap.c')
-rw-r--r--fs/ecryptfs/mmap.c35
1 files changed, 21 insertions, 14 deletions
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)