do_change_type(): refuse to operate on unmounted/not ours mounts
authorAl Viro <viro@zeniv.linux.org.uk>
Wed, 4 Jun 2025 16:27:08 +0000 (12:27 -0400)
committerAl Viro <viro@zeniv.linux.org.uk>
Sat, 7 Jun 2025 05:37:56 +0000 (01:37 -0400)
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: 07b20889e305 ("beginning of the shared-subtree proper")
Reported-by: "Orlando, Noah" <Noah.Orlando@deshaw.com>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
fs/namespace.c

index 1c54c16c7babebb9dfcec0e8807324ec891e6d44..2721d64ecfdf1c64c532e5c6f80450e464e1be5f 100644 (file)
@@ -2959,6 +2959,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)