diff options
Diffstat (limited to 'fs/ecryptfs')
-rw-r--r-- | fs/ecryptfs/crypto.c | 4 | ||||
-rw-r--r-- | fs/ecryptfs/file.c | 17 | ||||
-rw-r--r-- | fs/ecryptfs/inode.c | 158 | ||||
-rw-r--r-- | fs/ecryptfs/main.c | 4 |
4 files changed, 121 insertions, 62 deletions
diff --git a/fs/ecryptfs/crypto.c b/fs/ecryptfs/crypto.c index fbb6e5eed697..7cb0a59f4b9d 100644 --- a/fs/ecryptfs/crypto.c +++ b/fs/ecryptfs/crypto.c | |||
@@ -1748,7 +1748,7 @@ ecryptfs_process_key_cipher(struct crypto_blkcipher **key_tfm, | |||
1748 | char *cipher_name, size_t *key_size) | 1748 | char *cipher_name, size_t *key_size) |
1749 | { | 1749 | { |
1750 | char dummy_key[ECRYPTFS_MAX_KEY_BYTES]; | 1750 | char dummy_key[ECRYPTFS_MAX_KEY_BYTES]; |
1751 | char *full_alg_name; | 1751 | char *full_alg_name = NULL; |
1752 | int rc; | 1752 | int rc; |
1753 | 1753 | ||
1754 | *key_tfm = NULL; | 1754 | *key_tfm = NULL; |
@@ -1763,7 +1763,6 @@ ecryptfs_process_key_cipher(struct crypto_blkcipher **key_tfm, | |||
1763 | if (rc) | 1763 | if (rc) |
1764 | goto out; | 1764 | goto out; |
1765 | *key_tfm = crypto_alloc_blkcipher(full_alg_name, 0, CRYPTO_ALG_ASYNC); | 1765 | *key_tfm = crypto_alloc_blkcipher(full_alg_name, 0, CRYPTO_ALG_ASYNC); |
1766 | kfree(full_alg_name); | ||
1767 | if (IS_ERR(*key_tfm)) { | 1766 | if (IS_ERR(*key_tfm)) { |
1768 | rc = PTR_ERR(*key_tfm); | 1767 | rc = PTR_ERR(*key_tfm); |
1769 | printk(KERN_ERR "Unable to allocate crypto cipher with name " | 1768 | printk(KERN_ERR "Unable to allocate crypto cipher with name " |
@@ -1786,6 +1785,7 @@ ecryptfs_process_key_cipher(struct crypto_blkcipher **key_tfm, | |||
1786 | goto out; | 1785 | goto out; |
1787 | } | 1786 | } |
1788 | out: | 1787 | out: |
1788 | kfree(full_alg_name); | ||
1789 | return rc; | 1789 | return rc; |
1790 | } | 1790 | } |
1791 | 1791 | ||
diff --git a/fs/ecryptfs/file.c b/fs/ecryptfs/file.c index 9e944057001b..678172b61be2 100644 --- a/fs/ecryptfs/file.c +++ b/fs/ecryptfs/file.c | |||
@@ -158,7 +158,7 @@ static int ecryptfs_open(struct inode *inode, struct file *file) | |||
158 | struct dentry *ecryptfs_dentry = file->f_path.dentry; | 158 | struct dentry *ecryptfs_dentry = file->f_path.dentry; |
159 | /* Private value of ecryptfs_dentry allocated in | 159 | /* Private value of ecryptfs_dentry allocated in |
160 | * ecryptfs_lookup() */ | 160 | * ecryptfs_lookup() */ |
161 | struct dentry *lower_dentry = ecryptfs_dentry_to_lower(ecryptfs_dentry); | 161 | struct dentry *lower_dentry; |
162 | struct ecryptfs_file_info *file_info; | 162 | struct ecryptfs_file_info *file_info; |
163 | 163 | ||
164 | mount_crypt_stat = &ecryptfs_superblock_to_private( | 164 | mount_crypt_stat = &ecryptfs_superblock_to_private( |
@@ -191,13 +191,6 @@ static int ecryptfs_open(struct inode *inode, struct file *file) | |||
191 | | ECRYPTFS_ENCRYPTED); | 191 | | ECRYPTFS_ENCRYPTED); |
192 | } | 192 | } |
193 | mutex_unlock(&crypt_stat->cs_mutex); | 193 | mutex_unlock(&crypt_stat->cs_mutex); |
194 | if ((ecryptfs_inode_to_private(inode)->lower_file->f_flags & O_RDONLY) | ||
195 | && !(file->f_flags & O_RDONLY)) { | ||
196 | rc = -EPERM; | ||
197 | printk(KERN_WARNING "%s: Lower persistent file is RO; eCryptfs " | ||
198 | "file must hence be opened RO\n", __func__); | ||
199 | goto out; | ||
200 | } | ||
201 | if (!ecryptfs_inode_to_private(inode)->lower_file) { | 194 | if (!ecryptfs_inode_to_private(inode)->lower_file) { |
202 | rc = ecryptfs_init_persistent_file(ecryptfs_dentry); | 195 | rc = ecryptfs_init_persistent_file(ecryptfs_dentry); |
203 | if (rc) { | 196 | if (rc) { |
@@ -208,6 +201,13 @@ static int ecryptfs_open(struct inode *inode, struct file *file) | |||
208 | goto out; | 201 | goto out; |
209 | } | 202 | } |
210 | } | 203 | } |
204 | if ((ecryptfs_inode_to_private(inode)->lower_file->f_flags & O_RDONLY) | ||
205 | && !(file->f_flags & O_RDONLY)) { | ||
206 | rc = -EPERM; | ||
207 | printk(KERN_WARNING "%s: Lower persistent file is RO; eCryptfs " | ||
208 | "file must hence be opened RO\n", __func__); | ||
209 | goto out; | ||
210 | } | ||
211 | ecryptfs_set_file_lower( | 211 | ecryptfs_set_file_lower( |
212 | file, ecryptfs_inode_to_private(inode)->lower_file); | 212 | file, ecryptfs_inode_to_private(inode)->lower_file); |
213 | if (S_ISDIR(ecryptfs_dentry->d_inode->i_mode)) { | 213 | if (S_ISDIR(ecryptfs_dentry->d_inode->i_mode)) { |
@@ -299,7 +299,6 @@ static int ecryptfs_ioctl(struct inode *inode, struct file *file, | |||
299 | const struct file_operations ecryptfs_dir_fops = { | 299 | const struct file_operations ecryptfs_dir_fops = { |
300 | .readdir = ecryptfs_readdir, | 300 | .readdir = ecryptfs_readdir, |
301 | .ioctl = ecryptfs_ioctl, | 301 | .ioctl = ecryptfs_ioctl, |
302 | .mmap = generic_file_mmap, | ||
303 | .open = ecryptfs_open, | 302 | .open = ecryptfs_open, |
304 | .flush = ecryptfs_flush, | 303 | .flush = ecryptfs_flush, |
305 | .release = ecryptfs_release, | 304 | .release = ecryptfs_release, |
diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c index 429ca0b3ba08..4a430ab4115c 100644 --- a/fs/ecryptfs/inode.c +++ b/fs/ecryptfs/inode.c | |||
@@ -282,7 +282,8 @@ int ecryptfs_lookup_and_interpose_lower(struct dentry *ecryptfs_dentry, | |||
282 | goto out; | 282 | goto out; |
283 | } | 283 | } |
284 | rc = ecryptfs_interpose(lower_dentry, ecryptfs_dentry, | 284 | rc = ecryptfs_interpose(lower_dentry, ecryptfs_dentry, |
285 | ecryptfs_dir_inode->i_sb, 1); | 285 | ecryptfs_dir_inode->i_sb, |
286 | ECRYPTFS_INTERPOSE_FLAG_D_ADD); | ||
286 | if (rc) { | 287 | if (rc) { |
287 | printk(KERN_ERR "%s: Error interposing; rc = [%d]\n", | 288 | printk(KERN_ERR "%s: Error interposing; rc = [%d]\n", |
288 | __func__, rc); | 289 | __func__, rc); |
@@ -463,9 +464,6 @@ out_lock: | |||
463 | unlock_dir(lower_dir_dentry); | 464 | unlock_dir(lower_dir_dentry); |
464 | dput(lower_new_dentry); | 465 | dput(lower_new_dentry); |
465 | dput(lower_old_dentry); | 466 | dput(lower_old_dentry); |
466 | d_drop(lower_old_dentry); | ||
467 | d_drop(new_dentry); | ||
468 | d_drop(old_dentry); | ||
469 | return rc; | 467 | return rc; |
470 | } | 468 | } |
471 | 469 | ||
@@ -614,6 +612,7 @@ ecryptfs_rename(struct inode *old_dir, struct dentry *old_dentry, | |||
614 | struct dentry *lower_new_dentry; | 612 | struct dentry *lower_new_dentry; |
615 | struct dentry *lower_old_dir_dentry; | 613 | struct dentry *lower_old_dir_dentry; |
616 | struct dentry *lower_new_dir_dentry; | 614 | struct dentry *lower_new_dir_dentry; |
615 | struct dentry *trap = NULL; | ||
617 | 616 | ||
618 | lower_old_dentry = ecryptfs_dentry_to_lower(old_dentry); | 617 | lower_old_dentry = ecryptfs_dentry_to_lower(old_dentry); |
619 | lower_new_dentry = ecryptfs_dentry_to_lower(new_dentry); | 618 | lower_new_dentry = ecryptfs_dentry_to_lower(new_dentry); |
@@ -621,7 +620,17 @@ ecryptfs_rename(struct inode *old_dir, struct dentry *old_dentry, | |||
621 | dget(lower_new_dentry); | 620 | dget(lower_new_dentry); |
622 | lower_old_dir_dentry = dget_parent(lower_old_dentry); | 621 | lower_old_dir_dentry = dget_parent(lower_old_dentry); |
623 | lower_new_dir_dentry = dget_parent(lower_new_dentry); | 622 | lower_new_dir_dentry = dget_parent(lower_new_dentry); |
624 | lock_rename(lower_old_dir_dentry, lower_new_dir_dentry); | 623 | trap = lock_rename(lower_old_dir_dentry, lower_new_dir_dentry); |
624 | /* source should not be ancestor of target */ | ||
625 | if (trap == lower_old_dentry) { | ||
626 | rc = -EINVAL; | ||
627 | goto out_lock; | ||
628 | } | ||
629 | /* target should not be ancestor of source */ | ||
630 | if (trap == lower_new_dentry) { | ||
631 | rc = -ENOTEMPTY; | ||
632 | goto out_lock; | ||
633 | } | ||
625 | rc = vfs_rename(lower_old_dir_dentry->d_inode, lower_old_dentry, | 634 | rc = vfs_rename(lower_old_dir_dentry->d_inode, lower_old_dentry, |
626 | lower_new_dir_dentry->d_inode, lower_new_dentry); | 635 | lower_new_dir_dentry->d_inode, lower_new_dentry); |
627 | if (rc) | 636 | if (rc) |
@@ -715,31 +724,31 @@ static void *ecryptfs_follow_link(struct dentry *dentry, struct nameidata *nd) | |||
715 | /* Released in ecryptfs_put_link(); only release here on error */ | 724 | /* Released in ecryptfs_put_link(); only release here on error */ |
716 | buf = kmalloc(len, GFP_KERNEL); | 725 | buf = kmalloc(len, GFP_KERNEL); |
717 | if (!buf) { | 726 | if (!buf) { |
718 | rc = -ENOMEM; | 727 | buf = ERR_PTR(-ENOMEM); |
719 | goto out; | 728 | goto out; |
720 | } | 729 | } |
721 | old_fs = get_fs(); | 730 | old_fs = get_fs(); |
722 | set_fs(get_ds()); | 731 | set_fs(get_ds()); |
723 | rc = dentry->d_inode->i_op->readlink(dentry, (char __user *)buf, len); | 732 | rc = dentry->d_inode->i_op->readlink(dentry, (char __user *)buf, len); |
724 | set_fs(old_fs); | 733 | set_fs(old_fs); |
725 | if (rc < 0) | 734 | if (rc < 0) { |
726 | goto out_free; | 735 | kfree(buf); |
727 | else | 736 | buf = ERR_PTR(rc); |
737 | } else | ||
728 | buf[rc] = '\0'; | 738 | buf[rc] = '\0'; |
729 | rc = 0; | ||
730 | nd_set_link(nd, buf); | ||
731 | goto out; | ||
732 | out_free: | ||
733 | kfree(buf); | ||
734 | out: | 739 | out: |
735 | return ERR_PTR(rc); | 740 | nd_set_link(nd, buf); |
741 | return NULL; | ||
736 | } | 742 | } |
737 | 743 | ||
738 | static void | 744 | static void |
739 | ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr) | 745 | ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr) |
740 | { | 746 | { |
741 | /* Free the char* */ | 747 | char *buf = nd_get_link(nd); |
742 | kfree(nd_get_link(nd)); | 748 | if (!IS_ERR(buf)) { |
749 | /* Free the char* */ | ||
750 | kfree(buf); | ||
751 | } | ||
743 | } | 752 | } |
744 | 753 | ||
745 | /** | 754 | /** |
@@ -772,18 +781,23 @@ upper_size_to_lower_size(struct ecryptfs_crypt_stat *crypt_stat, | |||
772 | } | 781 | } |
773 | 782 | ||
774 | /** | 783 | /** |
775 | * ecryptfs_truncate | 784 | * truncate_upper |
776 | * @dentry: The ecryptfs layer dentry | 785 | * @dentry: The ecryptfs layer dentry |
777 | * @new_length: The length to expand the file to | 786 | * @ia: Address of the ecryptfs inode's attributes |
787 | * @lower_ia: Address of the lower inode's attributes | ||
778 | * | 788 | * |
779 | * Function to handle truncations modifying the size of the file. Note | 789 | * Function to handle truncations modifying the size of the file. Note |
780 | * that the file sizes are interpolated. When expanding, we are simply | 790 | * that the file sizes are interpolated. When expanding, we are simply |
781 | * writing strings of 0's out. When truncating, we need to modify the | 791 | * writing strings of 0's out. When truncating, we truncate the upper |
782 | * underlying file size according to the page index interpolations. | 792 | * inode and update the lower_ia according to the page index |
793 | * interpolations. If ATTR_SIZE is set in lower_ia->ia_valid upon return, | ||
794 | * the caller must use lower_ia in a call to notify_change() to perform | ||
795 | * the truncation of the lower inode. | ||
783 | * | 796 | * |
784 | * Returns zero on success; non-zero otherwise | 797 | * Returns zero on success; non-zero otherwise |
785 | */ | 798 | */ |
786 | int ecryptfs_truncate(struct dentry *dentry, loff_t new_length) | 799 | static int truncate_upper(struct dentry *dentry, struct iattr *ia, |
800 | struct iattr *lower_ia) | ||
787 | { | 801 | { |
788 | int rc = 0; | 802 | int rc = 0; |
789 | struct inode *inode = dentry->d_inode; | 803 | struct inode *inode = dentry->d_inode; |
@@ -794,8 +808,10 @@ int ecryptfs_truncate(struct dentry *dentry, loff_t new_length) | |||
794 | loff_t lower_size_before_truncate; | 808 | loff_t lower_size_before_truncate; |
795 | loff_t lower_size_after_truncate; | 809 | loff_t lower_size_after_truncate; |
796 | 810 | ||
797 | if (unlikely((new_length == i_size))) | 811 | if (unlikely((ia->ia_size == i_size))) { |
812 | lower_ia->ia_valid &= ~ATTR_SIZE; | ||
798 | goto out; | 813 | goto out; |
814 | } | ||
799 | crypt_stat = &ecryptfs_inode_to_private(dentry->d_inode)->crypt_stat; | 815 | crypt_stat = &ecryptfs_inode_to_private(dentry->d_inode)->crypt_stat; |
800 | /* Set up a fake ecryptfs file, this is used to interface with | 816 | /* Set up a fake ecryptfs file, this is used to interface with |
801 | * the file in the underlying filesystem so that the | 817 | * the file in the underlying filesystem so that the |
@@ -815,28 +831,30 @@ int ecryptfs_truncate(struct dentry *dentry, loff_t new_length) | |||
815 | &fake_ecryptfs_file, | 831 | &fake_ecryptfs_file, |
816 | ecryptfs_inode_to_private(dentry->d_inode)->lower_file); | 832 | ecryptfs_inode_to_private(dentry->d_inode)->lower_file); |
817 | /* Switch on growing or shrinking file */ | 833 | /* Switch on growing or shrinking file */ |
818 | if (new_length > i_size) { | 834 | if (ia->ia_size > i_size) { |
819 | char zero[] = { 0x00 }; | 835 | char zero[] = { 0x00 }; |
820 | 836 | ||
837 | lower_ia->ia_valid &= ~ATTR_SIZE; | ||
821 | /* Write a single 0 at the last position of the file; | 838 | /* Write a single 0 at the last position of the file; |
822 | * this triggers code that will fill in 0's throughout | 839 | * this triggers code that will fill in 0's throughout |
823 | * the intermediate portion of the previous end of the | 840 | * the intermediate portion of the previous end of the |
824 | * file and the new and of the file */ | 841 | * file and the new and of the file */ |
825 | rc = ecryptfs_write(&fake_ecryptfs_file, zero, | 842 | rc = ecryptfs_write(&fake_ecryptfs_file, zero, |
826 | (new_length - 1), 1); | 843 | (ia->ia_size - 1), 1); |
827 | } else { /* new_length < i_size_read(inode) */ | 844 | } else { /* ia->ia_size < i_size_read(inode) */ |
828 | /* We're chopping off all the pages down do the page | 845 | /* We're chopping off all the pages down to the page |
829 | * in which new_length is located. Fill in the end of | 846 | * in which ia->ia_size is located. Fill in the end of |
830 | * that page from (new_length & ~PAGE_CACHE_MASK) to | 847 | * that page from (ia->ia_size & ~PAGE_CACHE_MASK) to |
831 | * PAGE_CACHE_SIZE with zeros. */ | 848 | * PAGE_CACHE_SIZE with zeros. */ |
832 | size_t num_zeros = (PAGE_CACHE_SIZE | 849 | size_t num_zeros = (PAGE_CACHE_SIZE |
833 | - (new_length & ~PAGE_CACHE_MASK)); | 850 | - (ia->ia_size & ~PAGE_CACHE_MASK)); |
834 | 851 | ||
835 | if (!(crypt_stat->flags & ECRYPTFS_ENCRYPTED)) { | 852 | if (!(crypt_stat->flags & ECRYPTFS_ENCRYPTED)) { |
836 | rc = vmtruncate(inode, new_length); | 853 | rc = vmtruncate(inode, ia->ia_size); |
837 | if (rc) | 854 | if (rc) |
838 | goto out_free; | 855 | goto out_free; |
839 | rc = vmtruncate(lower_dentry->d_inode, new_length); | 856 | lower_ia->ia_size = ia->ia_size; |
857 | lower_ia->ia_valid |= ATTR_SIZE; | ||
840 | goto out_free; | 858 | goto out_free; |
841 | } | 859 | } |
842 | if (num_zeros) { | 860 | if (num_zeros) { |
@@ -848,7 +866,7 @@ int ecryptfs_truncate(struct dentry *dentry, loff_t new_length) | |||
848 | goto out_free; | 866 | goto out_free; |
849 | } | 867 | } |
850 | rc = ecryptfs_write(&fake_ecryptfs_file, zeros_virt, | 868 | rc = ecryptfs_write(&fake_ecryptfs_file, zeros_virt, |
851 | new_length, num_zeros); | 869 | ia->ia_size, num_zeros); |
852 | kfree(zeros_virt); | 870 | kfree(zeros_virt); |
853 | if (rc) { | 871 | if (rc) { |
854 | printk(KERN_ERR "Error attempting to zero out " | 872 | printk(KERN_ERR "Error attempting to zero out " |
@@ -857,7 +875,7 @@ int ecryptfs_truncate(struct dentry *dentry, loff_t new_length) | |||
857 | goto out_free; | 875 | goto out_free; |
858 | } | 876 | } |
859 | } | 877 | } |
860 | vmtruncate(inode, new_length); | 878 | vmtruncate(inode, ia->ia_size); |
861 | rc = ecryptfs_write_inode_size_to_metadata(inode); | 879 | rc = ecryptfs_write_inode_size_to_metadata(inode); |
862 | if (rc) { | 880 | if (rc) { |
863 | printk(KERN_ERR "Problem with " | 881 | printk(KERN_ERR "Problem with " |
@@ -870,10 +888,12 @@ int ecryptfs_truncate(struct dentry *dentry, loff_t new_length) | |||
870 | lower_size_before_truncate = | 888 | lower_size_before_truncate = |
871 | upper_size_to_lower_size(crypt_stat, i_size); | 889 | upper_size_to_lower_size(crypt_stat, i_size); |
872 | lower_size_after_truncate = | 890 | lower_size_after_truncate = |
873 | upper_size_to_lower_size(crypt_stat, new_length); | 891 | upper_size_to_lower_size(crypt_stat, ia->ia_size); |
874 | if (lower_size_after_truncate < lower_size_before_truncate) | 892 | if (lower_size_after_truncate < lower_size_before_truncate) { |
875 | vmtruncate(lower_dentry->d_inode, | 893 | lower_ia->ia_size = lower_size_after_truncate; |
876 | lower_size_after_truncate); | 894 | lower_ia->ia_valid |= ATTR_SIZE; |
895 | } else | ||
896 | lower_ia->ia_valid &= ~ATTR_SIZE; | ||
877 | } | 897 | } |
878 | out_free: | 898 | out_free: |
879 | if (ecryptfs_file_to_private(&fake_ecryptfs_file)) | 899 | if (ecryptfs_file_to_private(&fake_ecryptfs_file)) |
@@ -883,6 +903,33 @@ out: | |||
883 | return rc; | 903 | return rc; |
884 | } | 904 | } |
885 | 905 | ||
906 | /** | ||
907 | * ecryptfs_truncate | ||
908 | * @dentry: The ecryptfs layer dentry | ||
909 | * @new_length: The length to expand the file to | ||
910 | * | ||
911 | * Simple function that handles the truncation of an eCryptfs inode and | ||
912 | * its corresponding lower inode. | ||
913 | * | ||
914 | * Returns zero on success; non-zero otherwise | ||
915 | */ | ||
916 | int ecryptfs_truncate(struct dentry *dentry, loff_t new_length) | ||
917 | { | ||
918 | struct iattr ia = { .ia_valid = ATTR_SIZE, .ia_size = new_length }; | ||
919 | struct iattr lower_ia = { .ia_valid = 0 }; | ||
920 | int rc; | ||
921 | |||
922 | rc = truncate_upper(dentry, &ia, &lower_ia); | ||
923 | if (!rc && lower_ia.ia_valid & ATTR_SIZE) { | ||
924 | struct dentry *lower_dentry = ecryptfs_dentry_to_lower(dentry); | ||
925 | |||
926 | mutex_lock(&lower_dentry->d_inode->i_mutex); | ||
927 | rc = notify_change(lower_dentry, &lower_ia); | ||
928 | mutex_unlock(&lower_dentry->d_inode->i_mutex); | ||
929 | } | ||
930 | return rc; | ||
931 | } | ||
932 | |||
886 | static int | 933 | static int |
887 | ecryptfs_permission(struct inode *inode, int mask) | 934 | ecryptfs_permission(struct inode *inode, int mask) |
888 | { | 935 | { |
@@ -905,6 +952,7 @@ static int ecryptfs_setattr(struct dentry *dentry, struct iattr *ia) | |||
905 | { | 952 | { |
906 | int rc = 0; | 953 | int rc = 0; |
907 | struct dentry *lower_dentry; | 954 | struct dentry *lower_dentry; |
955 | struct iattr lower_ia; | ||
908 | struct inode *inode; | 956 | struct inode *inode; |
909 | struct inode *lower_inode; | 957 | struct inode *lower_inode; |
910 | struct ecryptfs_crypt_stat *crypt_stat; | 958 | struct ecryptfs_crypt_stat *crypt_stat; |
@@ -943,15 +991,11 @@ static int ecryptfs_setattr(struct dentry *dentry, struct iattr *ia) | |||
943 | } | 991 | } |
944 | } | 992 | } |
945 | mutex_unlock(&crypt_stat->cs_mutex); | 993 | mutex_unlock(&crypt_stat->cs_mutex); |
994 | memcpy(&lower_ia, ia, sizeof(lower_ia)); | ||
995 | if (ia->ia_valid & ATTR_FILE) | ||
996 | lower_ia.ia_file = ecryptfs_file_to_lower(ia->ia_file); | ||
946 | if (ia->ia_valid & ATTR_SIZE) { | 997 | if (ia->ia_valid & ATTR_SIZE) { |
947 | ecryptfs_printk(KERN_DEBUG, | 998 | rc = truncate_upper(dentry, ia, &lower_ia); |
948 | "ia->ia_valid = [0x%x] ATTR_SIZE" " = [0x%x]\n", | ||
949 | ia->ia_valid, ATTR_SIZE); | ||
950 | rc = ecryptfs_truncate(dentry, ia->ia_size); | ||
951 | /* ecryptfs_truncate handles resizing of the lower file */ | ||
952 | ia->ia_valid &= ~ATTR_SIZE; | ||
953 | ecryptfs_printk(KERN_DEBUG, "ia->ia_valid = [%x]\n", | ||
954 | ia->ia_valid); | ||
955 | if (rc < 0) | 999 | if (rc < 0) |
956 | goto out; | 1000 | goto out; |
957 | } | 1001 | } |
@@ -960,17 +1004,32 @@ static int ecryptfs_setattr(struct dentry *dentry, struct iattr *ia) | |||
960 | * mode change is for clearing setuid/setgid bits. Allow lower fs | 1004 | * mode change is for clearing setuid/setgid bits. Allow lower fs |
961 | * to interpret this in its own way. | 1005 | * to interpret this in its own way. |
962 | */ | 1006 | */ |
963 | if (ia->ia_valid & (ATTR_KILL_SUID | ATTR_KILL_SGID)) | 1007 | if (lower_ia.ia_valid & (ATTR_KILL_SUID | ATTR_KILL_SGID)) |
964 | ia->ia_valid &= ~ATTR_MODE; | 1008 | lower_ia.ia_valid &= ~ATTR_MODE; |
965 | 1009 | ||
966 | mutex_lock(&lower_dentry->d_inode->i_mutex); | 1010 | mutex_lock(&lower_dentry->d_inode->i_mutex); |
967 | rc = notify_change(lower_dentry, ia); | 1011 | rc = notify_change(lower_dentry, &lower_ia); |
968 | mutex_unlock(&lower_dentry->d_inode->i_mutex); | 1012 | mutex_unlock(&lower_dentry->d_inode->i_mutex); |
969 | out: | 1013 | out: |
970 | fsstack_copy_attr_all(inode, lower_inode); | 1014 | fsstack_copy_attr_all(inode, lower_inode); |
971 | return rc; | 1015 | return rc; |
972 | } | 1016 | } |
973 | 1017 | ||
1018 | int ecryptfs_getattr(struct vfsmount *mnt, struct dentry *dentry, | ||
1019 | struct kstat *stat) | ||
1020 | { | ||
1021 | struct kstat lower_stat; | ||
1022 | int rc; | ||
1023 | |||
1024 | rc = vfs_getattr(ecryptfs_dentry_to_lower_mnt(dentry), | ||
1025 | ecryptfs_dentry_to_lower(dentry), &lower_stat); | ||
1026 | if (!rc) { | ||
1027 | generic_fillattr(dentry->d_inode, stat); | ||
1028 | stat->blocks = lower_stat.blocks; | ||
1029 | } | ||
1030 | return rc; | ||
1031 | } | ||
1032 | |||
974 | int | 1033 | int |
975 | ecryptfs_setxattr(struct dentry *dentry, const char *name, const void *value, | 1034 | ecryptfs_setxattr(struct dentry *dentry, const char *name, const void *value, |
976 | size_t size, int flags) | 1035 | size_t size, int flags) |
@@ -1100,6 +1159,7 @@ const struct inode_operations ecryptfs_dir_iops = { | |||
1100 | const struct inode_operations ecryptfs_main_iops = { | 1159 | const struct inode_operations ecryptfs_main_iops = { |
1101 | .permission = ecryptfs_permission, | 1160 | .permission = ecryptfs_permission, |
1102 | .setattr = ecryptfs_setattr, | 1161 | .setattr = ecryptfs_setattr, |
1162 | .getattr = ecryptfs_getattr, | ||
1103 | .setxattr = ecryptfs_setxattr, | 1163 | .setxattr = ecryptfs_setxattr, |
1104 | .getxattr = ecryptfs_getxattr, | 1164 | .getxattr = ecryptfs_getxattr, |
1105 | .listxattr = ecryptfs_listxattr, | 1165 | .listxattr = ecryptfs_listxattr, |
diff --git a/fs/ecryptfs/main.c b/fs/ecryptfs/main.c index 567bc4b9f70a..ea2f92101dfe 100644 --- a/fs/ecryptfs/main.c +++ b/fs/ecryptfs/main.c | |||
@@ -585,8 +585,8 @@ out: | |||
585 | * with as much information as it can before needing | 585 | * with as much information as it can before needing |
586 | * the lower filesystem. | 586 | * the lower filesystem. |
587 | * ecryptfs_read_super(): this accesses the lower filesystem and uses | 587 | * ecryptfs_read_super(): this accesses the lower filesystem and uses |
588 | * ecryptfs_interpolate to perform most of the linking | 588 | * ecryptfs_interpose to perform most of the linking |
589 | * ecryptfs_interpolate(): links the lower filesystem into ecryptfs | 589 | * ecryptfs_interpose(): links the lower filesystem into ecryptfs (inode.c) |
590 | */ | 590 | */ |
591 | static int ecryptfs_get_sb(struct file_system_type *fs_type, int flags, | 591 | static int ecryptfs_get_sb(struct file_system_type *fs_type, int flags, |
592 | const char *dev_name, void *raw_data, | 592 | const char *dev_name, void *raw_data, |