]> git.proxmox.com Git - pve-kernel.git/blame - patches/kernel/0009-userns-also-map-extents-in-the-reverse-map-to-kernel.patch
Update sources to Ubuntu-4.15.0-44.47
[pve-kernel.git] / patches / kernel / 0009-userns-also-map-extents-in-the-reverse-map-to-kernel.patch
CommitLineData
47f3b899
SI
1From 5506202b83e65b844309093e712b5b507eb1e403 Mon Sep 17 00:00:00 2001
2From: Jann Horn <jannh@google.com>
3Date: Tue, 13 Nov 2018 07:42:38 +0000
4Subject: [PATCH 09/11] userns: also map extents in the reverse map to kernel
5 IDs
6
7BugLink: https://launchpad.net/bugs/1801924
8
9The current logic first clones the extent array and sorts both copies, then
10maps the lower IDs of the forward mapping into the lower namespace, but
11doesn't map the lower IDs of the reverse mapping.
12
13This means that code in a nested user namespace with >5 extents will see
14incorrect IDs. It also breaks some access checks, like
15inode_owner_or_capable() and privileged_wrt_inode_uidgid(), so a process
16can incorrectly appear to be capable relative to an inode.
17
18To fix it, we have to make sure that the "lower_first" members of extents
19in both arrays are translated; and we have to make sure that the reverse
20map is sorted *after* the translation (since otherwise the translation can
21break the sorting).
22
23This is CVE-2018-18955.
24
25Fixes: 6397fac4915a ("userns: bump idmap limits to 340")
26Cc: stable@vger.kernel.org
27Signed-off-by: Jann Horn <jannh@google.com>
28Tested-by: Eric W. Biederman <ebiederm@xmission.com>
29Reviewed-by: Eric W. Biederman <ebiederm@xmission.com>
30Signed-off-by: Eric W. Biederman <ebiederm@xmission.com>
31
32CVE-2018-18955
33
34(cherry picked from commit d2f007dbe7e4c9583eea6eb04d60001e85c6f1bd)
35Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
36Acked-by: Colin King <colin.king@canonical.com>
37Acked-by: Thadeu Lima de Souza Cascardo <cascardo@canonical.com>
38Signed-off-by: Thadeu Lima de Souza Cascardo <cascardo@canonical.com>
39---
40 kernel/user_namespace.c | 12 ++++++++----
41 1 file changed, 8 insertions(+), 4 deletions(-)
42
43diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
44index 08d638386b83..12de8c144db9 100644
45--- a/kernel/user_namespace.c
46+++ b/kernel/user_namespace.c
47@@ -983,10 +983,6 @@ static ssize_t map_write(struct file *file, const char __user *buf,
48 if (!new_idmap_permitted(file, ns, cap_setid, &new_map))
49 goto out;
50
51- ret = sort_idmaps(&new_map);
52- if (ret < 0)
53- goto out;
54-
55 ret = -EPERM;
56 /* Map the lower ids from the parent user namespace to the
57 * kernel global id space.
58@@ -1013,6 +1009,14 @@ static ssize_t map_write(struct file *file, const char __user *buf,
59 e->lower_first = lower_first;
60 }
61
62+ /*
63+ * If we want to use binary search for lookup, this clones the extent
64+ * array and sorts both copies.
65+ */
66+ ret = sort_idmaps(&new_map);
67+ if (ret < 0)
68+ goto out;
69+
70 /* Install the map */
71 if (new_map.nr_extents <= UID_GID_MAP_MAX_BASE_EXTENTS) {
72 memcpy(map->extent, new_map.extent,
73--
742.11.0
75