mnt: Fix fs_fully_visible to verify the root directory is visible
[pandora-kernel.git] / fs / namespace.c
index acc5583..1b9e111 100644 (file)
@@ -798,10 +798,8 @@ static void __touch_mnt_namespace(struct mnt_namespace *ns)
 /*
  * vfsmount lock must be held for write
  */
-static void detach_mnt(struct mount *mnt, struct path *old_path)
+static void unhash_mnt(struct mount *mnt)
 {
-       old_path->dentry = mnt->mnt_mountpoint;
-       old_path->mnt = &mnt->mnt_parent->mnt;
        mnt->mnt_parent = mnt;
        mnt->mnt_mountpoint = mnt->mnt.mnt_root;
        list_del_init(&mnt->mnt_child);
@@ -811,6 +809,26 @@ static void detach_mnt(struct mount *mnt, struct path *old_path)
        mnt->mnt_mp = NULL;
 }
 
+/*
+ * vfsmount lock must be held for write
+ */
+static void detach_mnt(struct mount *mnt, struct path *old_path)
+{
+       old_path->dentry = mnt->mnt_mountpoint;
+       old_path->mnt = &mnt->mnt_parent->mnt;
+       unhash_mnt(mnt);
+}
+
+/*
+ * vfsmount lock must be held for write
+ */
+static void umount_mnt(struct mount *mnt)
+{
+       /* old mountpoint will be dropped when we can do that */
+       mnt->mnt_ex_mountpoint = mnt->mnt_mountpoint;
+       unhash_mnt(mnt);
+}
+
 /*
  * vfsmount lock must be held for write
  */
@@ -1081,6 +1099,13 @@ static void mntput_no_expire(struct mount *mnt)
        rcu_read_unlock();
 
        list_del(&mnt->mnt_instance);
+
+       if (unlikely(!list_empty(&mnt->mnt_mounts))) {
+               struct mount *p, *tmp;
+               list_for_each_entry_safe(p, tmp, &mnt->mnt_mounts,  mnt_child) {
+                       umount_mnt(p);
+               }
+       }
        unlock_mount_hash();
 
        if (likely(!(mnt->mnt.mnt_flags & MNT_INTERNAL))) {
@@ -1323,6 +1348,7 @@ static inline void namespace_lock(void)
 enum umount_tree_flags {
        UMOUNT_SYNC = 1,
        UMOUNT_PROPAGATE = 2,
+       UMOUNT_CONNECTED = 4,
 };
 /*
  * mount_lock must be held
@@ -1352,6 +1378,7 @@ static void umount_tree(struct mount *mnt, enum umount_tree_flags how)
                propagate_umount(&tmp_list);
 
        while (!list_empty(&tmp_list)) {
+               bool disconnect;
                p = list_first_entry(&tmp_list, struct mount, mnt_list);
                list_del_init(&p->mnt_expire);
                list_del_init(&p->mnt_list);
@@ -1360,17 +1387,21 @@ static void umount_tree(struct mount *mnt, enum umount_tree_flags how)
                if (how & UMOUNT_SYNC)
                        p->mnt.mnt_flags |= MNT_SYNC_UMOUNT;
 
-               pin_insert_group(&p->mnt_umount, &p->mnt_parent->mnt, &unmounted);
+               disconnect = !(((how & UMOUNT_CONNECTED) &&
+                               mnt_has_parent(p) &&
+                               (p->mnt_parent->mnt.mnt_flags & MNT_UMOUNT)) ||
+                              IS_MNT_LOCKED_AND_LAZY(p));
+
+               pin_insert_group(&p->mnt_umount, &p->mnt_parent->mnt,
+                                disconnect ? &unmounted : NULL);
                if (mnt_has_parent(p)) {
-                       hlist_del_init(&p->mnt_mp_list);
-                       put_mountpoint(p->mnt_mp);
                        mnt_add_count(p->mnt_parent, -1);
-                       /* old mountpoint will be dropped when we can do that */
-                       p->mnt_ex_mountpoint = p->mnt_mountpoint;
-                       p->mnt_mountpoint = p->mnt.mnt_root;
-                       p->mnt_parent = p;
-                       p->mnt_mp = NULL;
-                       hlist_del_init_rcu(&p->mnt_hash);
+                       if (!disconnect) {
+                               /* Don't forget about p */
+                               list_add_tail(&p->mnt_child, &p->mnt_parent->mnt_mounts);
+                       } else {
+                               umount_mnt(p);
+                       }
                }
                change_mnt_propagation(p, MS_PRIVATE);
        }
@@ -1489,13 +1520,20 @@ void __detach_mounts(struct dentry *dentry)
 
        namespace_lock();
        mp = lookup_mountpoint(dentry);
-       if (!mp)
+       if (IS_ERR_OR_NULL(mp))
                goto out_unlock;
 
        lock_mount_hash();
        while (!hlist_empty(&mp->m_list)) {
                mnt = hlist_entry(mp->m_list.first, struct mount, mnt_mp_list);
-               umount_tree(mnt, 0);
+               if (mnt->mnt.mnt_flags & MNT_UMOUNT) {
+                       struct mount *p, *tmp;
+                       list_for_each_entry_safe(p, tmp, &mnt->mnt_mounts,  mnt_child) {
+                               hlist_add_head(&p->mnt_umount.s_list, &unmounted);
+                               umount_mnt(p);
+                       }
+               }
+               else umount_tree(mnt, UMOUNT_CONNECTED);
        }
        unlock_mount_hash();
        put_mountpoint(mp);
@@ -3141,6 +3179,12 @@ bool fs_fully_visible(struct file_system_type *type)
                if (mnt->mnt.mnt_sb->s_type != type)
                        continue;
 
+               /* This mount is not fully visible if it's root directory
+                * is not the root directory of the filesystem.
+                */
+               if (mnt->mnt.mnt_root != mnt->mnt.mnt_sb->s_root)
+                       continue;
+
                /* This mount is not fully visible if there are any child mounts
                 * that cover anything except for empty directories.
                 */