Merge tag 'ecryptfs-5.13-rc1-updates' of git://git.kernel.org/pub/scm/linux/kernel...
authorLinus Torvalds <torvalds@linux-foundation.org>
Thu, 6 May 2021 17:06:39 +0000 (10:06 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Thu, 6 May 2021 17:06:39 +0000 (10:06 -0700)
Pull ecryptfs updates from Tyler Hicks:
 "Code cleanups and a bug fix

   - W=1 compiler warning cleanups

   - Mutex initialization simplification

   - Protect against NULL pointer exception during mount"

* tag 'ecryptfs-5.13-rc1-updates' of git://git.kernel.org/pub/scm/linux/kernel/git/tyhicks/ecryptfs:
  ecryptfs: fix kernel panic with null dev_name
  ecryptfs: remove unused helpers
  ecryptfs: Fix typo in message
  eCryptfs: Use DEFINE_MUTEX() for mutex lock
  ecryptfs: keystore: Fix some kernel-doc issues and demote non-conformant headers
  ecryptfs: inode: Help out nearly-there header and demote non-conformant ones
  ecryptfs: mmap: Help out one function header and demote other abuses
  ecryptfs: crypto: Supply some missing param descriptions and demote abuses
  ecryptfs: miscdev: File headers are not good kernel-doc candidates
  ecryptfs: main: Demote a bunch of non-conformant kernel-doc headers
  ecryptfs: messaging: Add missing param descriptions and demote abuses
  ecryptfs: super: Fix formatting, naming and kernel-doc abuses
  ecryptfs: file: Demote kernel-doc abuses
  ecryptfs: kthread: Demote file header and provide description for 'cred'
  ecryptfs: dentry: File headers are not good candidates for kernel-doc
  ecryptfs: debug: Demote a couple of kernel-doc abuses
  ecryptfs: read_write: File headers do not make good candidates for kernel-doc
  ecryptfs: use DEFINE_MUTEX() for mutex lock
  eCryptfs: add a semicolon

1  2 
fs/ecryptfs/ecryptfs_kernel.h
fs/ecryptfs/inode.c

index 495fb4514d0907ade552ca8b80b5512d367f1b61,c8687c6384f52e33b4e52c125c8836edad45ff67..5f2b49e13731a2919ca0a168790e235b16c48935
@@@ -262,7 -262,10 +262,7 @@@ struct ecryptfs_inode_info 
   * vfsmount too. */
  struct ecryptfs_dentry_info {
        struct path lower_path;
 -      union {
 -              struct ecryptfs_crypt_stat *crypt_stat;
 -              struct rcu_head rcu;
 -      };
 +      struct rcu_head rcu;
  };
  
  /**
@@@ -513,7 -516,7 +513,7 @@@ ecryptfs_dentry_to_lower_path(struct de
  }
  
  #define ecryptfs_printk(type, fmt, arg...) \
-         __ecryptfs_printk(type "%s: " fmt, __func__, ## arg);
+         __ecryptfs_printk(type "%s: " fmt, __func__, ## arg)
  __printf(1, 2)
  void __ecryptfs_printk(const char *fmt, ...);
  
diff --combined fs/ecryptfs/inode.c
index 0a1ab1db14503df4bd240494a799e2d016afe879,11953eff1ad81ff4e5b8ec2cea120a29c5fa8a4a..16d50dface59abfc03ed0899f91a1b40ac8dd5d2
@@@ -1,5 -1,5 +1,5 @@@
  // SPDX-License-Identifier: GPL-2.0-or-later
- /**
+ /*
   * eCryptfs: Linux filesystem encryption layer
   *
   * Copyright (C) 1997-2004 Erez Zadok
  #include <linux/fs_stack.h>
  #include <linux/slab.h>
  #include <linux/xattr.h>
 +#include <linux/fileattr.h>
  #include <asm/unaligned.h>
  #include "ecryptfs_kernel.h"
  
 -static struct dentry *lock_parent(struct dentry *dentry)
 +static int lock_parent(struct dentry *dentry,
 +                     struct dentry **lower_dentry,
 +                     struct inode **lower_dir)
  {
 -      struct dentry *dir;
 +      struct dentry *lower_dir_dentry;
  
 -      dir = dget_parent(dentry);
 -      inode_lock_nested(d_inode(dir), I_MUTEX_PARENT);
 -      return dir;
 -}
 +      lower_dir_dentry = ecryptfs_dentry_to_lower(dentry->d_parent);
 +      *lower_dir = d_inode(lower_dir_dentry);
 +      *lower_dentry = ecryptfs_dentry_to_lower(dentry);
  
 -static void unlock_dir(struct dentry *dir)
 -{
 -      inode_unlock(d_inode(dir));
 -      dput(dir);
 +      inode_lock_nested(*lower_dir, I_MUTEX_PARENT);
 +      return (*lower_dentry)->d_parent == lower_dir_dentry ? 0 : -EINVAL;
  }
  
  static int ecryptfs_inode_test(struct inode *inode, void *lower_inode)
@@@ -127,29 -127,32 +127,29 @@@ static int ecryptfs_interpose(struct de
  static int ecryptfs_do_unlink(struct inode *dir, struct dentry *dentry,
                              struct inode *inode)
  {
 -      struct dentry *lower_dentry = ecryptfs_dentry_to_lower(dentry);
 -      struct dentry *lower_dir_dentry;
 -      struct inode *lower_dir_inode;
 +      struct dentry *lower_dentry;
 +      struct inode *lower_dir;
        int rc;
  
 -      lower_dir_dentry = ecryptfs_dentry_to_lower(dentry->d_parent);
 -      lower_dir_inode = d_inode(lower_dir_dentry);
 -      inode_lock_nested(lower_dir_inode, I_MUTEX_PARENT);
 +      rc = lock_parent(dentry, &lower_dentry, &lower_dir);
        dget(lower_dentry);     // don't even try to make the lower negative
 -      if (lower_dentry->d_parent != lower_dir_dentry)
 -              rc = -EINVAL;
 -      else if (d_unhashed(lower_dentry))
 -              rc = -EINVAL;
 -      else
 -              rc = vfs_unlink(&init_user_ns, lower_dir_inode, lower_dentry,
 -                              NULL);
 +      if (!rc) {
 +              if (d_unhashed(lower_dentry))
 +                      rc = -EINVAL;
 +              else
 +                      rc = vfs_unlink(&init_user_ns, lower_dir, lower_dentry,
 +                                      NULL);
 +      }
        if (rc) {
                printk(KERN_ERR "Error in vfs_unlink; rc = [%d]\n", rc);
                goto out_unlock;
        }
 -      fsstack_copy_attr_times(dir, lower_dir_inode);
 +      fsstack_copy_attr_times(dir, lower_dir);
        set_nlink(inode, ecryptfs_inode_to_lower(inode)->i_nlink);
        inode->i_ctime = dir->i_ctime;
  out_unlock:
        dput(lower_dentry);
 -      inode_unlock(lower_dir_inode);
 +      inode_unlock(lower_dir);
        if (!rc)
                d_drop(dentry);
        return rc;
@@@ -173,13 -176,13 +173,13 @@@ ecryptfs_do_create(struct inode *direct
  {
        int rc;
        struct dentry *lower_dentry;
 -      struct dentry *lower_dir_dentry;
 +      struct inode *lower_dir;
        struct inode *inode;
  
 -      lower_dentry = ecryptfs_dentry_to_lower(ecryptfs_dentry);
 -      lower_dir_dentry = lock_parent(lower_dentry);
 -      rc = vfs_create(&init_user_ns, d_inode(lower_dir_dentry), lower_dentry,
 -                      mode, true);
 +      rc = lock_parent(ecryptfs_dentry, &lower_dentry, &lower_dir);
 +      if (!rc)
 +              rc = vfs_create(&init_user_ns, lower_dir,
 +                              lower_dentry, mode, true);
        if (rc) {
                printk(KERN_ERR "%s: Failure to create dentry in lower fs; "
                       "rc = [%d]\n", __func__, rc);
        inode = __ecryptfs_get_inode(d_inode(lower_dentry),
                                     directory_inode->i_sb);
        if (IS_ERR(inode)) {
 -              vfs_unlink(&init_user_ns, d_inode(lower_dir_dentry),
 -                         lower_dentry, NULL);
 +              vfs_unlink(&init_user_ns, lower_dir, lower_dentry, NULL);
                goto out_lock;
        }
 -      fsstack_copy_attr_times(directory_inode, d_inode(lower_dir_dentry));
 -      fsstack_copy_inode_size(directory_inode, d_inode(lower_dir_dentry));
 +      fsstack_copy_attr_times(directory_inode, lower_dir);
 +      fsstack_copy_inode_size(directory_inode, lower_dir);
  out_lock:
 -      unlock_dir(lower_dir_dentry);
 +      inode_unlock(lower_dir);
        return inode;
  }
  
- /**
+ /*
   * ecryptfs_initialize_file
   *
   * Cause the file to be changed from a basic empty file to an ecryptfs
@@@ -242,10 -246,8 +242,8 @@@ out
        return rc;
  }
  
- /**
+ /*
   * ecryptfs_create
-  * @dir: The inode of the directory in which to create the file.
-  * @dentry: The eCryptfs dentry
   * @mode: The mode of the new file.
   *
   * Creates a new file.
@@@ -313,7 -315,7 +311,7 @@@ static int ecryptfs_i_size_read(struct 
        return 0;
  }
  
- /**
+ /*
   * ecryptfs_lookup_interpose - Dentry interposition for a lookup
   */
  static struct dentry *ecryptfs_lookup_interpose(struct dentry *dentry,
@@@ -426,28 -428,32 +424,28 @@@ static int ecryptfs_link(struct dentry 
  {
        struct dentry *lower_old_dentry;
        struct dentry *lower_new_dentry;
 -      struct dentry *lower_dir_dentry;
 +      struct inode *lower_dir;
        u64 file_size_save;
        int rc;
  
        file_size_save = i_size_read(d_inode(old_dentry));
        lower_old_dentry = ecryptfs_dentry_to_lower(old_dentry);
 -      lower_new_dentry = ecryptfs_dentry_to_lower(new_dentry);
 -      dget(lower_old_dentry);
 -      dget(lower_new_dentry);
 -      lower_dir_dentry = lock_parent(lower_new_dentry);
 -      rc = vfs_link(lower_old_dentry, &init_user_ns,
 -                    d_inode(lower_dir_dentry), lower_new_dentry, NULL);
 +      rc = lock_parent(new_dentry, &lower_new_dentry, &lower_dir);
 +      if (!rc)
 +              rc = vfs_link(lower_old_dentry, &init_user_ns, lower_dir,
 +                            lower_new_dentry, NULL);
        if (rc || d_really_is_negative(lower_new_dentry))
                goto out_lock;
        rc = ecryptfs_interpose(lower_new_dentry, new_dentry, dir->i_sb);
        if (rc)
                goto out_lock;
 -      fsstack_copy_attr_times(dir, d_inode(lower_dir_dentry));
 -      fsstack_copy_inode_size(dir, d_inode(lower_dir_dentry));
 +      fsstack_copy_attr_times(dir, lower_dir);
 +      fsstack_copy_inode_size(dir, lower_dir);
        set_nlink(d_inode(old_dentry),
                  ecryptfs_inode_to_lower(d_inode(old_dentry))->i_nlink);
        i_size_write(d_inode(new_dentry), file_size_save);
  out_lock:
 -      unlock_dir(lower_dir_dentry);
 -      dput(lower_new_dentry);
 -      dput(lower_old_dentry);
 +      inode_unlock(lower_dir);
        return rc;
  }
  
@@@ -462,14 -468,14 +460,14 @@@ static int ecryptfs_symlink(struct user
  {
        int rc;
        struct dentry *lower_dentry;
 -      struct dentry *lower_dir_dentry;
 +      struct inode *lower_dir;
        char *encoded_symname;
        size_t encoded_symlen;
        struct ecryptfs_mount_crypt_stat *mount_crypt_stat = NULL;
  
 -      lower_dentry = ecryptfs_dentry_to_lower(dentry);
 -      dget(lower_dentry);
 -      lower_dir_dentry = lock_parent(lower_dentry);
 +      rc = lock_parent(dentry, &lower_dentry, &lower_dir);
 +      if (rc)
 +              goto out_lock;
        mount_crypt_stat = &ecryptfs_superblock_to_private(
                dir->i_sb)->mount_crypt_stat;
        rc = ecryptfs_encrypt_and_encode_filename(&encoded_symname,
                                                  strlen(symname));
        if (rc)
                goto out_lock;
 -      rc = vfs_symlink(&init_user_ns, d_inode(lower_dir_dentry), lower_dentry,
 +      rc = vfs_symlink(&init_user_ns, lower_dir, lower_dentry,
                         encoded_symname);
        kfree(encoded_symname);
        if (rc || d_really_is_negative(lower_dentry))
        rc = ecryptfs_interpose(lower_dentry, dentry, dir->i_sb);
        if (rc)
                goto out_lock;
 -      fsstack_copy_attr_times(dir, d_inode(lower_dir_dentry));
 -      fsstack_copy_inode_size(dir, d_inode(lower_dir_dentry));
 +      fsstack_copy_attr_times(dir, lower_dir);
 +      fsstack_copy_inode_size(dir, lower_dir);
  out_lock:
 -      unlock_dir(lower_dir_dentry);
 -      dput(lower_dentry);
 +      inode_unlock(lower_dir);
        if (d_really_is_negative(dentry))
                d_drop(dentry);
        return rc;
@@@ -500,22 -507,22 +498,22 @@@ static int ecryptfs_mkdir(struct user_n
  {
        int rc;
        struct dentry *lower_dentry;
 -      struct dentry *lower_dir_dentry;
 +      struct inode *lower_dir;
  
 -      lower_dentry = ecryptfs_dentry_to_lower(dentry);
 -      lower_dir_dentry = lock_parent(lower_dentry);
 -      rc = vfs_mkdir(&init_user_ns, d_inode(lower_dir_dentry), lower_dentry,
 -                     mode);
 +      rc = lock_parent(dentry, &lower_dentry, &lower_dir);
 +      if (!rc)
 +              rc = vfs_mkdir(&init_user_ns, lower_dir,
 +                             lower_dentry, mode);
        if (rc || d_really_is_negative(lower_dentry))
                goto out;
        rc = ecryptfs_interpose(lower_dentry, dentry, dir->i_sb);
        if (rc)
                goto out;
 -      fsstack_copy_attr_times(dir, d_inode(lower_dir_dentry));
 -      fsstack_copy_inode_size(dir, d_inode(lower_dir_dentry));
 -      set_nlink(dir, d_inode(lower_dir_dentry)->i_nlink);
 +      fsstack_copy_attr_times(dir, lower_dir);
 +      fsstack_copy_inode_size(dir, lower_dir);
 +      set_nlink(dir, lower_dir->i_nlink);
  out:
 -      unlock_dir(lower_dir_dentry);
 +      inode_unlock(lower_dir);
        if (d_really_is_negative(dentry))
                d_drop(dentry);
        return rc;
  static int ecryptfs_rmdir(struct inode *dir, struct dentry *dentry)
  {
        struct dentry *lower_dentry;
 -      struct dentry *lower_dir_dentry;
 -      struct inode *lower_dir_inode;
 +      struct inode *lower_dir;
        int rc;
  
 -      lower_dentry = ecryptfs_dentry_to_lower(dentry);
 -      lower_dir_dentry = ecryptfs_dentry_to_lower(dentry->d_parent);
 -      lower_dir_inode = d_inode(lower_dir_dentry);
 -
 -      inode_lock_nested(lower_dir_inode, I_MUTEX_PARENT);
 +      rc = lock_parent(dentry, &lower_dentry, &lower_dir);
        dget(lower_dentry);     // don't even try to make the lower negative
 -      if (lower_dentry->d_parent != lower_dir_dentry)
 -              rc = -EINVAL;
 -      else if (d_unhashed(lower_dentry))
 -              rc = -EINVAL;
 -      else
 -              rc = vfs_rmdir(&init_user_ns, lower_dir_inode, lower_dentry);
 +      if (!rc) {
 +              if (d_unhashed(lower_dentry))
 +                      rc = -EINVAL;
 +              else
 +                      rc = vfs_rmdir(&init_user_ns, lower_dir, lower_dentry);
 +      }
        if (!rc) {
                clear_nlink(d_inode(dentry));
 -              fsstack_copy_attr_times(dir, lower_dir_inode);
 -              set_nlink(dir, lower_dir_inode->i_nlink);
 +              fsstack_copy_attr_times(dir, lower_dir);
 +              set_nlink(dir, lower_dir->i_nlink);
        }
        dput(lower_dentry);
 -      inode_unlock(lower_dir_inode);
 +      inode_unlock(lower_dir);
        if (!rc)
                d_drop(dentry);
        return rc;
@@@ -553,21 -565,21 +551,21 @@@ ecryptfs_mknod(struct user_namespace *m
  {
        int rc;
        struct dentry *lower_dentry;
 -      struct dentry *lower_dir_dentry;
 +      struct inode *lower_dir;
  
 -      lower_dentry = ecryptfs_dentry_to_lower(dentry);
 -      lower_dir_dentry = lock_parent(lower_dentry);
 -      rc = vfs_mknod(&init_user_ns, d_inode(lower_dir_dentry), lower_dentry,
 -                     mode, dev);
 +      rc = lock_parent(dentry, &lower_dentry, &lower_dir);
 +      if (!rc)
 +              rc = vfs_mknod(&init_user_ns, lower_dir,
 +                             lower_dentry, mode, dev);
        if (rc || d_really_is_negative(lower_dentry))
                goto out;
        rc = ecryptfs_interpose(lower_dentry, dentry, dir->i_sb);
        if (rc)
                goto out;
 -      fsstack_copy_attr_times(dir, d_inode(lower_dir_dentry));
 -      fsstack_copy_inode_size(dir, d_inode(lower_dir_dentry));
 +      fsstack_copy_attr_times(dir, lower_dir);
 +      fsstack_copy_inode_size(dir, lower_dir);
  out:
 -      unlock_dir(lower_dir_dentry);
 +      inode_unlock(lower_dir);
        if (d_really_is_negative(dentry))
                d_drop(dentry);
        return rc;
@@@ -873,6 -885,7 +871,7 @@@ ecryptfs_permission(struct user_namespa
  
  /**
   * ecryptfs_setattr
+  * @mnt_userns: user namespace of the target mount
   * @dentry: dentry handle to the inode to modify
   * @ia: Structure with flags of what to change and values
   *
        return rc;
  }
  
 +static int ecryptfs_fileattr_get(struct dentry *dentry, struct fileattr *fa)
 +{
 +      return vfs_fileattr_get(ecryptfs_dentry_to_lower(dentry), fa);
 +}
 +
 +static int ecryptfs_fileattr_set(struct user_namespace *mnt_userns,
 +                               struct dentry *dentry, struct fileattr *fa)
 +{
 +      struct dentry *lower_dentry = ecryptfs_dentry_to_lower(dentry);
 +      int rc;
 +
 +      rc = vfs_fileattr_set(&init_user_ns, lower_dentry, fa);
 +      fsstack_copy_attr_all(d_inode(dentry), d_inode(lower_dentry));
 +
 +      return rc;
 +}
 +
  const struct inode_operations ecryptfs_symlink_iops = {
        .get_link = ecryptfs_get_link,
        .permission = ecryptfs_permission,
@@@ -1142,8 -1138,6 +1141,8 @@@ const struct inode_operations ecryptfs_
        .permission = ecryptfs_permission,
        .setattr = ecryptfs_setattr,
        .listxattr = ecryptfs_listxattr,
 +      .fileattr_get = ecryptfs_fileattr_get,
 +      .fileattr_set = ecryptfs_fileattr_set,
  };
  
  const struct inode_operations ecryptfs_main_iops = {
        .setattr = ecryptfs_setattr,
        .getattr = ecryptfs_getattr,
        .listxattr = ecryptfs_listxattr,
 +      .fileattr_get = ecryptfs_fileattr_get,
 +      .fileattr_set = ecryptfs_fileattr_set,
  };
  
  static int ecryptfs_xattr_get(const struct xattr_handler *handler,