Skip to content

Commit 05da054

Browse files
author
Al Viro
committed
new predicate: anon_ns_root(mount)
checks if mount is the root of an anonymouns namespace. Switch open-coded equivalents to using it. For mounts that belong to anon namespace !mnt_has_parent(mount) is the same as mount == ns->root, and intent is more obvious in the latter form. Reviewed-by: Christian Brauner <[email protected]> Signed-off-by: Al Viro <[email protected]>
1 parent e031251 commit 05da054

File tree

2 files changed

+10
-25
lines changed

2 files changed

+10
-25
lines changed

fs/mount.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,13 @@ static inline bool is_anon_ns(struct mnt_namespace *ns)
161161
return ns->seq == 0;
162162
}
163163

164+
static inline bool anon_ns_root(const struct mount *m)
165+
{
166+
struct mnt_namespace *ns = READ_ONCE(m->mnt_ns);
167+
168+
return !IS_ERR_OR_NULL(ns) && is_anon_ns(ns) && m == ns->root;
169+
}
170+
164171
static inline bool mnt_ns_attached(const struct mount *mnt)
165172
{
166173
return !RB_EMPTY_NODE(&mnt->mnt_node);

fs/namespace.c

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2480,9 +2480,7 @@ struct vfsmount *clone_private_mount(const struct path *path)
24802480
* loops get created.
24812481
*/
24822482
if (!check_mnt(old_mnt)) {
2483-
if (!is_mounted(&old_mnt->mnt) ||
2484-
!is_anon_ns(old_mnt->mnt_ns) ||
2485-
mnt_has_parent(old_mnt))
2483+
if (!anon_ns_root(old_mnt))
24862484
return ERR_PTR(-EINVAL);
24872485

24882486
if (!check_for_nsfs_mounts(old_mnt))
@@ -3649,9 +3647,6 @@ static int do_move_mount(struct path *old_path,
36493647
ns = old->mnt_ns;
36503648

36513649
err = -EINVAL;
3652-
/* The thing moved must be mounted... */
3653-
if (!is_mounted(&old->mnt))
3654-
goto out;
36553650

36563651
if (check_mnt(old)) {
36573652
/* if the source is in our namespace... */
@@ -3664,10 +3659,8 @@ static int do_move_mount(struct path *old_path,
36643659
} else {
36653660
/*
36663661
* otherwise the source must be the root of some anon namespace.
3667-
* AV: check for mount being root of an anon namespace is worth
3668-
* an inlined predicate...
36693662
*/
3670-
if (!is_anon_ns(ns) || mnt_has_parent(old))
3663+
if (!anon_ns_root(old))
36713664
goto out;
36723665
/*
36733666
* Bail out early if the target is within the same namespace -
@@ -5028,22 +5021,7 @@ static int do_mount_setattr(struct path *path, struct mount_kattr *kattr)
50285021
err = -EINVAL;
50295022
lock_mount_hash();
50305023

5031-
/* Ensure that this isn't anything purely vfs internal. */
5032-
if (!is_mounted(&mnt->mnt))
5033-
goto out;
5034-
5035-
/*
5036-
* If this is an attached mount make sure it's located in the callers
5037-
* mount namespace. If it's not don't let the caller interact with it.
5038-
*
5039-
* If this mount doesn't have a parent it's most often simply a
5040-
* detached mount with an anonymous mount namespace. IOW, something
5041-
* that's simply not attached yet. But there are apparently also users
5042-
* that do change mount properties on the rootfs itself. That obviously
5043-
* neither has a parent nor is it a detached mount so we cannot
5044-
* unconditionally check for detached mounts.
5045-
*/
5046-
if ((mnt_has_parent(mnt) || !is_anon_ns(mnt->mnt_ns)) && !check_mnt(mnt))
5024+
if (!anon_ns_root(mnt) && !check_mnt(mnt))
50475025
goto out;
50485026

50495027
/*

0 commit comments

Comments
 (0)