diff options
author | Sona Sarmadi <sona.sarmadi@enea.com> | 2015-02-17 09:50:19 +0100 |
---|---|---|
committer | Tudor Florea <tudor.florea@enea.com> | 2015-07-06 20:27:14 +0200 |
commit | 0efd2da7fc86df00635de10a16b843d142e9044f (patch) | |
tree | 4a9576a057d07907f56577dd76a680ded11f5733 | |
parent | 499ef72deaee9d623eea5afcdb5c7a7793188acf (diff) | |
download | meta-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.patch | 194 | ||||
-rw-r--r-- | recipes-kernel/linux/linux-qoriq-sdk.bbappend | 1 |
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 @@ | |||
1 | From 4f80c6c1825a91cecf3b3bd19c824e768d98fe48 Mon Sep 17 00:00:00 2001 | ||
2 | From: Andy Lutomirski <luto@amacapital.net> | ||
3 | Date: Tue, 10 Jun 2014 12:45:42 -0700 | ||
4 | Subject: [PATCH] fs,userns: Change inode_capable to capable_wrt_inode_uidgid | ||
5 | |||
6 | commit 23adbe12ef7d3d4195e80800ab36b37bee28cd03 upstream. | ||
7 | |||
8 | The kernel has no concept of capabilities with respect to inodes; inodes | ||
9 | exist independently of namespaces. For example, inode_capable(inode, | ||
10 | CAP_LINUX_IMMUTABLE) would be nonsense. | ||
11 | |||
12 | This patch changes inode_capable to check for uid and gid mappings and | ||
13 | renames it to capable_wrt_inode_uidgid, which should make it more | ||
14 | obvious what it does. | ||
15 | |||
16 | Fixes CVE-2014-4014. | ||
17 | Upstream-Status: Backport | ||
18 | |||
19 | Cc: Theodore Ts'o <tytso@mit.edu> | ||
20 | Cc: Serge Hallyn <serge.hallyn@ubuntu.com> | ||
21 | Cc: "Eric W. Biederman" <ebiederm@xmission.com> | ||
22 | Cc: Dave Chinner <david@fromorbit.com> | ||
23 | Signed-off-by: Andy Lutomirski <luto@amacapital.net> | ||
24 | Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> | ||
25 | Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> | ||
26 | Signed-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 | |||
35 | diff --git a/fs/attr.c b/fs/attr.c | ||
36 | index 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 | } | ||
74 | diff --git a/fs/inode.c b/fs/inode.c | ||
75 | index 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 | } | ||
100 | diff --git a/fs/namei.c b/fs/namei.c | ||
101 | index 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 | /* | ||
145 | diff --git a/include/linux/capability.h b/include/linux/capability.h | ||
146 | index 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 */ | ||
158 | diff --git a/kernel/capability.c b/kernel/capability.c | ||
159 | index 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 | -- | ||
193 | 1.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 | ||
63 | SRC_URI_append_p2041rdb = " \ | 64 | SRC_URI_append_p2041rdb = " \ |