Merge tag 'ecryptfs-3.18-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git...
authorLinus Torvalds <torvalds@linux-foundation.org>
Sat, 11 Oct 2014 12:01:27 +0000 (08:01 -0400)
committerLinus Torvalds <torvalds@linux-foundation.org>
Sat, 11 Oct 2014 12:01:27 +0000 (08:01 -0400)
Pull eCryptfs updates from Tyler Hicks:
 "Minor code cleanups and a fix for when eCryptfs metadata is stored in
  xattrs"

* tag 'ecryptfs-3.18-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/tyhicks/ecryptfs:
  ecryptfs: remove unneeded buggy code in ecryptfs_do_create()
  ecryptfs: avoid to access NULL pointer when write metadata in xattr
  ecryptfs: remove unnecessary break after goto
  ecryptfs: Remove unnecessary include of syscall.h in keystore.c
  fs/ecryptfs/messaging.c: remove null test before kfree
  ecryptfs: Drop cast
  Use %pd in eCryptFS

1  2 
fs/ecryptfs/file.c
fs/ecryptfs/inode.c

diff --combined fs/ecryptfs/file.c
   * The function to be used for directory reads is ecryptfs_read.
   */
  static ssize_t ecryptfs_read_update_atime(struct kiocb *iocb,
 -                              const struct iovec *iov,
 -                              unsigned long nr_segs, loff_t pos)
 +                              struct iov_iter *to)
  {
        ssize_t rc;
        struct path *path;
        struct file *file = iocb->ki_filp;
  
 -      rc = generic_file_aio_read(iocb, iov, nr_segs, pos);
 +      rc = generic_file_read_iter(iocb, to);
        /*
         * Even though this is a async interface, we need to wait
         * for IO to finish to update atime
@@@ -229,8 -230,8 +229,8 @@@ static int ecryptfs_open(struct inode *
        if (rc) {
                printk(KERN_ERR "%s: Error attempting to initialize "
                        "the lower file for the dentry with name "
-                       "[%s]; rc = [%d]\n", __func__,
-                       ecryptfs_dentry->d_name.name, rc);
+                       "[%pd]; rc = [%d]\n", __func__,
+                       ecryptfs_dentry, rc);
                goto out_free;
        }
        if ((ecryptfs_inode_to_private(inode)->lower_file->f_flags & O_ACCMODE)
@@@ -351,10 -352,10 +351,10 @@@ const struct file_operations ecryptfs_d
  
  const struct file_operations ecryptfs_main_fops = {
        .llseek = generic_file_llseek,
 -      .read = do_sync_read,
 -      .aio_read = ecryptfs_read_update_atime,
 -      .write = do_sync_write,
 -      .aio_write = generic_file_aio_write,
 +      .read = new_sync_read,
 +      .read_iter = ecryptfs_read_update_atime,
 +      .write = new_sync_write,
 +      .write_iter = generic_file_write_iter,
        .iterate = ecryptfs_readdir,
        .unlocked_ioctl = ecryptfs_unlocked_ioctl,
  #ifdef CONFIG_COMPAT
diff --combined fs/ecryptfs/inode.c
@@@ -53,9 -53,7 +53,7 @@@ static void unlock_dir(struct dentry *d
  
  static int ecryptfs_inode_test(struct inode *inode, void *lower_inode)
  {
-       if (ecryptfs_inode_to_lower(inode) == (struct inode *)lower_inode)
-               return 1;
-       return 0;
+       return ecryptfs_inode_to_lower(inode) == lower_inode;
  }
  
  static int ecryptfs_inode_set(struct inode *inode, void *opaque)
@@@ -192,12 -190,6 +190,6 @@@ ecryptfs_do_create(struct inode *direct
  
        lower_dentry = ecryptfs_dentry_to_lower(ecryptfs_dentry);
        lower_dir_dentry = lock_parent(lower_dentry);
-       if (IS_ERR(lower_dir_dentry)) {
-               ecryptfs_printk(KERN_ERR, "Error locking directory of "
-                               "dentry\n");
-               inode = ERR_CAST(lower_dir_dentry);
-               goto out;
-       }
        rc = vfs_create(lower_dir_dentry->d_inode, lower_dentry, mode, true);
        if (rc) {
                printk(KERN_ERR "%s: Failure to create dentry in lower fs; "
        fsstack_copy_inode_size(directory_inode, lower_dir_dentry->d_inode);
  out_lock:
        unlock_dir(lower_dir_dentry);
- out:
        return inode;
  }
  
@@@ -250,8 -241,8 +241,8 @@@ int ecryptfs_initialize_file(struct den
        if (rc) {
                printk(KERN_ERR "%s: Error attempting to initialize "
                        "the lower file for the dentry with name "
-                       "[%s]; rc = [%d]\n", __func__,
-                       ecryptfs_dentry->d_name.name, rc);
+                       "[%pd]; rc = [%d]\n", __func__,
+                       ecryptfs_dentry, rc);
                goto out;
        }
        rc = ecryptfs_write_metadata(ecryptfs_dentry, ecryptfs_inode);
@@@ -313,8 -304,8 +304,8 @@@ static int ecryptfs_i_size_read(struct 
        if (rc) {
                printk(KERN_ERR "%s: Error attempting to initialize "
                        "the lower file for the dentry with name "
-                       "[%s]; rc = [%d]\n", __func__,
-                       dentry->d_name.name, rc);
+                       "[%pd]; rc = [%d]\n", __func__,
+                       dentry, rc);
                return rc;
        }
  
@@@ -418,8 -409,8 +409,8 @@@ static struct dentry *ecryptfs_lookup(s
        if (IS_ERR(lower_dentry)) {
                rc = PTR_ERR(lower_dentry);
                ecryptfs_printk(KERN_DEBUG, "%s: lookup_one_len() returned "
-                               "[%d] on lower_dentry = [%s]\n", __func__, rc,
-                               ecryptfs_dentry->d_name.name);
+                               "[%d] on lower_dentry = [%pd]\n", __func__, rc,
+                               ecryptfs_dentry);
                goto out;
        }
        if (lower_dentry->d_inode)
@@@ -641,7 -632,7 +632,7 @@@ ecryptfs_rename(struct inode *old_dir, 
        }
        rc = vfs_rename(lower_old_dir_dentry->d_inode, lower_old_dentry,
                        lower_new_dir_dentry->d_inode, lower_new_dentry,
 -                      NULL);
 +                      NULL, 0);
        if (rc)
                goto out_lock;
        if (target_inode)
@@@ -659,17 -650,19 +650,17 @@@ out_lock
        return rc;
  }
  
 -static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
 -                                 size_t *bufsiz)
 +static char *ecryptfs_readlink_lower(struct dentry *dentry, size_t *bufsiz)
  {
        struct dentry *lower_dentry = ecryptfs_dentry_to_lower(dentry);
        char *lower_buf;
 +      char *buf;
        mm_segment_t old_fs;
        int rc;
  
        lower_buf = kmalloc(PATH_MAX, GFP_KERNEL);
 -      if (!lower_buf) {
 -              rc = -ENOMEM;
 -              goto out;
 -      }
 +      if (!lower_buf)
 +              return ERR_PTR(-ENOMEM);
        old_fs = get_fs();
        set_fs(get_ds());
        rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
        set_fs(old_fs);
        if (rc < 0)
                goto out;
 -      rc = ecryptfs_decode_and_decrypt_filename(buf, bufsiz, dentry->d_sb,
 +      rc = ecryptfs_decode_and_decrypt_filename(&buf, bufsiz, dentry->d_sb,
                                                  lower_buf, rc);
  out:
        kfree(lower_buf);
 -      return rc;
 +      return rc ? ERR_PTR(rc) : buf;
  }
  
  static void *ecryptfs_follow_link(struct dentry *dentry, struct nameidata *nd)
  {
 -      char *buf;
 -      size_t len = PATH_MAX;
 -      int rc;
 -
 -      rc = ecryptfs_readlink_lower(dentry, &buf, &len);
 -      if (rc)
 +      size_t len;
 +      char *buf = ecryptfs_readlink_lower(dentry, &len);
 +      if (IS_ERR(buf))
                goto out;
        fsstack_copy_attr_atime(dentry->d_inode,
                                ecryptfs_dentry_to_lower(dentry)->d_inode);
@@@ -998,12 -994,10 +989,12 @@@ static int ecryptfs_getattr_link(struc
                char *target;
                size_t targetsiz;
  
 -              rc = ecryptfs_readlink_lower(dentry, &target, &targetsiz);
 -              if (!rc) {
 +              target = ecryptfs_readlink_lower(dentry, &targetsiz);
 +              if (!IS_ERR(target)) {
                        kfree(target);
                        stat->size = targetsiz;
 +              } else {
 +                      rc = PTR_ERR(target);
                }
        }
        return rc;
@@@ -1039,7 -1033,7 +1030,7 @@@ ecryptfs_setxattr(struct dentry *dentry
        }
  
        rc = vfs_setxattr(lower_dentry, name, value, size, flags);
-       if (!rc)
+       if (!rc && dentry->d_inode)
                fsstack_copy_attr_all(dentry->d_inode, lower_dentry->d_inode);
  out:
        return rc;