Skip to content

Commit 7faecd4

Browse files
ebiedermgregkh
authored andcommitted
userns: Only allow the creator of the userns unprivileged mappings
commit f95d791 upstream. If you did not create the user namespace and are allowed to write to uid_map or gid_map you should already have the necessary privilege in the parent user namespace to establish any mapping you want so this will not affect userspace in practice. Limiting unprivileged uid mapping establishment to the creator of the user namespace makes it easier to verify all credentials obtained with the uid mapping can be obtained without the uid mapping without privilege. Limiting unprivileged gid mapping establishment (which is temporarily absent) to the creator of the user namespace also ensures that the combination of uid and gid can already be obtained without privilege. This is part of the fix for CVE-2014-8989. Reviewed-by: Andy Lutomirski <luto@amacapital.net> Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent ea7c8d3 commit 7faecd4

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

‎kernel/user_namespace.c‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -804,14 +804,16 @@ static bool new_idmap_permitted(const struct file *file,
804804
struct user_namespace *ns, int cap_setid,
805805
struct uid_gid_map *new_map)
806806
{
807+
const struct cred *cred = file->f_cred;
807808
/* Don't allow mappings that would allow anything that wouldn't
808809
* be allowed without the establishment of unprivileged mappings.
809810
*/
810-
if ((new_map->nr_extents == 1) && (new_map->extent[0].count == 1)) {
811+
if ((new_map->nr_extents == 1) && (new_map->extent[0].count == 1) &&
812+
uid_eq(ns->owner, cred->euid)) {
811813
u32 id = new_map->extent[0].lower_first;
812814
if (cap_setid == CAP_SETUID) {
813815
kuid_t uid = make_kuid(ns->parent, id);
814-
if (uid_eq(uid, file->f_cred->euid))
816+
if (uid_eq(uid, cred->euid))
815817
return true;
816818
}
817819
}

0 commit comments

Comments
 (0)