diff options
author | Andrew G. Morgan <morgan@kernel.org> | 2008-05-28 01:05:17 -0400 |
---|---|---|
committer | Chris Wright <chrisw@sous-sol.org> | 2008-05-31 19:36:16 -0400 |
commit | ca05a99a54db1db5bca72eccb5866d2a86f8517f (patch) | |
tree | b39fba6604da4b4f77103d2769bb783118b9b508 /kernel | |
parent | cc94bc37d5e02aaf8a6409a28e3c62bbd479b9a8 (diff) |
capabilities: remain source compatible with 32-bit raw legacy capability support.
Source code out there hard-codes a notion of what the
_LINUX_CAPABILITY_VERSION #define means in terms of the semantics of the
raw capability system calls capget() and capset(). Its unfortunate, but
true.
Since the confusing header file has been in a released kernel, there is
software that is erroneously using 64-bit capabilities with the semantics
of 32-bit compatibilities. These recently compiled programs may suffer
corruption of their memory when sys_getcap() overwrites more memory than
they are coded to expect, and the raising of added capabilities when using
sys_capset().
As such, this patch does a number of things to clean up the situation
for all. It
1. forces the _LINUX_CAPABILITY_VERSION define to always retain its
legacy value.
2. adopts a new #define strategy for the kernel's internal
implementation of the preferred magic.
3. deprecates v2 capability magic in favor of a new (v3) magic
number. The functionality of v3 is entirely equivalent to v2,
the only difference being that the v2 magic causes the kernel
to log a "deprecated" warning so the admin can find applications
that may be using v2 inappropriately.
[User space code continues to be encouraged to use the libcap API which
protects the application from details like this. libcap-2.10 is the first
to support v3 capabilities.]
Fixes issue reported in https://bugzilla.redhat.com/show_bug.cgi?id=447518.
Thanks to Bojan Smojver for the report.
[akpm@linux-foundation.org: s/depreciate/deprecate/g]
[akpm@linux-foundation.org: be robust about put_user size]
[akpm@linux-foundation.org: coding-style fixes]
Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
Cc: Serge E. Hallyn <serue@us.ibm.com>
Cc: Bojan Smojver <bojan@rexursive.com>
Cc: stable@kernel.org
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Chris Wright <chrisw@sous-sol.org>
Diffstat (limited to 'kernel')
-rw-r--r-- | kernel/capability.c | 111 |
1 files changed, 73 insertions, 38 deletions
diff --git a/kernel/capability.c b/kernel/capability.c index 39e8193b41ea..cfbe44299488 100644 --- a/kernel/capability.c +++ b/kernel/capability.c | |||
@@ -53,6 +53,69 @@ static void warn_legacy_capability_use(void) | |||
53 | } | 53 | } |
54 | 54 | ||
55 | /* | 55 | /* |
56 | * Version 2 capabilities worked fine, but the linux/capability.h file | ||
57 | * that accompanied their introduction encouraged their use without | ||
58 | * the necessary user-space source code changes. As such, we have | ||
59 | * created a version 3 with equivalent functionality to version 2, but | ||
60 | * with a header change to protect legacy source code from using | ||
61 | * version 2 when it wanted to use version 1. If your system has code | ||
62 | * that trips the following warning, it is using version 2 specific | ||
63 | * capabilities and may be doing so insecurely. | ||
64 | * | ||
65 | * The remedy is to either upgrade your version of libcap (to 2.10+, | ||
66 | * if the application is linked against it), or recompile your | ||
67 | * application with modern kernel headers and this warning will go | ||
68 | * away. | ||
69 | */ | ||
70 | |||
71 | static void warn_deprecated_v2(void) | ||
72 | { | ||
73 | static int warned; | ||
74 | |||
75 | if (!warned) { | ||
76 | char name[sizeof(current->comm)]; | ||
77 | |||
78 | printk(KERN_INFO "warning: `%s' uses deprecated v2" | ||
79 | " capabilities in a way that may be insecure.\n", | ||
80 | get_task_comm(name, current)); | ||
81 | warned = 1; | ||
82 | } | ||
83 | } | ||
84 | |||
85 | /* | ||
86 | * Version check. Return the number of u32s in each capability flag | ||
87 | * array, or a negative value on error. | ||
88 | */ | ||
89 | static int cap_validate_magic(cap_user_header_t header, unsigned *tocopy) | ||
90 | { | ||
91 | __u32 version; | ||
92 | |||
93 | if (get_user(version, &header->version)) | ||
94 | return -EFAULT; | ||
95 | |||
96 | switch (version) { | ||
97 | case _LINUX_CAPABILITY_VERSION_1: | ||
98 | warn_legacy_capability_use(); | ||
99 | *tocopy = _LINUX_CAPABILITY_U32S_1; | ||
100 | break; | ||
101 | case _LINUX_CAPABILITY_VERSION_2: | ||
102 | warn_deprecated_v2(); | ||
103 | /* | ||
104 | * fall through - v3 is otherwise equivalent to v2. | ||
105 | */ | ||
106 | case _LINUX_CAPABILITY_VERSION_3: | ||
107 | *tocopy = _LINUX_CAPABILITY_U32S_3; | ||
108 | break; | ||
109 | default: | ||
110 | if (put_user((u32)_KERNEL_CAPABILITY_VERSION, &header->version)) | ||
111 | return -EFAULT; | ||
112 | return -EINVAL; | ||
113 | } | ||
114 | |||
115 | return 0; | ||
116 | } | ||
117 | |||
118 | /* | ||
56 | * For sys_getproccap() and sys_setproccap(), any of the three | 119 | * For sys_getproccap() and sys_setproccap(), any of the three |
57 | * capability set pointers may be NULL -- indicating that that set is | 120 | * capability set pointers may be NULL -- indicating that that set is |
58 | * uninteresting and/or not to be changed. | 121 | * uninteresting and/or not to be changed. |
@@ -71,27 +134,13 @@ asmlinkage long sys_capget(cap_user_header_t header, cap_user_data_t dataptr) | |||
71 | { | 134 | { |
72 | int ret = 0; | 135 | int ret = 0; |
73 | pid_t pid; | 136 | pid_t pid; |
74 | __u32 version; | ||
75 | struct task_struct *target; | 137 | struct task_struct *target; |
76 | unsigned tocopy; | 138 | unsigned tocopy; |
77 | kernel_cap_t pE, pI, pP; | 139 | kernel_cap_t pE, pI, pP; |
78 | 140 | ||
79 | if (get_user(version, &header->version)) | 141 | ret = cap_validate_magic(header, &tocopy); |
80 | return -EFAULT; | 142 | if (ret != 0) |
81 | 143 | return ret; | |
82 | switch (version) { | ||
83 | case _LINUX_CAPABILITY_VERSION_1: | ||
84 | warn_legacy_capability_use(); | ||
85 | tocopy = _LINUX_CAPABILITY_U32S_1; | ||
86 | break; | ||
87 | case _LINUX_CAPABILITY_VERSION_2: | ||
88 | tocopy = _LINUX_CAPABILITY_U32S_2; | ||
89 | break; | ||
90 | default: | ||
91 | if (put_user(_LINUX_CAPABILITY_VERSION, &header->version)) | ||
92 | return -EFAULT; | ||
93 | return -EINVAL; | ||
94 | } | ||
95 | 144 | ||
96 | if (get_user(pid, &header->pid)) | 145 | if (get_user(pid, &header->pid)) |
97 | return -EFAULT; | 146 | return -EFAULT; |
@@ -118,7 +167,7 @@ out: | |||
118 | spin_unlock(&task_capability_lock); | 167 | spin_unlock(&task_capability_lock); |
119 | 168 | ||
120 | if (!ret) { | 169 | if (!ret) { |
121 | struct __user_cap_data_struct kdata[_LINUX_CAPABILITY_U32S]; | 170 | struct __user_cap_data_struct kdata[_KERNEL_CAPABILITY_U32S]; |
122 | unsigned i; | 171 | unsigned i; |
123 | 172 | ||
124 | for (i = 0; i < tocopy; i++) { | 173 | for (i = 0; i < tocopy; i++) { |
@@ -128,7 +177,7 @@ out: | |||
128 | } | 177 | } |
129 | 178 | ||
130 | /* | 179 | /* |
131 | * Note, in the case, tocopy < _LINUX_CAPABILITY_U32S, | 180 | * Note, in the case, tocopy < _KERNEL_CAPABILITY_U32S, |
132 | * we silently drop the upper capabilities here. This | 181 | * we silently drop the upper capabilities here. This |
133 | * has the effect of making older libcap | 182 | * has the effect of making older libcap |
134 | * implementations implicitly drop upper capability | 183 | * implementations implicitly drop upper capability |
@@ -240,30 +289,16 @@ static inline int cap_set_all(kernel_cap_t *effective, | |||
240 | */ | 289 | */ |
241 | asmlinkage long sys_capset(cap_user_header_t header, const cap_user_data_t data) | 290 | asmlinkage long sys_capset(cap_user_header_t header, const cap_user_data_t data) |
242 | { | 291 | { |
243 | struct __user_cap_data_struct kdata[_LINUX_CAPABILITY_U32S]; | 292 | struct __user_cap_data_struct kdata[_KERNEL_CAPABILITY_U32S]; |
244 | unsigned i, tocopy; | 293 | unsigned i, tocopy; |
245 | kernel_cap_t inheritable, permitted, effective; | 294 | kernel_cap_t inheritable, permitted, effective; |
246 | __u32 version; | ||
247 | struct task_struct *target; | 295 | struct task_struct *target; |
248 | int ret; | 296 | int ret; |
249 | pid_t pid; | 297 | pid_t pid; |
250 | 298 | ||
251 | if (get_user(version, &header->version)) | 299 | ret = cap_validate_magic(header, &tocopy); |
252 | return -EFAULT; | 300 | if (ret != 0) |
253 | 301 | return ret; | |
254 | switch (version) { | ||
255 | case _LINUX_CAPABILITY_VERSION_1: | ||
256 | warn_legacy_capability_use(); | ||
257 | tocopy = _LINUX_CAPABILITY_U32S_1; | ||
258 | break; | ||
259 | case _LINUX_CAPABILITY_VERSION_2: | ||
260 | tocopy = _LINUX_CAPABILITY_U32S_2; | ||
261 | break; | ||
262 | default: | ||
263 | if (put_user(_LINUX_CAPABILITY_VERSION, &header->version)) | ||
264 | return -EFAULT; | ||
265 | return -EINVAL; | ||
266 | } | ||
267 | 302 | ||
268 | if (get_user(pid, &header->pid)) | 303 | if (get_user(pid, &header->pid)) |
269 | return -EFAULT; | 304 | return -EFAULT; |
@@ -281,7 +316,7 @@ asmlinkage long sys_capset(cap_user_header_t header, const cap_user_data_t data) | |||
281 | permitted.cap[i] = kdata[i].permitted; | 316 | permitted.cap[i] = kdata[i].permitted; |
282 | inheritable.cap[i] = kdata[i].inheritable; | 317 | inheritable.cap[i] = kdata[i].inheritable; |
283 | } | 318 | } |
284 | while (i < _LINUX_CAPABILITY_U32S) { | 319 | while (i < _KERNEL_CAPABILITY_U32S) { |
285 | effective.cap[i] = 0; | 320 | effective.cap[i] = 0; |
286 | permitted.cap[i] = 0; | 321 | permitted.cap[i] = 0; |
287 | inheritable.cap[i] = 0; | 322 | inheritable.cap[i] = 0; |