diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2013-07-11 13:20:18 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2013-07-11 13:20:18 -0400 |
commit | 746919d2668037f297595da9281a22cd558f3d18 (patch) | |
tree | 427ed5f852739537e6e378a98268fdf43c05a38e /fs/ecryptfs | |
parent | 9db019278cad416681e27b15203d4c5e939c315b (diff) | |
parent | cc18ec3c8f5dd735c1bff5da30fd33860c08a293 (diff) |
Merge tag 'ecryptfs-3.11-rc1-cleanup' of git://git.kernel.org/pub/scm/linux/kernel/git/tyhicks/ecryptfs
Pull eCryptfs updates from Tyler Hicks:
"Code cleanups and improved buffer handling during page crypto
operations:
- Remove redundant code by merging some encrypt and decrypt functions
- Get rid of a helper page allocation during page decryption by using
in-place decryption
- Better use of entire pages during page crypto operations
- Several code cleanups"
* tag 'ecryptfs-3.11-rc1-cleanup' of git://git.kernel.org/pub/scm/linux/kernel/git/tyhicks/ecryptfs:
Use ecryptfs_dentry_to_lower_path in a couple of places
eCryptfs: Make extent and scatterlist crypt function parameters similar
eCryptfs: Collapse crypt_page_offset() into crypt_extent()
eCryptfs: Merge ecryptfs_encrypt_extent() and ecryptfs_decrypt_extent()
eCryptfs: Combine page_offset crypto functions
eCryptfs: Combine encrypt_scatterlist() and decrypt_scatterlist()
eCryptfs: Decrypt pages in-place
eCryptfs: Accept one offset parameter in page offset crypto functions
eCryptfs: Simplify lower file offset calculation
eCryptfs: Read/write entire page during page IO
eCryptfs: Use entire helper page during page crypto operations
eCryptfs: Cocci spatch "memdup.spatch"
Diffstat (limited to 'fs/ecryptfs')
-rw-r--r-- | fs/ecryptfs/crypto.c | 337 | ||||
-rw-r--r-- | fs/ecryptfs/file.c | 7 | ||||
-rw-r--r-- | fs/ecryptfs/main.c | 7 | ||||
-rw-r--r-- | fs/ecryptfs/messaging.c | 3 |
4 files changed, 85 insertions, 269 deletions
diff --git a/fs/ecryptfs/crypto.c b/fs/ecryptfs/crypto.c index cfa109a4d5a2..d10757635b9c 100644 --- a/fs/ecryptfs/crypto.c +++ b/fs/ecryptfs/crypto.c | |||
@@ -37,16 +37,8 @@ | |||
37 | #include <asm/unaligned.h> | 37 | #include <asm/unaligned.h> |
38 | #include "ecryptfs_kernel.h" | 38 | #include "ecryptfs_kernel.h" |
39 | 39 | ||
40 | static int | 40 | #define DECRYPT 0 |
41 | ecryptfs_decrypt_page_offset(struct ecryptfs_crypt_stat *crypt_stat, | 41 | #define ENCRYPT 1 |
42 | struct page *dst_page, int dst_offset, | ||
43 | struct page *src_page, int src_offset, int size, | ||
44 | unsigned char *iv); | ||
45 | static int | ||
46 | ecryptfs_encrypt_page_offset(struct ecryptfs_crypt_stat *crypt_stat, | ||
47 | struct page *dst_page, int dst_offset, | ||
48 | struct page *src_page, int src_offset, int size, | ||
49 | unsigned char *iv); | ||
50 | 42 | ||
51 | /** | 43 | /** |
52 | * ecryptfs_to_hex | 44 | * ecryptfs_to_hex |
@@ -336,19 +328,20 @@ static void extent_crypt_complete(struct crypto_async_request *req, int rc) | |||
336 | } | 328 | } |
337 | 329 | ||
338 | /** | 330 | /** |
339 | * encrypt_scatterlist | 331 | * crypt_scatterlist |
340 | * @crypt_stat: Pointer to the crypt_stat struct to initialize. | 332 | * @crypt_stat: Pointer to the crypt_stat struct to initialize. |
341 | * @dest_sg: Destination of encrypted data | 333 | * @dst_sg: Destination of the data after performing the crypto operation |
342 | * @src_sg: Data to be encrypted | 334 | * @src_sg: Data to be encrypted or decrypted |
343 | * @size: Length of data to be encrypted | 335 | * @size: Length of data |
344 | * @iv: iv to use during encryption | 336 | * @iv: IV to use |
337 | * @op: ENCRYPT or DECRYPT to indicate the desired operation | ||
345 | * | 338 | * |
346 | * Returns the number of bytes encrypted; negative value on error | 339 | * Returns the number of bytes encrypted or decrypted; negative value on error |
347 | */ | 340 | */ |
348 | static int encrypt_scatterlist(struct ecryptfs_crypt_stat *crypt_stat, | 341 | static int crypt_scatterlist(struct ecryptfs_crypt_stat *crypt_stat, |
349 | struct scatterlist *dest_sg, | 342 | struct scatterlist *dst_sg, |
350 | struct scatterlist *src_sg, int size, | 343 | struct scatterlist *src_sg, int size, |
351 | unsigned char *iv) | 344 | unsigned char *iv, int op) |
352 | { | 345 | { |
353 | struct ablkcipher_request *req = NULL; | 346 | struct ablkcipher_request *req = NULL; |
354 | struct extent_crypt_result ecr; | 347 | struct extent_crypt_result ecr; |
@@ -391,9 +384,9 @@ static int encrypt_scatterlist(struct ecryptfs_crypt_stat *crypt_stat, | |||
391 | crypt_stat->flags |= ECRYPTFS_KEY_SET; | 384 | crypt_stat->flags |= ECRYPTFS_KEY_SET; |
392 | } | 385 | } |
393 | mutex_unlock(&crypt_stat->cs_tfm_mutex); | 386 | mutex_unlock(&crypt_stat->cs_tfm_mutex); |
394 | ecryptfs_printk(KERN_DEBUG, "Encrypting [%d] bytes.\n", size); | 387 | ablkcipher_request_set_crypt(req, src_sg, dst_sg, size, iv); |
395 | ablkcipher_request_set_crypt(req, src_sg, dest_sg, size, iv); | 388 | rc = op == ENCRYPT ? crypto_ablkcipher_encrypt(req) : |
396 | rc = crypto_ablkcipher_encrypt(req); | 389 | crypto_ablkcipher_decrypt(req); |
397 | if (rc == -EINPROGRESS || rc == -EBUSY) { | 390 | if (rc == -EINPROGRESS || rc == -EBUSY) { |
398 | struct extent_crypt_result *ecr = req->base.data; | 391 | struct extent_crypt_result *ecr = req->base.data; |
399 | 392 | ||
@@ -407,41 +400,43 @@ out: | |||
407 | } | 400 | } |
408 | 401 | ||
409 | /** | 402 | /** |
410 | * ecryptfs_lower_offset_for_extent | 403 | * lower_offset_for_page |
411 | * | 404 | * |
412 | * Convert an eCryptfs page index into a lower byte offset | 405 | * Convert an eCryptfs page index into a lower byte offset |
413 | */ | 406 | */ |
414 | static void ecryptfs_lower_offset_for_extent(loff_t *offset, loff_t extent_num, | 407 | static loff_t lower_offset_for_page(struct ecryptfs_crypt_stat *crypt_stat, |
415 | struct ecryptfs_crypt_stat *crypt_stat) | 408 | struct page *page) |
416 | { | 409 | { |
417 | (*offset) = ecryptfs_lower_header_size(crypt_stat) | 410 | return ecryptfs_lower_header_size(crypt_stat) + |
418 | + (crypt_stat->extent_size * extent_num); | 411 | (page->index << PAGE_CACHE_SHIFT); |
419 | } | 412 | } |
420 | 413 | ||
421 | /** | 414 | /** |
422 | * ecryptfs_encrypt_extent | 415 | * crypt_extent |
423 | * @enc_extent_page: Allocated page into which to encrypt the data in | ||
424 | * @page | ||
425 | * @crypt_stat: crypt_stat containing cryptographic context for the | 416 | * @crypt_stat: crypt_stat containing cryptographic context for the |
426 | * encryption operation | 417 | * encryption operation |
427 | * @page: Page containing plaintext data extent to encrypt | 418 | * @dst_page: The page to write the result into |
419 | * @src_page: The page to read from | ||
428 | * @extent_offset: Page extent offset for use in generating IV | 420 | * @extent_offset: Page extent offset for use in generating IV |
421 | * @op: ENCRYPT or DECRYPT to indicate the desired operation | ||
429 | * | 422 | * |
430 | * Encrypts one extent of data. | 423 | * Encrypts or decrypts one extent of data. |
431 | * | 424 | * |
432 | * Return zero on success; non-zero otherwise | 425 | * Return zero on success; non-zero otherwise |
433 | */ | 426 | */ |
434 | static int ecryptfs_encrypt_extent(struct page *enc_extent_page, | 427 | static int crypt_extent(struct ecryptfs_crypt_stat *crypt_stat, |
435 | struct ecryptfs_crypt_stat *crypt_stat, | 428 | struct page *dst_page, |
436 | struct page *page, | 429 | struct page *src_page, |
437 | unsigned long extent_offset) | 430 | unsigned long extent_offset, int op) |
438 | { | 431 | { |
432 | pgoff_t page_index = op == ENCRYPT ? src_page->index : dst_page->index; | ||
439 | loff_t extent_base; | 433 | loff_t extent_base; |
440 | char extent_iv[ECRYPTFS_MAX_IV_BYTES]; | 434 | char extent_iv[ECRYPTFS_MAX_IV_BYTES]; |
435 | struct scatterlist src_sg, dst_sg; | ||
436 | size_t extent_size = crypt_stat->extent_size; | ||
441 | int rc; | 437 | int rc; |
442 | 438 | ||
443 | extent_base = (((loff_t)page->index) | 439 | extent_base = (((loff_t)page_index) * (PAGE_CACHE_SIZE / extent_size)); |
444 | * (PAGE_CACHE_SIZE / crypt_stat->extent_size)); | ||
445 | rc = ecryptfs_derive_iv(extent_iv, crypt_stat, | 440 | rc = ecryptfs_derive_iv(extent_iv, crypt_stat, |
446 | (extent_base + extent_offset)); | 441 | (extent_base + extent_offset)); |
447 | if (rc) { | 442 | if (rc) { |
@@ -450,15 +445,21 @@ static int ecryptfs_encrypt_extent(struct page *enc_extent_page, | |||
450 | (unsigned long long)(extent_base + extent_offset), rc); | 445 | (unsigned long long)(extent_base + extent_offset), rc); |
451 | goto out; | 446 | goto out; |
452 | } | 447 | } |
453 | rc = ecryptfs_encrypt_page_offset(crypt_stat, enc_extent_page, 0, | 448 | |
454 | page, (extent_offset | 449 | sg_init_table(&src_sg, 1); |
455 | * crypt_stat->extent_size), | 450 | sg_init_table(&dst_sg, 1); |
456 | crypt_stat->extent_size, extent_iv); | 451 | |
452 | sg_set_page(&src_sg, src_page, extent_size, | ||
453 | extent_offset * extent_size); | ||
454 | sg_set_page(&dst_sg, dst_page, extent_size, | ||
455 | extent_offset * extent_size); | ||
456 | |||
457 | rc = crypt_scatterlist(crypt_stat, &dst_sg, &src_sg, extent_size, | ||
458 | extent_iv, op); | ||
457 | if (rc < 0) { | 459 | if (rc < 0) { |
458 | printk(KERN_ERR "%s: Error attempting to encrypt page with " | 460 | printk(KERN_ERR "%s: Error attempting to crypt page with " |
459 | "page->index = [%ld], extent_offset = [%ld]; " | 461 | "page_index = [%ld], extent_offset = [%ld]; " |
460 | "rc = [%d]\n", __func__, page->index, extent_offset, | 462 | "rc = [%d]\n", __func__, page_index, extent_offset, rc); |
461 | rc); | ||
462 | goto out; | 463 | goto out; |
463 | } | 464 | } |
464 | rc = 0; | 465 | rc = 0; |
@@ -489,6 +490,7 @@ int ecryptfs_encrypt_page(struct page *page) | |||
489 | char *enc_extent_virt; | 490 | char *enc_extent_virt; |
490 | struct page *enc_extent_page = NULL; | 491 | struct page *enc_extent_page = NULL; |
491 | loff_t extent_offset; | 492 | loff_t extent_offset; |
493 | loff_t lower_offset; | ||
492 | int rc = 0; | 494 | int rc = 0; |
493 | 495 | ||
494 | ecryptfs_inode = page->mapping->host; | 496 | ecryptfs_inode = page->mapping->host; |
@@ -502,75 +504,35 @@ int ecryptfs_encrypt_page(struct page *page) | |||
502 | "encrypted extent\n"); | 504 | "encrypted extent\n"); |
503 | goto out; | 505 | goto out; |
504 | } | 506 | } |
505 | enc_extent_virt = kmap(enc_extent_page); | 507 | |
506 | for (extent_offset = 0; | 508 | for (extent_offset = 0; |
507 | extent_offset < (PAGE_CACHE_SIZE / crypt_stat->extent_size); | 509 | extent_offset < (PAGE_CACHE_SIZE / crypt_stat->extent_size); |
508 | extent_offset++) { | 510 | extent_offset++) { |
509 | loff_t offset; | 511 | rc = crypt_extent(crypt_stat, enc_extent_page, page, |
510 | 512 | extent_offset, ENCRYPT); | |
511 | rc = ecryptfs_encrypt_extent(enc_extent_page, crypt_stat, page, | ||
512 | extent_offset); | ||
513 | if (rc) { | 513 | if (rc) { |
514 | printk(KERN_ERR "%s: Error encrypting extent; " | 514 | printk(KERN_ERR "%s: Error encrypting extent; " |
515 | "rc = [%d]\n", __func__, rc); | 515 | "rc = [%d]\n", __func__, rc); |
516 | goto out; | 516 | goto out; |
517 | } | 517 | } |
518 | ecryptfs_lower_offset_for_extent( | ||
519 | &offset, ((((loff_t)page->index) | ||
520 | * (PAGE_CACHE_SIZE | ||
521 | / crypt_stat->extent_size)) | ||
522 | + extent_offset), crypt_stat); | ||
523 | rc = ecryptfs_write_lower(ecryptfs_inode, enc_extent_virt, | ||
524 | offset, crypt_stat->extent_size); | ||
525 | if (rc < 0) { | ||
526 | ecryptfs_printk(KERN_ERR, "Error attempting " | ||
527 | "to write lower page; rc = [%d]" | ||
528 | "\n", rc); | ||
529 | goto out; | ||
530 | } | ||
531 | } | ||
532 | rc = 0; | ||
533 | out: | ||
534 | if (enc_extent_page) { | ||
535 | kunmap(enc_extent_page); | ||
536 | __free_page(enc_extent_page); | ||
537 | } | 518 | } |
538 | return rc; | ||
539 | } | ||
540 | 519 | ||
541 | static int ecryptfs_decrypt_extent(struct page *page, | 520 | lower_offset = lower_offset_for_page(crypt_stat, page); |
542 | struct ecryptfs_crypt_stat *crypt_stat, | 521 | enc_extent_virt = kmap(enc_extent_page); |
543 | struct page *enc_extent_page, | 522 | rc = ecryptfs_write_lower(ecryptfs_inode, enc_extent_virt, lower_offset, |
544 | unsigned long extent_offset) | 523 | PAGE_CACHE_SIZE); |
545 | { | 524 | kunmap(enc_extent_page); |
546 | loff_t extent_base; | ||
547 | char extent_iv[ECRYPTFS_MAX_IV_BYTES]; | ||
548 | int rc; | ||
549 | |||
550 | extent_base = (((loff_t)page->index) | ||
551 | * (PAGE_CACHE_SIZE / crypt_stat->extent_size)); | ||
552 | rc = ecryptfs_derive_iv(extent_iv, crypt_stat, | ||
553 | (extent_base + extent_offset)); | ||
554 | if (rc) { | ||
555 | ecryptfs_printk(KERN_ERR, "Error attempting to derive IV for " | ||
556 | "extent [0x%.16llx]; rc = [%d]\n", | ||
557 | (unsigned long long)(extent_base + extent_offset), rc); | ||
558 | goto out; | ||
559 | } | ||
560 | rc = ecryptfs_decrypt_page_offset(crypt_stat, page, | ||
561 | (extent_offset | ||
562 | * crypt_stat->extent_size), | ||
563 | enc_extent_page, 0, | ||
564 | crypt_stat->extent_size, extent_iv); | ||
565 | if (rc < 0) { | 525 | if (rc < 0) { |
566 | printk(KERN_ERR "%s: Error attempting to decrypt to page with " | 526 | ecryptfs_printk(KERN_ERR, |
567 | "page->index = [%ld], extent_offset = [%ld]; " | 527 | "Error attempting to write lower page; rc = [%d]\n", |
568 | "rc = [%d]\n", __func__, page->index, extent_offset, | 528 | rc); |
569 | rc); | ||
570 | goto out; | 529 | goto out; |
571 | } | 530 | } |
572 | rc = 0; | 531 | rc = 0; |
573 | out: | 532 | out: |
533 | if (enc_extent_page) { | ||
534 | __free_page(enc_extent_page); | ||
535 | } | ||
574 | return rc; | 536 | return rc; |
575 | } | 537 | } |
576 | 538 | ||
@@ -594,43 +556,33 @@ int ecryptfs_decrypt_page(struct page *page) | |||
594 | { | 556 | { |
595 | struct inode *ecryptfs_inode; | 557 | struct inode *ecryptfs_inode; |
596 | struct ecryptfs_crypt_stat *crypt_stat; | 558 | struct ecryptfs_crypt_stat *crypt_stat; |
597 | char *enc_extent_virt; | 559 | char *page_virt; |
598 | struct page *enc_extent_page = NULL; | ||
599 | unsigned long extent_offset; | 560 | unsigned long extent_offset; |
561 | loff_t lower_offset; | ||
600 | int rc = 0; | 562 | int rc = 0; |
601 | 563 | ||
602 | ecryptfs_inode = page->mapping->host; | 564 | ecryptfs_inode = page->mapping->host; |
603 | crypt_stat = | 565 | crypt_stat = |
604 | &(ecryptfs_inode_to_private(ecryptfs_inode)->crypt_stat); | 566 | &(ecryptfs_inode_to_private(ecryptfs_inode)->crypt_stat); |
605 | BUG_ON(!(crypt_stat->flags & ECRYPTFS_ENCRYPTED)); | 567 | BUG_ON(!(crypt_stat->flags & ECRYPTFS_ENCRYPTED)); |
606 | enc_extent_page = alloc_page(GFP_USER); | 568 | |
607 | if (!enc_extent_page) { | 569 | lower_offset = lower_offset_for_page(crypt_stat, page); |
608 | rc = -ENOMEM; | 570 | page_virt = kmap(page); |
609 | ecryptfs_printk(KERN_ERR, "Error allocating memory for " | 571 | rc = ecryptfs_read_lower(page_virt, lower_offset, PAGE_CACHE_SIZE, |
610 | "encrypted extent\n"); | 572 | ecryptfs_inode); |
573 | kunmap(page); | ||
574 | if (rc < 0) { | ||
575 | ecryptfs_printk(KERN_ERR, | ||
576 | "Error attempting to read lower page; rc = [%d]\n", | ||
577 | rc); | ||
611 | goto out; | 578 | goto out; |
612 | } | 579 | } |
613 | enc_extent_virt = kmap(enc_extent_page); | 580 | |
614 | for (extent_offset = 0; | 581 | for (extent_offset = 0; |
615 | extent_offset < (PAGE_CACHE_SIZE / crypt_stat->extent_size); | 582 | extent_offset < (PAGE_CACHE_SIZE / crypt_stat->extent_size); |
616 | extent_offset++) { | 583 | extent_offset++) { |
617 | loff_t offset; | 584 | rc = crypt_extent(crypt_stat, page, page, |
618 | 585 | extent_offset, DECRYPT); | |
619 | ecryptfs_lower_offset_for_extent( | ||
620 | &offset, ((page->index * (PAGE_CACHE_SIZE | ||
621 | / crypt_stat->extent_size)) | ||
622 | + extent_offset), crypt_stat); | ||
623 | rc = ecryptfs_read_lower(enc_extent_virt, offset, | ||
624 | crypt_stat->extent_size, | ||
625 | ecryptfs_inode); | ||
626 | if (rc < 0) { | ||
627 | ecryptfs_printk(KERN_ERR, "Error attempting " | ||
628 | "to read lower page; rc = [%d]" | ||
629 | "\n", rc); | ||
630 | goto out; | ||
631 | } | ||
632 | rc = ecryptfs_decrypt_extent(page, crypt_stat, enc_extent_page, | ||
633 | extent_offset); | ||
634 | if (rc) { | 586 | if (rc) { |
635 | printk(KERN_ERR "%s: Error encrypting extent; " | 587 | printk(KERN_ERR "%s: Error encrypting extent; " |
636 | "rc = [%d]\n", __func__, rc); | 588 | "rc = [%d]\n", __func__, rc); |
@@ -638,140 +590,7 @@ int ecryptfs_decrypt_page(struct page *page) | |||
638 | } | 590 | } |
639 | } | 591 | } |
640 | out: | 592 | out: |
641 | if (enc_extent_page) { | ||
642 | kunmap(enc_extent_page); | ||
643 | __free_page(enc_extent_page); | ||
644 | } | ||
645 | return rc; | ||
646 | } | ||
647 | |||
648 | /** | ||
649 | * decrypt_scatterlist | ||
650 | * @crypt_stat: Cryptographic context | ||
651 | * @dest_sg: The destination scatterlist to decrypt into | ||
652 | * @src_sg: The source scatterlist to decrypt from | ||
653 | * @size: The number of bytes to decrypt | ||
654 | * @iv: The initialization vector to use for the decryption | ||
655 | * | ||
656 | * Returns the number of bytes decrypted; negative value on error | ||
657 | */ | ||
658 | static int decrypt_scatterlist(struct ecryptfs_crypt_stat *crypt_stat, | ||
659 | struct scatterlist *dest_sg, | ||
660 | struct scatterlist *src_sg, int size, | ||
661 | unsigned char *iv) | ||
662 | { | ||
663 | struct ablkcipher_request *req = NULL; | ||
664 | struct extent_crypt_result ecr; | ||
665 | int rc = 0; | ||
666 | |||
667 | BUG_ON(!crypt_stat || !crypt_stat->tfm | ||
668 | || !(crypt_stat->flags & ECRYPTFS_STRUCT_INITIALIZED)); | ||
669 | if (unlikely(ecryptfs_verbosity > 0)) { | ||
670 | ecryptfs_printk(KERN_DEBUG, "Key size [%zd]; key:\n", | ||
671 | crypt_stat->key_size); | ||
672 | ecryptfs_dump_hex(crypt_stat->key, | ||
673 | crypt_stat->key_size); | ||
674 | } | ||
675 | |||
676 | init_completion(&ecr.completion); | ||
677 | |||
678 | mutex_lock(&crypt_stat->cs_tfm_mutex); | ||
679 | req = ablkcipher_request_alloc(crypt_stat->tfm, GFP_NOFS); | ||
680 | if (!req) { | ||
681 | mutex_unlock(&crypt_stat->cs_tfm_mutex); | ||
682 | rc = -ENOMEM; | ||
683 | goto out; | ||
684 | } | ||
685 | |||
686 | ablkcipher_request_set_callback(req, | ||
687 | CRYPTO_TFM_REQ_MAY_BACKLOG | CRYPTO_TFM_REQ_MAY_SLEEP, | ||
688 | extent_crypt_complete, &ecr); | ||
689 | /* Consider doing this once, when the file is opened */ | ||
690 | if (!(crypt_stat->flags & ECRYPTFS_KEY_SET)) { | ||
691 | rc = crypto_ablkcipher_setkey(crypt_stat->tfm, crypt_stat->key, | ||
692 | crypt_stat->key_size); | ||
693 | if (rc) { | ||
694 | ecryptfs_printk(KERN_ERR, | ||
695 | "Error setting key; rc = [%d]\n", | ||
696 | rc); | ||
697 | mutex_unlock(&crypt_stat->cs_tfm_mutex); | ||
698 | rc = -EINVAL; | ||
699 | goto out; | ||
700 | } | ||
701 | crypt_stat->flags |= ECRYPTFS_KEY_SET; | ||
702 | } | ||
703 | mutex_unlock(&crypt_stat->cs_tfm_mutex); | ||
704 | ecryptfs_printk(KERN_DEBUG, "Decrypting [%d] bytes.\n", size); | ||
705 | ablkcipher_request_set_crypt(req, src_sg, dest_sg, size, iv); | ||
706 | rc = crypto_ablkcipher_decrypt(req); | ||
707 | if (rc == -EINPROGRESS || rc == -EBUSY) { | ||
708 | struct extent_crypt_result *ecr = req->base.data; | ||
709 | |||
710 | wait_for_completion(&ecr->completion); | ||
711 | rc = ecr->rc; | ||
712 | INIT_COMPLETION(ecr->completion); | ||
713 | } | ||
714 | out: | ||
715 | ablkcipher_request_free(req); | ||
716 | return rc; | 593 | return rc; |
717 | |||
718 | } | ||
719 | |||
720 | /** | ||
721 | * ecryptfs_encrypt_page_offset | ||
722 | * @crypt_stat: The cryptographic context | ||
723 | * @dst_page: The page to encrypt into | ||
724 | * @dst_offset: The offset in the page to encrypt into | ||
725 | * @src_page: The page to encrypt from | ||
726 | * @src_offset: The offset in the page to encrypt from | ||
727 | * @size: The number of bytes to encrypt | ||
728 | * @iv: The initialization vector to use for the encryption | ||
729 | * | ||
730 | * Returns the number of bytes encrypted | ||
731 | */ | ||
732 | static int | ||
733 | ecryptfs_encrypt_page_offset(struct ecryptfs_crypt_stat *crypt_stat, | ||
734 | struct page *dst_page, int dst_offset, | ||
735 | struct page *src_page, int src_offset, int size, | ||
736 | unsigned char *iv) | ||
737 | { | ||
738 | struct scatterlist src_sg, dst_sg; | ||
739 | |||
740 | sg_init_table(&src_sg, 1); | ||
741 | sg_init_table(&dst_sg, 1); | ||
742 | |||
743 | sg_set_page(&src_sg, src_page, size, src_offset); | ||
744 | sg_set_page(&dst_sg, dst_page, size, dst_offset); | ||
745 | return encrypt_scatterlist(crypt_stat, &dst_sg, &src_sg, size, iv); | ||
746 | } | ||
747 | |||
748 | /** | ||
749 | * ecryptfs_decrypt_page_offset | ||
750 | * @crypt_stat: The cryptographic context | ||
751 | * @dst_page: The page to decrypt into | ||
752 | * @dst_offset: The offset in the page to decrypt into | ||
753 | * @src_page: The page to decrypt from | ||
754 | * @src_offset: The offset in the page to decrypt from | ||
755 | * @size: The number of bytes to decrypt | ||
756 | * @iv: The initialization vector to use for the decryption | ||
757 | * | ||
758 | * Returns the number of bytes decrypted | ||
759 | */ | ||
760 | static int | ||
761 | ecryptfs_decrypt_page_offset(struct ecryptfs_crypt_stat *crypt_stat, | ||
762 | struct page *dst_page, int dst_offset, | ||
763 | struct page *src_page, int src_offset, int size, | ||
764 | unsigned char *iv) | ||
765 | { | ||
766 | struct scatterlist src_sg, dst_sg; | ||
767 | |||
768 | sg_init_table(&src_sg, 1); | ||
769 | sg_set_page(&src_sg, src_page, size, src_offset); | ||
770 | |||
771 | sg_init_table(&dst_sg, 1); | ||
772 | sg_set_page(&dst_sg, dst_page, size, dst_offset); | ||
773 | |||
774 | return decrypt_scatterlist(crypt_stat, &dst_sg, &src_sg, size, iv); | ||
775 | } | 594 | } |
776 | 595 | ||
777 | #define ECRYPTFS_MAX_SCATTERLIST_LEN 4 | 596 | #define ECRYPTFS_MAX_SCATTERLIST_LEN 4 |
diff --git a/fs/ecryptfs/file.c b/fs/ecryptfs/file.c index 24f1105fda3a..992cf95830b5 100644 --- a/fs/ecryptfs/file.c +++ b/fs/ecryptfs/file.c | |||
@@ -49,7 +49,7 @@ static ssize_t ecryptfs_read_update_atime(struct kiocb *iocb, | |||
49 | unsigned long nr_segs, loff_t pos) | 49 | unsigned long nr_segs, loff_t pos) |
50 | { | 50 | { |
51 | ssize_t rc; | 51 | ssize_t rc; |
52 | struct path lower; | 52 | struct path *path; |
53 | struct file *file = iocb->ki_filp; | 53 | struct file *file = iocb->ki_filp; |
54 | 54 | ||
55 | rc = generic_file_aio_read(iocb, iov, nr_segs, pos); | 55 | rc = generic_file_aio_read(iocb, iov, nr_segs, pos); |
@@ -60,9 +60,8 @@ static ssize_t ecryptfs_read_update_atime(struct kiocb *iocb, | |||
60 | if (-EIOCBQUEUED == rc) | 60 | if (-EIOCBQUEUED == rc) |
61 | rc = wait_on_sync_kiocb(iocb); | 61 | rc = wait_on_sync_kiocb(iocb); |
62 | if (rc >= 0) { | 62 | if (rc >= 0) { |
63 | lower.dentry = ecryptfs_dentry_to_lower(file->f_path.dentry); | 63 | path = ecryptfs_dentry_to_lower_path(file->f_path.dentry); |
64 | lower.mnt = ecryptfs_dentry_to_lower_mnt(file->f_path.dentry); | 64 | touch_atime(path); |
65 | touch_atime(&lower); | ||
66 | } | 65 | } |
67 | return rc; | 66 | return rc; |
68 | } | 67 | } |
diff --git a/fs/ecryptfs/main.c b/fs/ecryptfs/main.c index e924cf45aad9..eb1c5979ecaf 100644 --- a/fs/ecryptfs/main.c +++ b/fs/ecryptfs/main.c | |||
@@ -120,16 +120,15 @@ static int ecryptfs_init_lower_file(struct dentry *dentry, | |||
120 | struct file **lower_file) | 120 | struct file **lower_file) |
121 | { | 121 | { |
122 | const struct cred *cred = current_cred(); | 122 | const struct cred *cred = current_cred(); |
123 | struct dentry *lower_dentry = ecryptfs_dentry_to_lower(dentry); | 123 | struct path *path = ecryptfs_dentry_to_lower_path(dentry); |
124 | struct vfsmount *lower_mnt = ecryptfs_dentry_to_lower_mnt(dentry); | ||
125 | int rc; | 124 | int rc; |
126 | 125 | ||
127 | rc = ecryptfs_privileged_open(lower_file, lower_dentry, lower_mnt, | 126 | rc = ecryptfs_privileged_open(lower_file, path->dentry, path->mnt, |
128 | cred); | 127 | cred); |
129 | if (rc) { | 128 | if (rc) { |
130 | printk(KERN_ERR "Error opening lower file " | 129 | printk(KERN_ERR "Error opening lower file " |
131 | "for lower_dentry [0x%p] and lower_mnt [0x%p]; " | 130 | "for lower_dentry [0x%p] and lower_mnt [0x%p]; " |
132 | "rc = [%d]\n", lower_dentry, lower_mnt, rc); | 131 | "rc = [%d]\n", path->dentry, path->mnt, rc); |
133 | (*lower_file) = NULL; | 132 | (*lower_file) = NULL; |
134 | } | 133 | } |
135 | return rc; | 134 | return rc; |
diff --git a/fs/ecryptfs/messaging.c b/fs/ecryptfs/messaging.c index 49ff8ea08f1c..e57380e5f6bd 100644 --- a/fs/ecryptfs/messaging.c +++ b/fs/ecryptfs/messaging.c | |||
@@ -247,14 +247,13 @@ int ecryptfs_process_response(struct ecryptfs_daemon *daemon, | |||
247 | goto unlock; | 247 | goto unlock; |
248 | } | 248 | } |
249 | msg_size = (sizeof(*msg) + msg->data_len); | 249 | msg_size = (sizeof(*msg) + msg->data_len); |
250 | msg_ctx->msg = kmalloc(msg_size, GFP_KERNEL); | 250 | msg_ctx->msg = kmemdup(msg, msg_size, GFP_KERNEL); |
251 | if (!msg_ctx->msg) { | 251 | if (!msg_ctx->msg) { |
252 | rc = -ENOMEM; | 252 | rc = -ENOMEM; |
253 | printk(KERN_ERR "%s: Failed to allocate [%zd] bytes of " | 253 | printk(KERN_ERR "%s: Failed to allocate [%zd] bytes of " |
254 | "GFP_KERNEL memory\n", __func__, msg_size); | 254 | "GFP_KERNEL memory\n", __func__, msg_size); |
255 | goto unlock; | 255 | goto unlock; |
256 | } | 256 | } |
257 | memcpy(msg_ctx->msg, msg, msg_size); | ||
258 | msg_ctx->state = ECRYPTFS_MSG_CTX_STATE_DONE; | 257 | msg_ctx->state = ECRYPTFS_MSG_CTX_STATE_DONE; |
259 | wake_up_process(msg_ctx->task); | 258 | wake_up_process(msg_ctx->task); |
260 | rc = 0; | 259 | rc = 0; |