summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSona Sarmadi <sona.sarmadi@enea.com>2015-02-17 09:50:19 +0100
committerTudor Florea <tudor.florea@enea.com>2015-07-06 20:27:14 +0200
commit0efd2da7fc86df00635de10a16b843d142e9044f (patch)
tree4a9576a057d07907f56577dd76a680ded11f5733
parent499ef72deaee9d623eea5afcdb5c7a7793188acf (diff)
downloadmeta-enea-0efd2da7fc86df00635de10a16b843d142e9044f.tar.gz
fs-userns: CVE-2014-4014
Fixes a potential privilege escalation flaw when the Linux kernel is built with the user namespaces(CONFIG_USER_NS) References: http://www.openwall.com/lists/oss-security/2014/06/10/4 http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2014-4014 Signed-off-by: Sona Sarmadi <sona.sarmadi@enea.com>
-rw-r--r--recipes-kernel/linux/files/fs-CVE-2014-4014.patch194
-rw-r--r--recipes-kernel/linux/linux-qoriq-sdk.bbappend1
2 files changed, 195 insertions, 0 deletions
diff --git a/recipes-kernel/linux/files/fs-CVE-2014-4014.patch b/recipes-kernel/linux/files/fs-CVE-2014-4014.patch
new file mode 100644
index 0000000..bc457e6
--- /dev/null
+++ b/recipes-kernel/linux/files/fs-CVE-2014-4014.patch
@@ -0,0 +1,194 @@
1From 4f80c6c1825a91cecf3b3bd19c824e768d98fe48 Mon Sep 17 00:00:00 2001
2From: Andy Lutomirski <luto@amacapital.net>
3Date: Tue, 10 Jun 2014 12:45:42 -0700
4Subject: [PATCH] fs,userns: Change inode_capable to capable_wrt_inode_uidgid
5
6commit 23adbe12ef7d3d4195e80800ab36b37bee28cd03 upstream.
7
8The kernel has no concept of capabilities with respect to inodes; inodes
9exist independently of namespaces. For example, inode_capable(inode,
10CAP_LINUX_IMMUTABLE) would be nonsense.
11
12This patch changes inode_capable to check for uid and gid mappings and
13renames it to capable_wrt_inode_uidgid, which should make it more
14obvious what it does.
15
16Fixes CVE-2014-4014.
17Upstream-Status: Backport
18
19Cc: Theodore Ts'o <tytso@mit.edu>
20Cc: Serge Hallyn <serge.hallyn@ubuntu.com>
21Cc: "Eric W. Biederman" <ebiederm@xmission.com>
22Cc: Dave Chinner <david@fromorbit.com>
23Signed-off-by: Andy Lutomirski <luto@amacapital.net>
24Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
25Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
26Signed-off-by: Sona Sarmadi <sona.sarmadi@enea.com>
27---
28 fs/attr.c | 8 ++++----
29 fs/inode.c | 10 +++++++---
30 fs/namei.c | 11 ++++++-----
31 include/linux/capability.h | 2 +-
32 kernel/capability.c | 18 +++++++-----------
33 5 files changed, 25 insertions(+), 24 deletions(-)
34
35diff --git a/fs/attr.c b/fs/attr.c
36index 8dd5825..66fa625 100644
37--- a/fs/attr.c
38+++ b/fs/attr.c
39@@ -50,14 +50,14 @@ int inode_change_ok(const struct inode *inode, struct iattr *attr)
40 if ((ia_valid & ATTR_UID) &&
41 (!uid_eq(current_fsuid(), inode->i_uid) ||
42 !uid_eq(attr->ia_uid, inode->i_uid)) &&
43- !inode_capable(inode, CAP_CHOWN))
44+ !capable_wrt_inode_uidgid(inode, CAP_CHOWN))
45 return -EPERM;
46
47 /* Make sure caller can chgrp. */
48 if ((ia_valid & ATTR_GID) &&
49 (!uid_eq(current_fsuid(), inode->i_uid) ||
50 (!in_group_p(attr->ia_gid) && !gid_eq(attr->ia_gid, inode->i_gid))) &&
51- !inode_capable(inode, CAP_CHOWN))
52+ !capable_wrt_inode_uidgid(inode, CAP_CHOWN))
53 return -EPERM;
54
55 /* Make sure a caller can chmod. */
56@@ -67,7 +67,7 @@ int inode_change_ok(const struct inode *inode, struct iattr *attr)
57 /* Also check the setgid bit! */
58 if (!in_group_p((ia_valid & ATTR_GID) ? attr->ia_gid :
59 inode->i_gid) &&
60- !inode_capable(inode, CAP_FSETID))
61+ !capable_wrt_inode_uidgid(inode, CAP_FSETID))
62 attr->ia_mode &= ~S_ISGID;
63 }
64
65@@ -160,7 +160,7 @@ void setattr_copy(struct inode *inode, const struct iattr *attr)
66 umode_t mode = attr->ia_mode;
67
68 if (!in_group_p(inode->i_gid) &&
69- !inode_capable(inode, CAP_FSETID))
70+ !capable_wrt_inode_uidgid(inode, CAP_FSETID))
71 mode &= ~S_ISGID;
72 inode->i_mode = mode;
73 }
74diff --git a/fs/inode.c b/fs/inode.c
75index 00d5fc3..1b300a0 100644
76--- a/fs/inode.c
77+++ b/fs/inode.c
78@@ -1837,14 +1837,18 @@ EXPORT_SYMBOL(inode_init_owner);
79 * inode_owner_or_capable - check current task permissions to inode
80 * @inode: inode being checked
81 *
82- * Return true if current either has CAP_FOWNER to the inode, or
83- * owns the file.
84+ * Return true if current either has CAP_FOWNER in a namespace with the
85+ * inode owner uid mapped, or owns the file.
86 */
87 bool inode_owner_or_capable(const struct inode *inode)
88 {
89+ struct user_namespace *ns;
90+
91 if (uid_eq(current_fsuid(), inode->i_uid))
92 return true;
93- if (inode_capable(inode, CAP_FOWNER))
94+
95+ ns = current_user_ns();
96+ if (ns_capable(ns, CAP_FOWNER) && kuid_has_mapping(ns, inode->i_uid))
97 return true;
98 return false;
99 }
100diff --git a/fs/namei.c b/fs/namei.c
101index 1211ee5..6ac16a3 100644
102--- a/fs/namei.c
103+++ b/fs/namei.c
104@@ -321,10 +321,11 @@ int generic_permission(struct inode *inode, int mask)
105
106 if (S_ISDIR(inode->i_mode)) {
107 /* DACs are overridable for directories */
108- if (inode_capable(inode, CAP_DAC_OVERRIDE))
109+ if (capable_wrt_inode_uidgid(inode, CAP_DAC_OVERRIDE))
110 return 0;
111 if (!(mask & MAY_WRITE))
112- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
113+ if (capable_wrt_inode_uidgid(inode,
114+ CAP_DAC_READ_SEARCH))
115 return 0;
116 return -EACCES;
117 }
118@@ -334,7 +335,7 @@ int generic_permission(struct inode *inode, int mask)
119 * at least one exec bit set.
120 */
121 if (!(mask & MAY_EXEC) || (inode->i_mode & S_IXUGO))
122- if (inode_capable(inode, CAP_DAC_OVERRIDE))
123+ if (capable_wrt_inode_uidgid(inode, CAP_DAC_OVERRIDE))
124 return 0;
125
126 /*
127@@ -342,7 +343,7 @@ int generic_permission(struct inode *inode, int mask)
128 */
129 mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
130 if (mask == MAY_READ)
131- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
132+ if (capable_wrt_inode_uidgid(inode, CAP_DAC_READ_SEARCH))
133 return 0;
134
135 return -EACCES;
136@@ -2199,7 +2200,7 @@ static inline int check_sticky(struct inode *dir, struct inode *inode)
137 return 0;
138 if (uid_eq(dir->i_uid, fsuid))
139 return 0;
140- return !inode_capable(inode, CAP_FOWNER);
141+ return !capable_wrt_inode_uidgid(inode, CAP_FOWNER);
142 }
143
144 /*
145diff --git a/include/linux/capability.h b/include/linux/capability.h
146index d9a4f7f4..15f9092 100644
147--- a/include/linux/capability.h
148+++ b/include/linux/capability.h
149@@ -211,7 +211,7 @@ extern bool has_ns_capability_noaudit(struct task_struct *t,
150 extern bool capable(int cap);
151 extern bool ns_capable(struct user_namespace *ns, int cap);
152 extern bool nsown_capable(int cap);
153-extern bool inode_capable(const struct inode *inode, int cap);
154+extern bool capable_wrt_inode_uidgid(const struct inode *inode, int cap);
155 extern bool file_ns_capable(const struct file *file, struct user_namespace *ns, int cap);
156
157 /* audit system wants to get cap info from files as well */
158diff --git a/kernel/capability.c b/kernel/capability.c
159index f6c2ce5..d52eecc 100644
160--- a/kernel/capability.c
161+++ b/kernel/capability.c
162@@ -445,22 +445,18 @@ bool nsown_capable(int cap)
163 }
164
165 /**
166- * inode_capable - Check superior capability over inode
167+ * capable_wrt_inode_uidgid - Check nsown_capable and uid and gid mapped
168 * @inode: The inode in question
169 * @cap: The capability in question
170 *
171- * Return true if the current task has the given superior capability
172- * targeted at it's own user namespace and that the given inode is owned
173- * by the current user namespace or a child namespace.
174- *
175- * Currently we check to see if an inode is owned by the current
176- * user namespace by seeing if the inode's owner maps into the
177- * current user namespace.
178- *
179+ * Return true if the current task has the given capability targeted at
180+ * its own user namespace and that the given inode's uid and gid are
181+ * mapped into the current user namespace.
182 */
183-bool inode_capable(const struct inode *inode, int cap)
184+bool capable_wrt_inode_uidgid(const struct inode *inode, int cap)
185 {
186 struct user_namespace *ns = current_user_ns();
187
188- return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
189+ return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid) &&
190+ kgid_has_mapping(ns, inode->i_gid);
191 }
192--
1931.9.1
194
diff --git a/recipes-kernel/linux/linux-qoriq-sdk.bbappend b/recipes-kernel/linux/linux-qoriq-sdk.bbappend
index 8a23881..dc9fec8 100644
--- a/recipes-kernel/linux/linux-qoriq-sdk.bbappend
+++ b/recipes-kernel/linux/linux-qoriq-sdk.bbappend
@@ -58,6 +58,7 @@ SRC_URI += "file://add-no-error-uninitialized.patch \
58 file://0001-shmem-CVE-2014-4171.patch \ 58 file://0001-shmem-CVE-2014-4171.patch \
59 file://0002-shmem-CVE-2014-4171.patch \ 59 file://0002-shmem-CVE-2014-4171.patch \
60 file://0003-shmem-CVE-2014-4171.patch \ 60 file://0003-shmem-CVE-2014-4171.patch \
61 file://fs-CVE-2014-4014.patch \
61 " 62 "
62 63
63SRC_URI_append_p2041rdb = " \ 64SRC_URI_append_p2041rdb = " \