|
@@ -25,7 +25,8 @@
|
|
|
|
|
|
static struct kmem_cache *user_ns_cachep __read_mostly;
|
|
|
|
|
|
-static bool new_idmap_permitted(struct user_namespace *ns, int cap_setid,
|
|
|
+static bool new_idmap_permitted(const struct file *file,
|
|
|
+ struct user_namespace *ns, int cap_setid,
|
|
|
struct uid_gid_map *map);
|
|
|
|
|
|
static void set_cred_user_ns(struct cred *cred, struct user_namespace *user_ns)
|
|
@@ -700,7 +701,7 @@ static ssize_t map_write(struct file *file, const char __user *buf,
|
|
|
|
|
|
ret = -EPERM;
|
|
|
/* Validate the user is allowed to use user id's mapped to. */
|
|
|
- if (!new_idmap_permitted(ns, cap_setid, &new_map))
|
|
|
+ if (!new_idmap_permitted(file, ns, cap_setid, &new_map))
|
|
|
goto out;
|
|
|
|
|
|
/* Map the lower ids from the parent user namespace to the
|
|
@@ -787,7 +788,8 @@ ssize_t proc_projid_map_write(struct file *file, const char __user *buf, size_t
|
|
|
&ns->projid_map, &ns->parent->projid_map);
|
|
|
}
|
|
|
|
|
|
-static bool new_idmap_permitted(struct user_namespace *ns, int cap_setid,
|
|
|
+static bool new_idmap_permitted(const struct file *file,
|
|
|
+ struct user_namespace *ns, int cap_setid,
|
|
|
struct uid_gid_map *new_map)
|
|
|
{
|
|
|
/* Allow mapping to your own filesystem ids */
|
|
@@ -811,8 +813,10 @@ static bool new_idmap_permitted(struct user_namespace *ns, int cap_setid,
|
|
|
|
|
|
/* Allow the specified ids if we have the appropriate capability
|
|
|
* (CAP_SETUID or CAP_SETGID) over the parent user namespace.
|
|
|
+ * And the opener of the id file also had the approprpiate capability.
|
|
|
*/
|
|
|
- if (ns_capable(ns->parent, cap_setid))
|
|
|
+ if (ns_capable(ns->parent, cap_setid) &&
|
|
|
+ file_ns_capable(file, ns->parent, cap_setid))
|
|
|
return true;
|
|
|
|
|
|
return false;
|