summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSona Sarmadi <sona.sarmadi@enea.com>2016-02-08 14:29:42 +0100
committerSona Sarmadi <sona.sarmadi@enea.com>2016-02-09 08:34:01 +0100
commitfa34e4b39a0d27086a2e797b637d8a1b1df89784 (patch)
tree59325a463785c67026caa237cc855cb9cdd4b5b4
parent2e775f75b52ecd963b842f4b91469f2851a6086b (diff)
downloadmeta-fsl-ppc-fa34e4b39a0d27086a2e797b637d8a1b1df89784.tar.gz
kernel/fs-userns: CVE-2014-4014
Change inode_capable to capable_wrt_inode_uidgid Fixes privileges escalation in Linux kernel built with the user namespaces(CONFIG_USER_NS). References: https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2014-4014 http://www.openwall.com/lists/oss-security/2014/06/10/4 Upstream patch: https://git.kernel.org/cgit/linux/kernel/git/stable/linux-stable.git/ patch/?id= 2246a472bce19c0d373fb5488a0e612e3328ce0a Signed-off-by: Sona Sarmadi <sona.sarmadi@enea.com>
-rw-r--r--recipes-kernel/linux/files/fs-userns-CVE-2014-4014.patch211
-rw-r--r--recipes-kernel/linux/linux-qoriq_3.12.bb1
2 files changed, 212 insertions, 0 deletions
diff --git a/recipes-kernel/linux/files/fs-userns-CVE-2014-4014.patch b/recipes-kernel/linux/files/fs-userns-CVE-2014-4014.patch
new file mode 100644
index 0000000..d6e4132
--- /dev/null
+++ b/recipes-kernel/linux/files/fs-userns-CVE-2014-4014.patch
@@ -0,0 +1,211 @@
1From 2246a472bce19c0d373fb5488a0e612e3328ce0a Mon Sep 17 00:00:00 2001
2From: Andy Lutomirski <luto@amacapital.net>
3Date: Tue, 10 Jun 2014 12:45:42 -0700
4Subject: 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.
17
18Upstream-Status: Backport
19
20Cc: Theodore Ts'o <tytso@mit.edu>
21Cc: Serge Hallyn <serge.hallyn@ubuntu.com>
22Cc: "Eric W. Biederman" <ebiederm@xmission.com>
23Cc: Dave Chinner <david@fromorbit.com>
24Signed-off-by: Andy Lutomirski <luto@amacapital.net>
25Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
26Signed-off-by: Jiri Slaby <jslaby@suse.cz>
27Signed-off-by: Sona Sarmadi <sona.sarmadi@enea.com>
28---
29 fs/attr.c | 8 ++++----
30 fs/inode.c | 10 +++++++---
31 fs/namei.c | 11 ++++++-----
32 fs/xfs/xfs_ioctl.c | 2 +-
33 include/linux/capability.h | 2 +-
34 kernel/capability.c | 20 ++++++++------------
35 6 files changed, 27 insertions(+), 26 deletions(-)
36
37diff --git a/fs/attr.c b/fs/attr.c
38index 8dd5825..66fa625 100644
39--- a/fs/attr.c
40+++ b/fs/attr.c
41@@ -50,14 +50,14 @@ int inode_change_ok(const struct inode *inode, struct iattr *attr)
42 if ((ia_valid & ATTR_UID) &&
43 (!uid_eq(current_fsuid(), inode->i_uid) ||
44 !uid_eq(attr->ia_uid, inode->i_uid)) &&
45- !inode_capable(inode, CAP_CHOWN))
46+ !capable_wrt_inode_uidgid(inode, CAP_CHOWN))
47 return -EPERM;
48
49 /* Make sure caller can chgrp. */
50 if ((ia_valid & ATTR_GID) &&
51 (!uid_eq(current_fsuid(), inode->i_uid) ||
52 (!in_group_p(attr->ia_gid) && !gid_eq(attr->ia_gid, inode->i_gid))) &&
53- !inode_capable(inode, CAP_CHOWN))
54+ !capable_wrt_inode_uidgid(inode, CAP_CHOWN))
55 return -EPERM;
56
57 /* Make sure a caller can chmod. */
58@@ -67,7 +67,7 @@ int inode_change_ok(const struct inode *inode, struct iattr *attr)
59 /* Also check the setgid bit! */
60 if (!in_group_p((ia_valid & ATTR_GID) ? attr->ia_gid :
61 inode->i_gid) &&
62- !inode_capable(inode, CAP_FSETID))
63+ !capable_wrt_inode_uidgid(inode, CAP_FSETID))
64 attr->ia_mode &= ~S_ISGID;
65 }
66
67@@ -160,7 +160,7 @@ void setattr_copy(struct inode *inode, const struct iattr *attr)
68 umode_t mode = attr->ia_mode;
69
70 if (!in_group_p(inode->i_gid) &&
71- !inode_capable(inode, CAP_FSETID))
72+ !capable_wrt_inode_uidgid(inode, CAP_FSETID))
73 mode &= ~S_ISGID;
74 inode->i_mode = mode;
75 }
76diff --git a/fs/inode.c b/fs/inode.c
77index b33ba8e..1e6e846 100644
78--- a/fs/inode.c
79+++ b/fs/inode.c
80@@ -1808,14 +1808,18 @@ EXPORT_SYMBOL(inode_init_owner);
81 * inode_owner_or_capable - check current task permissions to inode
82 * @inode: inode being checked
83 *
84- * Return true if current either has CAP_FOWNER to the inode, or
85- * owns the file.
86+ * Return true if current either has CAP_FOWNER in a namespace with the
87+ * inode owner uid mapped, or owns the file.
88 */
89 bool inode_owner_or_capable(const struct inode *inode)
90 {
91+ struct user_namespace *ns;
92+
93 if (uid_eq(current_fsuid(), inode->i_uid))
94 return true;
95- if (inode_capable(inode, CAP_FOWNER))
96+
97+ ns = current_user_ns();
98+ if (ns_capable(ns, CAP_FOWNER) && kuid_has_mapping(ns, inode->i_uid))
99 return true;
100 return false;
101 }
102diff --git a/fs/namei.c b/fs/namei.c
103index 187cacf..338d08b 100644
104--- a/fs/namei.c
105+++ b/fs/namei.c
106@@ -321,10 +321,11 @@ int generic_permission(struct inode *inode, int mask)
107
108 if (S_ISDIR(inode->i_mode)) {
109 /* DACs are overridable for directories */
110- if (inode_capable(inode, CAP_DAC_OVERRIDE))
111+ if (capable_wrt_inode_uidgid(inode, CAP_DAC_OVERRIDE))
112 return 0;
113 if (!(mask & MAY_WRITE))
114- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
115+ if (capable_wrt_inode_uidgid(inode,
116+ CAP_DAC_READ_SEARCH))
117 return 0;
118 return -EACCES;
119 }
120@@ -334,7 +335,7 @@ int generic_permission(struct inode *inode, int mask)
121 * at least one exec bit set.
122 */
123 if (!(mask & MAY_EXEC) || (inode->i_mode & S_IXUGO))
124- if (inode_capable(inode, CAP_DAC_OVERRIDE))
125+ if (capable_wrt_inode_uidgid(inode, CAP_DAC_OVERRIDE))
126 return 0;
127
128 /*
129@@ -342,7 +343,7 @@ int generic_permission(struct inode *inode, int mask)
130 */
131 mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
132 if (mask == MAY_READ)
133- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
134+ if (capable_wrt_inode_uidgid(inode, CAP_DAC_READ_SEARCH))
135 return 0;
136
137 return -EACCES;
138@@ -2404,7 +2405,7 @@ static inline int check_sticky(struct inode *dir, struct inode *inode)
139 return 0;
140 if (uid_eq(dir->i_uid, fsuid))
141 return 0;
142- return !inode_capable(inode, CAP_FOWNER);
143+ return !capable_wrt_inode_uidgid(inode, CAP_FOWNER);
144 }
145
146 /*
147diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
148index 8c8ef24..52b5375 100644
149--- a/fs/xfs/xfs_ioctl.c
150+++ b/fs/xfs/xfs_ioctl.c
151@@ -1133,7 +1133,7 @@ xfs_ioctl_setattr(
152 * cleared upon successful return from chown()
153 */
154 if ((ip->i_d.di_mode & (S_ISUID|S_ISGID)) &&
155- !inode_capable(VFS_I(ip), CAP_FSETID))
156+ !capable_wrt_inode_uidgid(VFS_I(ip), CAP_FSETID))
157 ip->i_d.di_mode &= ~(S_ISUID|S_ISGID);
158
159 /*
160diff --git a/include/linux/capability.h b/include/linux/capability.h
161index a6ee1f9..84b13ad 100644
162--- a/include/linux/capability.h
163+++ b/include/linux/capability.h
164@@ -210,7 +210,7 @@ extern bool has_ns_capability_noaudit(struct task_struct *t,
165 struct user_namespace *ns, int cap);
166 extern bool capable(int cap);
167 extern bool ns_capable(struct user_namespace *ns, int cap);
168-extern bool inode_capable(const struct inode *inode, int cap);
169+extern bool capable_wrt_inode_uidgid(const struct inode *inode, int cap);
170 extern bool file_ns_capable(const struct file *file, struct user_namespace *ns, int cap);
171
172 /* audit system wants to get cap info from files as well */
173diff --git a/kernel/capability.c b/kernel/capability.c
174index 4e66bf9..788653b 100644
175--- a/kernel/capability.c
176+++ b/kernel/capability.c
177@@ -433,23 +433,19 @@ bool capable(int cap)
178 EXPORT_SYMBOL(capable);
179
180 /**
181- * inode_capable - Check superior capability over inode
182+ * capable_wrt_inode_uidgid - Check nsown_capable and uid and gid mapped
183 * @inode: The inode in question
184 * @cap: The capability in question
185 *
186- * Return true if the current task has the given superior capability
187- * targeted at it's own user namespace and that the given inode is owned
188- * by the current user namespace or a child namespace.
189- *
190- * Currently we check to see if an inode is owned by the current
191- * user namespace by seeing if the inode's owner maps into the
192- * current user namespace.
193- *
194+ * Return true if the current task has the given capability targeted at
195+ * its own user namespace and that the given inode's uid and gid are
196+ * mapped into the current user namespace.
197 */
198-bool inode_capable(const struct inode *inode, int cap)
199+bool capable_wrt_inode_uidgid(const struct inode *inode, int cap)
200 {
201 struct user_namespace *ns = current_user_ns();
202
203- return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
204+ return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid) &&
205+ kgid_has_mapping(ns, inode->i_gid);
206 }
207-EXPORT_SYMBOL(inode_capable);
208+EXPORT_SYMBOL(capable_wrt_inode_uidgid);
209--
210cgit v0.11.2
211
diff --git a/recipes-kernel/linux/linux-qoriq_3.12.bb b/recipes-kernel/linux/linux-qoriq_3.12.bb
index 262a6c8..bcf2930 100644
--- a/recipes-kernel/linux/linux-qoriq_3.12.bb
+++ b/recipes-kernel/linux/linux-qoriq_3.12.bb
@@ -35,6 +35,7 @@ SRC_URI = "git://git.freescale.com/ppc/sdk/linux.git;nobranch=1 \
35 file://udp-CVE-2015-5364_CVE-2015-5366.patch \ 35 file://udp-CVE-2015-5364_CVE-2015-5366.patch \
36 file://net-CVE-2015-2041.patch \ 36 file://net-CVE-2015-2041.patch \
37 file://media-CVE-2014-1739.patch \ 37 file://media-CVE-2014-1739.patch \
38 file://fs-userns-CVE-2014-4014.patch \
38" 39"
39SRCREV = "6619b8b55796cdf0cec04b66a71288edd3057229" 40SRCREV = "6619b8b55796cdf0cec04b66a71288edd3057229"
40 41