diff options
author | Serge E. Hallyn <serge@hallyn.com> | 2011-03-23 19:43:17 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2011-03-23 22:47:02 -0400 |
commit | 3486740a4f32a6a466f5ac931654d154790ba648 (patch) | |
tree | ac5d968a66057fa84933b8f89fd3e916270dffed /security/security.c | |
parent | 59607db367c57f515183cb203642291bb14d9c40 (diff) |
userns: security: make capabilities relative to the user namespace
- Introduce ns_capable to test for a capability in a non-default
user namespace.
- Teach cap_capable to handle capabilities in a non-default
user namespace.
The motivation is to get to the unprivileged creation of new
namespaces. It looks like this gets us 90% of the way there, with
only potential uid confusion issues left.
I still need to handle getting all caps after creation but otherwise I
think I have a good starter patch that achieves all of your goals.
Changelog:
11/05/2010: [serge] add apparmor
12/14/2010: [serge] fix capabilities to created user namespaces
Without this, if user serge creates a user_ns, he won't have
capabilities to the user_ns he created. THis is because we
were first checking whether his effective caps had the caps
he needed and returning -EPERM if not, and THEN checking whether
he was the creator. Reverse those checks.
12/16/2010: [serge] security_real_capable needs ns argument in !security case
01/11/2011: [serge] add task_ns_capable helper
01/11/2011: [serge] add nsown_capable() helper per Bastian Blank suggestion
02/16/2011: [serge] fix a logic bug: the root user is always creator of
init_user_ns, but should not always have capabilities to
it! Fix the check in cap_capable().
02/21/2011: Add the required user_ns parameter to security_capable,
fixing a compile failure.
02/23/2011: Convert some macros to functions as per akpm comments. Some
couldn't be converted because we can't easily forward-declare
them (they are inline if !SECURITY, extern if SECURITY). Add
a current_user_ns function so we can use it in capability.h
without #including cred.h. Move all forward declarations
together to the top of the #ifdef __KERNEL__ section, and use
kernel-doc format.
02/23/2011: Per dhowells, clean up comment in cap_capable().
02/23/2011: Per akpm, remove unreachable 'return -EPERM' in cap_capable.
(Original written and signed off by Eric; latest, modified version
acked by him)
[akpm@linux-foundation.org: fix build]
[akpm@linux-foundation.org: export current_user_ns() for ecryptfs]
[serge.hallyn@canonical.com: remove unneeded extra argument in selinux's task_has_capability]
Signed-off-by: Eric W. Biederman <ebiederm@xmission.com>
Signed-off-by: Serge E. Hallyn <serge.hallyn@canonical.com>
Acked-by: "Eric W. Biederman" <ebiederm@xmission.com>
Acked-by: Daniel Lezcano <daniel.lezcano@free.fr>
Acked-by: David Howells <dhowells@redhat.com>
Cc: James Morris <jmorris@namei.org>
Signed-off-by: Serge E. Hallyn <serge.hallyn@canonical.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'security/security.c')
-rw-r--r-- | security/security.c | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/security/security.c b/security/security.c index 9187665a3fdd..101142369db4 100644 --- a/security/security.c +++ b/security/security.c | |||
@@ -154,29 +154,33 @@ int security_capset(struct cred *new, const struct cred *old, | |||
154 | effective, inheritable, permitted); | 154 | effective, inheritable, permitted); |
155 | } | 155 | } |
156 | 156 | ||
157 | int security_capable(const struct cred *cred, int cap) | 157 | int security_capable(struct user_namespace *ns, const struct cred *cred, |
158 | int cap) | ||
158 | { | 159 | { |
159 | return security_ops->capable(current, cred, cap, SECURITY_CAP_AUDIT); | 160 | return security_ops->capable(current, cred, ns, cap, |
161 | SECURITY_CAP_AUDIT); | ||
160 | } | 162 | } |
161 | 163 | ||
162 | int security_real_capable(struct task_struct *tsk, int cap) | 164 | int security_real_capable(struct task_struct *tsk, struct user_namespace *ns, |
165 | int cap) | ||
163 | { | 166 | { |
164 | const struct cred *cred; | 167 | const struct cred *cred; |
165 | int ret; | 168 | int ret; |
166 | 169 | ||
167 | cred = get_task_cred(tsk); | 170 | cred = get_task_cred(tsk); |
168 | ret = security_ops->capable(tsk, cred, cap, SECURITY_CAP_AUDIT); | 171 | ret = security_ops->capable(tsk, cred, ns, cap, SECURITY_CAP_AUDIT); |
169 | put_cred(cred); | 172 | put_cred(cred); |
170 | return ret; | 173 | return ret; |
171 | } | 174 | } |
172 | 175 | ||
173 | int security_real_capable_noaudit(struct task_struct *tsk, int cap) | 176 | int security_real_capable_noaudit(struct task_struct *tsk, |
177 | struct user_namespace *ns, int cap) | ||
174 | { | 178 | { |
175 | const struct cred *cred; | 179 | const struct cred *cred; |
176 | int ret; | 180 | int ret; |
177 | 181 | ||
178 | cred = get_task_cred(tsk); | 182 | cred = get_task_cred(tsk); |
179 | ret = security_ops->capable(tsk, cred, cap, SECURITY_CAP_NOAUDIT); | 183 | ret = security_ops->capable(tsk, cred, ns, cap, SECURITY_CAP_NOAUDIT); |
180 | put_cred(cred); | 184 | put_cred(cred); |
181 | return ret; | 185 | return ret; |
182 | } | 186 | } |