mirror of
https://github.com/torvalds/linux.git
synced 2026-11-09 13:44:03 +01:00
namespace: check the target before walking it in do_mount_setattr()
When mount_setattr() changes the propagation type to MS_SHARED
do_mount_setattr() takes namespace_sem and calls invent_group_ids()
which walks the whole target tree with next_mnt() and allocates a peer
group id for every mount that doesn't have one.
Whether the caller may touch the target at all is only checked
afterwards under mount_lock. If it may not, cleanup_group_ids() walks
the tree a second time on the way out to free the ids again.
A detached tree that a file descriptor keeps alive, a mount in another
mount namespace or a mount below the root of an anonymous mount
namespace does a bunch of allocation work that is completely useless
because it will fail and revert right after.
Do the right thing and check the target right after taking namespace_sem
instead. A mount leaves its namespace only under namespace_sem so the
mount stays stable. The check under mount_lock stays for the case where
no propagation change is requested and namespace_sem isn't taken.
Callers get the same EINVAL as before.
Fixes: 2a1867219c ("fs: add mount_setattr()")
Cc: stable@vger.kernel.org
Link: https://patch.msgid.link/20260926-work-mount-fixes-2-v1-5-f357abf3d17b@kernel.org
Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
This commit is contained in:
parent
8bacbf6be9
commit
08f4288a37
|
|
@ -4976,6 +4976,11 @@ static int do_mount_setattr(const struct path *path, struct mount_kattr *kattr)
|
|||
* propagation.
|
||||
*/
|
||||
namespace_lock();
|
||||
/* invent_group_ids() walks the tree, only walk a mounted one */
|
||||
if (!anon_ns_root(mnt) && !check_mnt(mnt)) {
|
||||
namespace_unlock();
|
||||
return -EINVAL;
|
||||
}
|
||||
if (kattr->propagation == MS_SHARED) {
|
||||
err = invent_group_ids(mnt, kattr->kflags & MOUNT_KATTR_RECURSE);
|
||||
if (err) {
|
||||
|
|
@ -4988,6 +4993,7 @@ static int do_mount_setattr(const struct path *path, struct mount_kattr *kattr)
|
|||
err = -EINVAL;
|
||||
lock_mount_hash();
|
||||
|
||||
/* Checked under namespace_sem already if the propagation changes. */
|
||||
if (!anon_ns_root(mnt) && !check_mnt(mnt))
|
||||
goto out;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user