Merge tag 'ecryptfs-3.9-rc2-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git...
authorLinus Torvalds <torvalds@linux-foundation.org>
Thu, 7 Mar 2013 20:47:24 +0000 (12:47 -0800)
committerLinus Torvalds <torvalds@linux-foundation.org>
Thu, 7 Mar 2013 20:47:24 +0000 (12:47 -0800)
Pull ecryptfs fixes from Tyler Hicks:
 "Minor code cleanups and new Kconfig option to disable /dev/ecryptfs

  The code cleanups fix up W=1 compiler warnings and some unnecessary
  checks.  The new Kconfig option, defaulting to N, allows the rarely
  used eCryptfs kernel to userspace communication channel to be compiled
  out.  This may be the first step in it being eventually removed."

Hmm.  I'm not sure whether these should be called "fixes", and it
probably should have gone in the merge window.  But I'll let it slide.

* tag 'ecryptfs-3.9-rc2-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/tyhicks/ecryptfs:
  eCryptfs: allow userspace messaging to be disabled
  eCryptfs: Fix redundant error check on ecryptfs_find_daemon_by_euid()
  ecryptfs: ecryptfs_msg_ctx_alloc_to_free(): remove kfree() redundant null check
  eCryptfs: decrypt_pki_encrypted_session_key(): remove kfree() redundant null check
  eCryptfs: remove unneeded checks in virt_to_scatterlist()
  eCryptfs: Fix -Wmissing-prototypes warnings
  eCryptfs: Fix -Wunused-but-set-variable warnings
  eCryptfs: initialize payload_len in keystore.c

1  2 
fs/ecryptfs/Kconfig
fs/ecryptfs/ecryptfs_kernel.h
fs/ecryptfs/file.c
fs/ecryptfs/inode.c
fs/ecryptfs/messaging.c

diff --combined fs/ecryptfs/Kconfig
@@@ -1,6 -1,6 +1,6 @@@
  config ECRYPT_FS
 -      tristate "eCrypt filesystem layer support (EXPERIMENTAL)"
 -      depends on EXPERIMENTAL && KEYS && CRYPTO && (ENCRYPTED_KEYS || ENCRYPTED_KEYS=n)
 +      tristate "eCrypt filesystem layer support"
 +      depends on KEYS && CRYPTO && (ENCRYPTED_KEYS || ENCRYPTED_KEYS=n)
        select CRYPTO_ECB
        select CRYPTO_CBC
        select CRYPTO_MD5
  
          To compile this file system support as a module, choose M here: the
          module will be called ecryptfs.
+ config ECRYPT_FS_MESSAGING
+       bool "Enable notifications for userspace key wrap/unwrap"
+       depends on ECRYPT_FS
+       help
+         Enables the /dev/ecryptfs entry for use by ecryptfsd. This allows
+         for userspace to wrap/unwrap file encryption keys by other
+         backends, like OpenSSL.
@@@ -172,6 -172,19 +172,19 @@@ ecryptfs_get_key_payload_data(struct ke
  #define ECRYPTFS_FNEK_ENCRYPTED_FILENAME_PREFIX_SIZE 24
  #define ECRYPTFS_ENCRYPTED_DENTRY_NAME_LEN (18 + 1 + 4 + 1 + 32)
  
+ #ifdef CONFIG_ECRYPT_FS_MESSAGING
+ # define ECRYPTFS_VERSIONING_MASK_MESSAGING (ECRYPTFS_VERSIONING_DEVMISC \
+                                            | ECRYPTFS_VERSIONING_PUBKEY)
+ #else
+ # define ECRYPTFS_VERSIONING_MASK_MESSAGING 0
+ #endif
+ #define ECRYPTFS_VERSIONING_MASK (ECRYPTFS_VERSIONING_PASSPHRASE \
+                                 | ECRYPTFS_VERSIONING_PLAINTEXT_PASSTHROUGH \
+                                 | ECRYPTFS_VERSIONING_XATTR \
+                                 | ECRYPTFS_VERSIONING_MULTKEY \
+                                 | ECRYPTFS_VERSIONING_MASK_MESSAGING \
+                                 | ECRYPTFS_VERSIONING_FILENAME_ENCRYPTION)
  struct ecryptfs_key_sig {
        struct list_head crypt_stat_list;
        char keysig[ECRYPTFS_SIG_SIZE_HEX + 1];
@@@ -399,7 -412,9 +412,9 @@@ struct ecryptfs_daemon 
        struct hlist_node euid_chain;
  };
  
+ #ifdef CONFIG_ECRYPT_FS_MESSAGING
  extern struct mutex ecryptfs_daemon_hash_mux;
+ #endif
  
  static inline size_t
  ecryptfs_lower_header_size(struct ecryptfs_crypt_stat *crypt_stat)
@@@ -509,12 -524,6 +524,12 @@@ ecryptfs_dentry_to_lower_mnt(struct den
        return ((struct ecryptfs_dentry_info *)dentry->d_fsdata)->lower_path.mnt;
  }
  
 +static inline struct path *
 +ecryptfs_dentry_to_lower_path(struct dentry *dentry)
 +{
 +      return &((struct ecryptfs_dentry_info *)dentry->d_fsdata)->lower_path;
 +}
 +
  static inline void
  ecryptfs_set_dentry_lower_mnt(struct dentry *dentry, struct vfsmount *lower_mnt)
  {
@@@ -610,6 -619,7 +625,7 @@@ in
  ecryptfs_setxattr(struct dentry *dentry, const char *name, const void *value,
                  size_t size, int flags);
  int ecryptfs_read_xattr_region(char *page_virt, struct inode *ecryptfs_inode);
+ #ifdef CONFIG_ECRYPT_FS_MESSAGING
  int ecryptfs_process_response(struct ecryptfs_daemon *daemon,
                              struct ecryptfs_message *msg, u32 seq);
  int ecryptfs_send_message(char *data, int data_len,
@@@ -618,6 -628,24 +634,24 @@@ int ecryptfs_wait_for_response(struct e
                               struct ecryptfs_message **emsg);
  int ecryptfs_init_messaging(void);
  void ecryptfs_release_messaging(void);
+ #else
+ static inline int ecryptfs_init_messaging(void)
+ {
+       return 0;
+ }
+ static inline void ecryptfs_release_messaging(void)
+ { }
+ static inline int ecryptfs_send_message(char *data, int data_len,
+                                       struct ecryptfs_msg_ctx **msg_ctx)
+ {
+       return -ENOTCONN;
+ }
+ static inline int ecryptfs_wait_for_response(struct ecryptfs_msg_ctx *msg_ctx,
+                                            struct ecryptfs_message **emsg)
+ {
+       return -ENOMSG;
+ }
+ #endif
  
  void
  ecryptfs_write_header_metadata(char *virt,
@@@ -655,12 -683,11 +689,11 @@@ int ecryptfs_read_lower_page_segment(st
                                     size_t offset_in_page, size_t size,
                                     struct inode *ecryptfs_inode);
  struct page *ecryptfs_get_locked_page(struct inode *inode, loff_t index);
- int ecryptfs_exorcise_daemon(struct ecryptfs_daemon *daemon);
- int ecryptfs_find_daemon_by_euid(struct ecryptfs_daemon **daemon);
  int ecryptfs_parse_packet_length(unsigned char *data, size_t *size,
                                 size_t *length_size);
  int ecryptfs_write_packet_length(char *dest, size_t size,
                                 size_t *packet_size_length);
+ #ifdef CONFIG_ECRYPT_FS_MESSAGING
  int ecryptfs_init_ecryptfs_miscdev(void);
  void ecryptfs_destroy_ecryptfs_miscdev(void);
  int ecryptfs_send_miscdev(char *data, size_t data_size,
  void ecryptfs_msg_ctx_alloc_to_free(struct ecryptfs_msg_ctx *msg_ctx);
  int
  ecryptfs_spawn_daemon(struct ecryptfs_daemon **daemon, struct file *file);
+ int ecryptfs_exorcise_daemon(struct ecryptfs_daemon *daemon);
+ int ecryptfs_find_daemon_by_euid(struct ecryptfs_daemon **daemon);
+ #endif
  int ecryptfs_init_kthread(void);
  void ecryptfs_destroy_kthread(void);
  int ecryptfs_privileged_open(struct file **lower_file,
diff --combined fs/ecryptfs/file.c
@@@ -118,7 -118,7 +118,7 @@@ static int ecryptfs_readdir(struct fil
  
        lower_file = ecryptfs_file_to_lower(file);
        lower_file->f_pos = file->f_pos;
 -      inode = file->f_path.dentry->d_inode;
 +      inode = file_inode(file);
        memset(&buf, 0, sizeof(buf));
        buf.dirent = dirent;
        buf.dentry = file->f_path.dentry;
                goto out;
        if (rc >= 0)
                fsstack_copy_attr_atime(inode,
 -                                      lower_file->f_path.dentry->d_inode);
 +                                      file_inode(lower_file));
  out:
        return rc;
  }
@@@ -199,7 -199,6 +199,6 @@@ static int ecryptfs_open(struct inode *
        struct dentry *ecryptfs_dentry = file->f_path.dentry;
        /* Private value of ecryptfs_dentry allocated in
         * ecryptfs_lookup() */
-       struct dentry *lower_dentry;
        struct ecryptfs_file_info *file_info;
  
        mount_crypt_stat = &ecryptfs_superblock_to_private(
                rc = -ENOMEM;
                goto out;
        }
-       lower_dentry = ecryptfs_dentry_to_lower(ecryptfs_dentry);
        crypt_stat = &ecryptfs_inode_to_private(inode)->crypt_stat;
        mutex_lock(&crypt_stat->cs_mutex);
        if (!(crypt_stat->flags & ECRYPTFS_POLICY_APPLIED)) {
diff --combined fs/ecryptfs/inode.c
@@@ -999,8 -999,8 +999,8 @@@ out
        return rc;
  }
  
- int ecryptfs_getattr_link(struct vfsmount *mnt, struct dentry *dentry,
-                         struct kstat *stat)
static int ecryptfs_getattr_link(struct vfsmount *mnt, struct dentry *dentry,
+                                struct kstat *stat)
  {
        struct ecryptfs_mount_crypt_stat *mount_crypt_stat;
        int rc = 0;
        return rc;
  }
  
- int ecryptfs_getattr(struct vfsmount *mnt, struct dentry *dentry,
-                    struct kstat *stat)
static int ecryptfs_getattr(struct vfsmount *mnt, struct dentry *dentry,
+                           struct kstat *stat)
  {
        struct kstat lower_stat;
        int rc;
  
 -      rc = vfs_getattr(ecryptfs_dentry_to_lower_mnt(dentry),
 -                       ecryptfs_dentry_to_lower(dentry), &lower_stat);
 +      rc = vfs_getattr(ecryptfs_dentry_to_lower_path(dentry), &lower_stat);
        if (!rc) {
                fsstack_copy_attr_all(dentry->d_inode,
                                      ecryptfs_inode_to_lower(dentry->d_inode));
diff --combined fs/ecryptfs/messaging.c
@@@ -97,8 -97,7 +97,7 @@@ static void ecryptfs_msg_ctx_free_to_al
  void ecryptfs_msg_ctx_alloc_to_free(struct ecryptfs_msg_ctx *msg_ctx)
  {
        list_move(&(msg_ctx->node), &ecryptfs_msg_ctx_free_list);
-       if (msg_ctx->msg)
-               kfree(msg_ctx->msg);
+       kfree(msg_ctx->msg);
        msg_ctx->msg = NULL;
        msg_ctx->state = ECRYPTFS_MSG_CTX_STATE_FREE;
  }
   */
  int ecryptfs_find_daemon_by_euid(struct ecryptfs_daemon **daemon)
  {
 -      struct hlist_node *elem;
        int rc;
  
 -      hlist_for_each_entry(*daemon, elem,
 +      hlist_for_each_entry(*daemon,
                            &ecryptfs_daemon_hash[ecryptfs_current_euid_hash()],
                            euid_chain) {
                if (uid_eq((*daemon)->file->f_cred->euid, current_euid())) {
@@@ -283,7 -283,7 +282,7 @@@ ecryptfs_send_message_locked(char *data
        int rc;
  
        rc = ecryptfs_find_daemon_by_euid(&daemon);
-       if (rc || !daemon) {
+       if (rc) {
                rc = -ENOTCONN;
                goto out;
        }
@@@ -444,6 -444,7 +443,6 @@@ void ecryptfs_release_messaging(void
                mutex_unlock(&ecryptfs_msg_ctx_lists_mux);
        }
        if (ecryptfs_daemon_hash) {
 -              struct hlist_node *elem;
                struct ecryptfs_daemon *daemon;
                int i;
  
                for (i = 0; i < (1 << ecryptfs_hash_bits); i++) {
                        int rc;
  
 -                      hlist_for_each_entry(daemon, elem,
 +                      hlist_for_each_entry(daemon,
                                             &ecryptfs_daemon_hash[i],
                                             euid_chain) {
                                rc = ecryptfs_exorcise_daemon(daemon);