@@ -324,6 +324,7 @@ int ecryptfs_lookup_and_interpose_lower(struct dentry *ecryptfs_dentry,
324324 rc = ecryptfs_read_and_validate_header_region (page_virt ,
325325 ecryptfs_dentry -> d_inode );
326326 if (rc ) {
327+ memset (page_virt , 0 , PAGE_CACHE_SIZE );
327328 rc = ecryptfs_read_and_validate_xattr_region (page_virt ,
328329 ecryptfs_dentry );
329330 if (rc ) {
@@ -336,7 +337,7 @@ int ecryptfs_lookup_and_interpose_lower(struct dentry *ecryptfs_dentry,
336337 ecryptfs_dentry -> d_sb )-> mount_crypt_stat ;
337338 if (mount_crypt_stat -> flags & ECRYPTFS_ENCRYPTED_VIEW_ENABLED ) {
338339 if (crypt_stat -> flags & ECRYPTFS_METADATA_IN_XATTR )
339- file_size = (crypt_stat -> num_header_bytes_at_front
340+ file_size = (crypt_stat -> metadata_size
340341 + i_size_read (lower_dentry -> d_inode ));
341342 else
342343 file_size = i_size_read (lower_dentry -> d_inode );
@@ -388,9 +389,9 @@ static struct dentry *ecryptfs_lookup(struct inode *ecryptfs_dir_inode,
388389 mutex_unlock (& lower_dir_dentry -> d_inode -> i_mutex );
389390 if (IS_ERR (lower_dentry )) {
390391 rc = PTR_ERR (lower_dentry );
391- printk ( KERN_ERR "%s: lookup_one_len() returned [%d] on "
392- " lower_dentry = [%s]\n" , __func__ , rc ,
393- ecryptfs_dentry -> d_name . name );
392+ ecryptfs_printk ( KERN_DEBUG , "%s: lookup_one_len() returned "
393+ "[%d] on lower_dentry = [%s]\n" , __func__ , rc ,
394+ encrypted_and_encoded_name );
394395 goto out_d_drop ;
395396 }
396397 if (lower_dentry -> d_inode )
@@ -417,9 +418,9 @@ static struct dentry *ecryptfs_lookup(struct inode *ecryptfs_dir_inode,
417418 mutex_unlock (& lower_dir_dentry -> d_inode -> i_mutex );
418419 if (IS_ERR (lower_dentry )) {
419420 rc = PTR_ERR (lower_dentry );
420- printk ( KERN_ERR "%s: lookup_one_len() returned [%d] on "
421- " lower_dentry = [%s]\n" , __func__ , rc ,
422- encrypted_and_encoded_name );
421+ ecryptfs_printk ( KERN_DEBUG , "%s: lookup_one_len() returned "
422+ "[%d] on lower_dentry = [%s]\n" , __func__ , rc ,
423+ encrypted_and_encoded_name );
423424 goto out_d_drop ;
424425 }
425426lookup_and_interpose :
@@ -456,8 +457,8 @@ static int ecryptfs_link(struct dentry *old_dentry, struct inode *dir,
456457 rc = ecryptfs_interpose (lower_new_dentry , new_dentry , dir -> i_sb , 0 );
457458 if (rc )
458459 goto out_lock ;
459- fsstack_copy_attr_times (dir , lower_new_dentry -> d_inode );
460- fsstack_copy_inode_size (dir , lower_new_dentry -> d_inode );
460+ fsstack_copy_attr_times (dir , lower_dir_dentry -> d_inode );
461+ fsstack_copy_inode_size (dir , lower_dir_dentry -> d_inode );
461462 old_dentry -> d_inode -> i_nlink =
462463 ecryptfs_inode_to_lower (old_dentry -> d_inode )-> i_nlink ;
463464 i_size_write (new_dentry -> d_inode , file_size_save );
@@ -648,38 +649,17 @@ ecryptfs_rename(struct inode *old_dir, struct dentry *old_dentry,
648649 return rc ;
649650}
650651
651- static int
652- ecryptfs_readlink ( struct dentry * dentry , char __user * buf , int bufsiz )
652+ static int ecryptfs_readlink_lower ( struct dentry * dentry , char * * buf ,
653+ size_t * bufsiz )
653654{
655+ struct dentry * lower_dentry = ecryptfs_dentry_to_lower (dentry );
654656 char * lower_buf ;
655- size_t lower_bufsiz ;
656- struct dentry * lower_dentry ;
657- struct ecryptfs_mount_crypt_stat * mount_crypt_stat ;
658- char * plaintext_name ;
659- size_t plaintext_name_size ;
657+ size_t lower_bufsiz = PATH_MAX ;
660658 mm_segment_t old_fs ;
661659 int rc ;
662660
663- lower_dentry = ecryptfs_dentry_to_lower (dentry );
664- if (!lower_dentry -> d_inode -> i_op -> readlink ) {
665- rc = - EINVAL ;
666- goto out ;
667- }
668- mount_crypt_stat = & ecryptfs_superblock_to_private (
669- dentry -> d_sb )-> mount_crypt_stat ;
670- /*
671- * If the lower filename is encrypted, it will result in a significantly
672- * longer name. If needed, truncate the name after decode and decrypt.
673- */
674- if (mount_crypt_stat -> flags & ECRYPTFS_GLOBAL_ENCRYPT_FILENAMES )
675- lower_bufsiz = PATH_MAX ;
676- else
677- lower_bufsiz = bufsiz ;
678- /* Released in this function */
679661 lower_buf = kmalloc (lower_bufsiz , GFP_KERNEL );
680- if (lower_buf == NULL ) {
681- printk (KERN_ERR "%s: Out of memory whilst attempting to "
682- "kmalloc [%zd] bytes\n" , __func__ , lower_bufsiz );
662+ if (!lower_buf ) {
683663 rc = - ENOMEM ;
684664 goto out ;
685665 }
@@ -689,29 +669,31 @@ ecryptfs_readlink(struct dentry *dentry, char __user *buf, int bufsiz)
689669 (char __user * )lower_buf ,
690670 lower_bufsiz );
691671 set_fs (old_fs );
692- if (rc >= 0 ) {
693- rc = ecryptfs_decode_and_decrypt_filename (& plaintext_name ,
694- & plaintext_name_size ,
695- dentry , lower_buf ,
696- rc );
697- if (rc ) {
698- printk (KERN_ERR "%s: Error attempting to decode and "
699- "decrypt filename; rc = [%d]\n" , __func__ ,
700- rc );
701- goto out_free_lower_buf ;
702- }
703- /* Check for bufsiz <= 0 done in sys_readlinkat() */
704- rc = copy_to_user (buf , plaintext_name ,
705- min ((size_t ) bufsiz , plaintext_name_size ));
706- if (rc )
707- rc = - EFAULT ;
708- else
709- rc = plaintext_name_size ;
710- kfree (plaintext_name );
711- fsstack_copy_attr_atime (dentry -> d_inode , lower_dentry -> d_inode );
712- }
713- out_free_lower_buf :
672+ if (rc < 0 )
673+ goto out ;
674+ lower_bufsiz = rc ;
675+ rc = ecryptfs_decode_and_decrypt_filename (buf , bufsiz , dentry ,
676+ lower_buf , lower_bufsiz );
677+ out :
714678 kfree (lower_buf );
679+ return rc ;
680+ }
681+
682+ static int
683+ ecryptfs_readlink (struct dentry * dentry , char __user * buf , int bufsiz )
684+ {
685+ char * kbuf ;
686+ size_t kbufsiz , copied ;
687+ int rc ;
688+
689+ rc = ecryptfs_readlink_lower (dentry , & kbuf , & kbufsiz );
690+ if (rc )
691+ goto out ;
692+ copied = min_t (size_t , bufsiz , kbufsiz );
693+ rc = copy_to_user (buf , kbuf , copied ) ? - EFAULT : copied ;
694+ kfree (kbuf );
695+ fsstack_copy_attr_atime (dentry -> d_inode ,
696+ ecryptfs_dentry_to_lower (dentry )-> d_inode );
715697out :
716698 return rc ;
717699}
@@ -769,7 +751,7 @@ upper_size_to_lower_size(struct ecryptfs_crypt_stat *crypt_stat,
769751{
770752 loff_t lower_size ;
771753
772- lower_size = crypt_stat -> num_header_bytes_at_front ;
754+ lower_size = ecryptfs_lower_header_size ( crypt_stat ) ;
773755 if (upper_size != 0 ) {
774756 loff_t num_extents ;
775757
@@ -1016,6 +998,28 @@ static int ecryptfs_setattr(struct dentry *dentry, struct iattr *ia)
1016998 return rc ;
1017999}
10181000
1001+ int ecryptfs_getattr_link (struct vfsmount * mnt , struct dentry * dentry ,
1002+ struct kstat * stat )
1003+ {
1004+ struct ecryptfs_mount_crypt_stat * mount_crypt_stat ;
1005+ int rc = 0 ;
1006+
1007+ mount_crypt_stat = & ecryptfs_superblock_to_private (
1008+ dentry -> d_sb )-> mount_crypt_stat ;
1009+ generic_fillattr (dentry -> d_inode , stat );
1010+ if (mount_crypt_stat -> flags & ECRYPTFS_GLOBAL_ENCRYPT_FILENAMES ) {
1011+ char * target ;
1012+ size_t targetsiz ;
1013+
1014+ rc = ecryptfs_readlink_lower (dentry , & target , & targetsiz );
1015+ if (!rc ) {
1016+ kfree (target );
1017+ stat -> size = targetsiz ;
1018+ }
1019+ }
1020+ return rc ;
1021+ }
1022+
10191023int ecryptfs_getattr (struct vfsmount * mnt , struct dentry * dentry ,
10201024 struct kstat * stat )
10211025{
@@ -1040,7 +1044,7 @@ ecryptfs_setxattr(struct dentry *dentry, const char *name, const void *value,
10401044
10411045 lower_dentry = ecryptfs_dentry_to_lower (dentry );
10421046 if (!lower_dentry -> d_inode -> i_op -> setxattr ) {
1043- rc = - ENOSYS ;
1047+ rc = - EOPNOTSUPP ;
10441048 goto out ;
10451049 }
10461050 mutex_lock (& lower_dentry -> d_inode -> i_mutex );
@@ -1058,7 +1062,7 @@ ecryptfs_getxattr_lower(struct dentry *lower_dentry, const char *name,
10581062 int rc = 0 ;
10591063
10601064 if (!lower_dentry -> d_inode -> i_op -> getxattr ) {
1061- rc = - ENOSYS ;
1065+ rc = - EOPNOTSUPP ;
10621066 goto out ;
10631067 }
10641068 mutex_lock (& lower_dentry -> d_inode -> i_mutex );
@@ -1085,7 +1089,7 @@ ecryptfs_listxattr(struct dentry *dentry, char *list, size_t size)
10851089
10861090 lower_dentry = ecryptfs_dentry_to_lower (dentry );
10871091 if (!lower_dentry -> d_inode -> i_op -> listxattr ) {
1088- rc = - ENOSYS ;
1092+ rc = - EOPNOTSUPP ;
10891093 goto out ;
10901094 }
10911095 mutex_lock (& lower_dentry -> d_inode -> i_mutex );
@@ -1102,7 +1106,7 @@ static int ecryptfs_removexattr(struct dentry *dentry, const char *name)
11021106
11031107 lower_dentry = ecryptfs_dentry_to_lower (dentry );
11041108 if (!lower_dentry -> d_inode -> i_op -> removexattr ) {
1105- rc = - ENOSYS ;
1109+ rc = - EOPNOTSUPP ;
11061110 goto out ;
11071111 }
11081112 mutex_lock (& lower_dentry -> d_inode -> i_mutex );
@@ -1133,6 +1137,7 @@ const struct inode_operations ecryptfs_symlink_iops = {
11331137 .put_link = ecryptfs_put_link ,
11341138 .permission = ecryptfs_permission ,
11351139 .setattr = ecryptfs_setattr ,
1140+ .getattr = ecryptfs_getattr_link ,
11361141 .setxattr = ecryptfs_setxattr ,
11371142 .getxattr = ecryptfs_getxattr ,
11381143 .listxattr = ecryptfs_listxattr ,
0 commit comments