Skip to content

Commit 6fc9222

Browse files
committed
use uniform permission checks for all mount propagation changes
jira VULN-98610 cve-bf CVE-2025-38498 commit-author Al Viro <[email protected]> commit cffd044 do_change_type() and do_set_group() are operating on different aspects of the same thing - propagation graph. The latter asks for mounts involved to be mounted in namespace(s) the caller has CAP_SYS_ADMIN for. The former is a mess - originally it didn't even check that mount *is* mounted. That got fixed, but the resulting check turns out to be too strict for userland - in effect, we check that mount is in our namespace, having already checked that we have CAP_SYS_ADMIN there. What we really need (in both cases) is * only touch mounts that are mounted. That's a must-have constraint - data corruption happens if it get violated. * don't allow to mess with a namespace unless you already have enough permissions to do so (i.e. CAP_SYS_ADMIN in its userns). That's an equivalent of what do_set_group() does; let's extract that into a helper (may_change_propagation()) and use it in both do_set_group() and do_change_type(). Fixes: 12f147d "do_change_type(): refuse to operate on unmounted/not ours mounts" Acked-by: Andrei Vagin <[email protected]> Reviewed-by: Pavel Tikhomirov <[email protected]> Tested-by: Pavel Tikhomirov <[email protected]> Reviewed-by: Christian Brauner <[email protected]> Signed-off-by: Al Viro <[email protected]> (cherry picked from commit cffd044) Signed-off-by: Roxana Nicolescu <[email protected]>
1 parent 64d6ebe commit 6fc9222

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

fs/namespace.c

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2293,6 +2293,19 @@ static int graft_tree(struct mount *mnt, struct mount *p, struct mountpoint *mp)
22932293
return attach_recursive_mnt(mnt, p, mp, false);
22942294
}
22952295

2296+
static int may_change_propagation(const struct mount *m)
2297+
{
2298+
struct mnt_namespace *ns = m->mnt_ns;
2299+
2300+
// it must be mounted in some namespace
2301+
if (IS_ERR_OR_NULL(ns)) // is_mounted()
2302+
return -EINVAL;
2303+
// and the caller must be admin in userns of that namespace
2304+
if (!ns_capable(ns->user_ns, CAP_SYS_ADMIN))
2305+
return -EPERM;
2306+
return 0;
2307+
}
2308+
22962309
/*
22972310
* Sanity check the flags to change_mnt_propagation.
22982311
*/
@@ -2329,10 +2342,10 @@ static int do_change_type(struct path *path, int ms_flags)
23292342
return -EINVAL;
23302343

23312344
namespace_lock();
2332-
if (!check_mnt(mnt)) {
2333-
err = -EINVAL;
2345+
err = may_change_propagation(mnt);
2346+
if (err)
23342347
goto out_unlock;
2335-
}
2348+
23362349
if (type == MS_SHARED) {
23372350
err = invent_group_ids(mnt, recurse);
23382351
if (err)
@@ -2715,18 +2728,11 @@ static int do_set_group(struct path *from_path, struct path *to_path)
27152728

27162729
namespace_lock();
27172730

2718-
err = -EINVAL;
2719-
/* To and From must be mounted */
2720-
if (!is_mounted(&from->mnt))
2721-
goto out;
2722-
if (!is_mounted(&to->mnt))
2723-
goto out;
2724-
2725-
err = -EPERM;
2726-
/* We should be allowed to modify mount namespaces of both mounts */
2727-
if (!ns_capable(from->mnt_ns->user_ns, CAP_SYS_ADMIN))
2731+
err = may_change_propagation(from);
2732+
if (err)
27282733
goto out;
2729-
if (!ns_capable(to->mnt_ns->user_ns, CAP_SYS_ADMIN))
2734+
err = may_change_propagation(to);
2735+
if (err)
27302736
goto out;
27312737

27322738
err = -EINVAL;

0 commit comments

Comments
 (0)