do_change_type(): refuse to operate on unmounted/not ours mounts

[ Upstream commit 12f147ddd6de7382dad54812e65f3f08d05809fc ]

Ensure that propagation settings can only be changed for mounts located
in the caller's mount namespace. This change aligns permission checking
with the rest of mount(2).

Reviewed-by: Christian Brauner <brauner@kernel.org>
Fixes: 07b20889e3 ("beginning of the shared-subtree proper")
Reported-by: "Orlando, Noah" <Noah.Orlando@deshaw.com>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Sasha Levin <sashal@kernel.org>
(cherry picked from commit 4f091ad0862b02dc42a19a120b7048de848561f8)
This commit is contained in:
Al Viro 2025-06-04 12:27:08 -04:00 committed by Wentao Guan
parent 1ee6ad481b
commit 01f70b9de5
1 changed files with 4 additions and 0 deletions

View File

@ -2557,6 +2557,10 @@ static int do_change_type(struct path *path, int ms_flags)
return -EINVAL;
namespace_lock();
if (!check_mnt(mnt)) {
err = -EINVAL;
goto out_unlock;
}
if (type == MS_SHARED) {
err = invent_group_ids(mnt, recurse);
if (err)