Skip to content

Commit d7b7253

Browse files
author
Al Viro
committed
copy_mnt_ns(): use guards
* mntput() of rootmnt and pwdmnt done via __free(mntput) * mnt_ns_tree_add() can be done within namespace_excl scope. Signed-off-by: Al Viro <[email protected]>
1 parent 7bb4c85 commit d7b7253

File tree

1 file changed

+4
-12
lines changed

1 file changed

+4
-12
lines changed

fs/namespace.c

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4158,7 +4158,8 @@ struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
41584158
struct user_namespace *user_ns, struct fs_struct *new_fs)
41594159
{
41604160
struct mnt_namespace *new_ns;
4161-
struct vfsmount *rootmnt = NULL, *pwdmnt = NULL;
4161+
struct vfsmount *rootmnt __free(mntput) = NULL;
4162+
struct vfsmount *pwdmnt __free(mntput) = NULL;
41624163
struct mount *p, *q;
41634164
struct mount *old;
41644165
struct mount *new;
@@ -4177,21 +4178,19 @@ struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
41774178
if (IS_ERR(new_ns))
41784179
return new_ns;
41794180

4180-
namespace_lock();
4181+
guard(namespace_excl)();
41814182
/* First pass: copy the tree topology */
41824183
copy_flags = CL_COPY_UNBINDABLE | CL_EXPIRE;
41834184
if (user_ns != ns->user_ns)
41844185
copy_flags |= CL_SLAVE;
41854186
new = copy_tree(old, old->mnt.mnt_root, copy_flags);
41864187
if (IS_ERR(new)) {
41874188
emptied_ns = new_ns;
4188-
namespace_unlock();
41894189
return ERR_CAST(new);
41904190
}
41914191
if (user_ns != ns->user_ns) {
4192-
lock_mount_hash();
4192+
guard(mount_writer)();
41934193
lock_mnt_tree(new);
4194-
unlock_mount_hash();
41954194
}
41964195
new_ns->root = new;
41974196

@@ -4223,13 +4222,6 @@ struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
42234222
while (p->mnt.mnt_root != q->mnt.mnt_root)
42244223
p = next_mnt(skip_mnt_tree(p), old);
42254224
}
4226-
namespace_unlock();
4227-
4228-
if (rootmnt)
4229-
mntput(rootmnt);
4230-
if (pwdmnt)
4231-
mntput(pwdmnt);
4232-
42334225
mnt_ns_tree_add(new_ns);
42344226
return new_ns;
42354227
}

0 commit comments

Comments
 (0)