diff --git a/fs/namespace.c b/fs/namespace.c index dc31ad6b370f3..d946298691ed4 100644 --- a/fs/namespace.c +++ b/fs/namespace.c @@ -4168,6 +4168,13 @@ static int build_mount_idmapped(const struct mount_attr *attr, size_t usize, err = -EPERM; goto out_fput; } + + /* We're not controlling the target namespace. */ + if (!ns_capable(mnt_userns, CAP_SYS_ADMIN)) { + err = -EPERM; + goto out_fput; + } + kattr->mnt_userns = get_user_ns(mnt_userns); out_fput: