eCryptfs: check readlink result was not an error before using it
[safe/jmp/linux-2.6] / fs / ecryptfs / dentry.c
index 52d1e36..5e59658 100644 (file)
@@ -25,6 +25,7 @@
 #include <linux/dcache.h>
 #include <linux/namei.h>
 #include <linux/mount.h>
+#include <linux/fs_stack.h>
 #include "ecryptfs_kernel.h"
 
 /**
@@ -50,18 +51,18 @@ static int ecryptfs_d_revalidate(struct dentry *dentry, struct nameidata *nd)
 
        if (!lower_dentry->d_op || !lower_dentry->d_op->d_revalidate)
                goto out;
-       dentry_save = nd->dentry;
-       vfsmount_save = nd->mnt;
-       nd->dentry = lower_dentry;
-       nd->mnt = lower_mnt;
+       dentry_save = nd->path.dentry;
+       vfsmount_save = nd->path.mnt;
+       nd->path.dentry = lower_dentry;
+       nd->path.mnt = lower_mnt;
        rc = lower_dentry->d_op->d_revalidate(lower_dentry, nd);
-       nd->dentry = dentry_save;
-       nd->mnt = vfsmount_save;
+       nd->path.dentry = dentry_save;
+       nd->path.mnt = vfsmount_save;
        if (dentry->d_inode) {
                struct inode *lower_inode =
                        ecryptfs_inode_to_lower(dentry->d_inode);
 
-               ecryptfs_copy_attr_all(dentry->d_inode, lower_inode);
+               fsstack_copy_attr_all(dentry->d_inode, lower_inode, NULL);
        }
 out:
        return rc;
@@ -77,18 +78,13 @@ struct kmem_cache *ecryptfs_dentry_info_cache;
  */
 static void ecryptfs_d_release(struct dentry *dentry)
 {
-       struct dentry *lower_dentry;
-
-       lower_dentry = ecryptfs_dentry_to_lower(dentry);
-       if (ecryptfs_dentry_to_private(dentry))
+       if (ecryptfs_dentry_to_private(dentry)) {
+               if (ecryptfs_dentry_to_lower(dentry)) {
+                       dput(ecryptfs_dentry_to_lower(dentry));
+                       mntput(ecryptfs_dentry_to_lower_mnt(dentry));
+               }
                kmem_cache_free(ecryptfs_dentry_info_cache,
                                ecryptfs_dentry_to_private(dentry));
-       if (lower_dentry) {
-               struct vfsmount *lower_mnt =
-                       ecryptfs_dentry_to_lower_mnt(dentry);
-
-               mntput(lower_mnt);
-               dput(lower_dentry);
        }
        return;
 }