diff options
| author | Thomas Gleixner <tglx@linutronix.de> | 2013-07-12 06:34:42 -0400 |
|---|---|---|
| committer | Thomas Gleixner <tglx@linutronix.de> | 2013-07-12 06:34:42 -0400 |
| commit | f2006e27396f55276f24434f56e208d86e7f9908 (patch) | |
| tree | 71896db916d33888b4286f80117d3cac0da40e6d /fs/ecryptfs | |
| parent | e399eb56a6110e13f97e644658648602e2b08de7 (diff) | |
| parent | 9903883f1dd6e86f286b7bfa6e4b423f98c1cd9e (diff) | |
Merge branch 'linus' into timers/urgent
Get upstream changes so we can apply fixes against them
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Diffstat (limited to 'fs/ecryptfs')
| -rw-r--r-- | fs/ecryptfs/crypto.c | 342 | ||||
| -rw-r--r-- | fs/ecryptfs/ecryptfs_kernel.h | 2 | ||||
| -rw-r--r-- | fs/ecryptfs/file.c | 16 | ||||
| -rw-r--r-- | fs/ecryptfs/inode.c | 4 | ||||
| -rw-r--r-- | fs/ecryptfs/main.c | 7 | ||||
| -rw-r--r-- | fs/ecryptfs/messaging.c | 3 |
6 files changed, 94 insertions, 280 deletions
diff --git a/fs/ecryptfs/crypto.c b/fs/ecryptfs/crypto.c index f71ec125290d..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,142 +590,9 @@ 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; | 593 | return rc; |
| 646 | } | 594 | } |
| 647 | 595 | ||
| 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; | ||
| 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 | } | ||
| 776 | |||
| 777 | #define ECRYPTFS_MAX_SCATTERLIST_LEN 4 | 596 | #define ECRYPTFS_MAX_SCATTERLIST_LEN 4 |
| 778 | 597 | ||
| 779 | /** | 598 | /** |
| @@ -2243,12 +2062,11 @@ out: | |||
| 2243 | */ | 2062 | */ |
| 2244 | int ecryptfs_decode_and_decrypt_filename(char **plaintext_name, | 2063 | int ecryptfs_decode_and_decrypt_filename(char **plaintext_name, |
| 2245 | size_t *plaintext_name_size, | 2064 | size_t *plaintext_name_size, |
| 2246 | struct dentry *ecryptfs_dir_dentry, | 2065 | struct super_block *sb, |
| 2247 | const char *name, size_t name_size) | 2066 | const char *name, size_t name_size) |
| 2248 | { | 2067 | { |
| 2249 | struct ecryptfs_mount_crypt_stat *mount_crypt_stat = | 2068 | struct ecryptfs_mount_crypt_stat *mount_crypt_stat = |
| 2250 | &ecryptfs_superblock_to_private( | 2069 | &ecryptfs_superblock_to_private(sb)->mount_crypt_stat; |
| 2251 | ecryptfs_dir_dentry->d_sb)->mount_crypt_stat; | ||
| 2252 | char *decoded_name; | 2070 | char *decoded_name; |
| 2253 | size_t decoded_name_size; | 2071 | size_t decoded_name_size; |
| 2254 | size_t packet_size; | 2072 | size_t packet_size; |
diff --git a/fs/ecryptfs/ecryptfs_kernel.h b/fs/ecryptfs/ecryptfs_kernel.h index f622a733f7ad..df19d34a033b 100644 --- a/fs/ecryptfs/ecryptfs_kernel.h +++ b/fs/ecryptfs/ecryptfs_kernel.h | |||
| @@ -575,7 +575,7 @@ int ecryptfs_initialize_file(struct dentry *ecryptfs_dentry, | |||
| 575 | struct inode *ecryptfs_inode); | 575 | struct inode *ecryptfs_inode); |
| 576 | int ecryptfs_decode_and_decrypt_filename(char **decrypted_name, | 576 | int ecryptfs_decode_and_decrypt_filename(char **decrypted_name, |
| 577 | size_t *decrypted_name_size, | 577 | size_t *decrypted_name_size, |
| 578 | struct dentry *ecryptfs_dentry, | 578 | struct super_block *sb, |
| 579 | const char *name, size_t name_size); | 579 | const char *name, size_t name_size); |
| 580 | int ecryptfs_fill_zeros(struct file *file, loff_t new_length); | 580 | int ecryptfs_fill_zeros(struct file *file, loff_t new_length); |
| 581 | int ecryptfs_encrypt_and_encode_filename( | 581 | int ecryptfs_encrypt_and_encode_filename( |
diff --git a/fs/ecryptfs/file.c b/fs/ecryptfs/file.c index 9aa05e08060b..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 | } |
| @@ -70,7 +69,7 @@ static ssize_t ecryptfs_read_update_atime(struct kiocb *iocb, | |||
| 70 | struct ecryptfs_getdents_callback { | 69 | struct ecryptfs_getdents_callback { |
| 71 | struct dir_context ctx; | 70 | struct dir_context ctx; |
| 72 | struct dir_context *caller; | 71 | struct dir_context *caller; |
| 73 | struct dentry *dentry; | 72 | struct super_block *sb; |
| 74 | int filldir_called; | 73 | int filldir_called; |
| 75 | int entries_written; | 74 | int entries_written; |
| 76 | }; | 75 | }; |
| @@ -88,7 +87,7 @@ ecryptfs_filldir(void *dirent, const char *lower_name, int lower_namelen, | |||
| 88 | 87 | ||
| 89 | buf->filldir_called++; | 88 | buf->filldir_called++; |
| 90 | rc = ecryptfs_decode_and_decrypt_filename(&name, &name_size, | 89 | rc = ecryptfs_decode_and_decrypt_filename(&name, &name_size, |
| 91 | buf->dentry, lower_name, | 90 | buf->sb, lower_name, |
| 92 | lower_namelen); | 91 | lower_namelen); |
| 93 | if (rc) { | 92 | if (rc) { |
| 94 | printk(KERN_ERR "%s: Error attempting to decode and decrypt " | 93 | printk(KERN_ERR "%s: Error attempting to decode and decrypt " |
| @@ -114,15 +113,14 @@ static int ecryptfs_readdir(struct file *file, struct dir_context *ctx) | |||
| 114 | { | 113 | { |
| 115 | int rc; | 114 | int rc; |
| 116 | struct file *lower_file; | 115 | struct file *lower_file; |
| 117 | struct inode *inode; | 116 | struct inode *inode = file_inode(file); |
| 118 | struct ecryptfs_getdents_callback buf = { | 117 | struct ecryptfs_getdents_callback buf = { |
| 119 | .ctx.actor = ecryptfs_filldir, | 118 | .ctx.actor = ecryptfs_filldir, |
| 120 | .caller = ctx, | 119 | .caller = ctx, |
| 121 | .dentry = file->f_path.dentry | 120 | .sb = inode->i_sb, |
| 122 | }; | 121 | }; |
| 123 | lower_file = ecryptfs_file_to_lower(file); | 122 | lower_file = ecryptfs_file_to_lower(file); |
| 124 | lower_file->f_pos = ctx->pos; | 123 | lower_file->f_pos = ctx->pos; |
| 125 | inode = file_inode(file); | ||
| 126 | rc = iterate_dir(lower_file, &buf.ctx); | 124 | rc = iterate_dir(lower_file, &buf.ctx); |
| 127 | ctx->pos = buf.ctx.pos; | 125 | ctx->pos = buf.ctx.pos; |
| 128 | if (rc < 0) | 126 | if (rc < 0) |
diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c index 5eab400e2590..67e9b6339691 100644 --- a/fs/ecryptfs/inode.c +++ b/fs/ecryptfs/inode.c | |||
| @@ -358,7 +358,7 @@ static int ecryptfs_lookup_interpose(struct dentry *dentry, | |||
| 358 | 358 | ||
| 359 | lower_mnt = mntget(ecryptfs_dentry_to_lower_mnt(dentry->d_parent)); | 359 | lower_mnt = mntget(ecryptfs_dentry_to_lower_mnt(dentry->d_parent)); |
| 360 | fsstack_copy_attr_atime(dir_inode, lower_dentry->d_parent->d_inode); | 360 | fsstack_copy_attr_atime(dir_inode, lower_dentry->d_parent->d_inode); |
| 361 | BUG_ON(!lower_dentry->d_count); | 361 | BUG_ON(!d_count(lower_dentry)); |
| 362 | 362 | ||
| 363 | ecryptfs_set_dentry_private(dentry, dentry_info); | 363 | ecryptfs_set_dentry_private(dentry, dentry_info); |
| 364 | ecryptfs_set_dentry_lower(dentry, lower_dentry); | 364 | ecryptfs_set_dentry_lower(dentry, lower_dentry); |
| @@ -679,7 +679,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf, | |||
| 679 | set_fs(old_fs); | 679 | set_fs(old_fs); |
| 680 | if (rc < 0) | 680 | if (rc < 0) |
| 681 | goto out; | 681 | goto out; |
| 682 | rc = ecryptfs_decode_and_decrypt_filename(buf, bufsiz, dentry, | 682 | rc = ecryptfs_decode_and_decrypt_filename(buf, bufsiz, dentry->d_sb, |
| 683 | lower_buf, rc); | 683 | lower_buf, rc); |
| 684 | out: | 684 | out: |
| 685 | kfree(lower_buf); | 685 | kfree(lower_buf); |
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; |
