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/selinux | |
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/selinux')
-rw-r--r-- | security/selinux/hooks.c | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c index 6475e1f0223e..c67f863d3546 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c | |||
@@ -79,6 +79,7 @@ | |||
79 | #include <linux/mutex.h> | 79 | #include <linux/mutex.h> |
80 | #include <linux/posix-timers.h> | 80 | #include <linux/posix-timers.h> |
81 | #include <linux/syslog.h> | 81 | #include <linux/syslog.h> |
82 | #include <linux/user_namespace.h> | ||
82 | 83 | ||
83 | #include "avc.h" | 84 | #include "avc.h" |
84 | #include "objsec.h" | 85 | #include "objsec.h" |
@@ -1846,11 +1847,11 @@ static int selinux_capset(struct cred *new, const struct cred *old, | |||
1846 | */ | 1847 | */ |
1847 | 1848 | ||
1848 | static int selinux_capable(struct task_struct *tsk, const struct cred *cred, | 1849 | static int selinux_capable(struct task_struct *tsk, const struct cred *cred, |
1849 | int cap, int audit) | 1850 | struct user_namespace *ns, int cap, int audit) |
1850 | { | 1851 | { |
1851 | int rc; | 1852 | int rc; |
1852 | 1853 | ||
1853 | rc = cap_capable(tsk, cred, cap, audit); | 1854 | rc = cap_capable(tsk, cred, ns, cap, audit); |
1854 | if (rc) | 1855 | if (rc) |
1855 | return rc; | 1856 | return rc; |
1856 | 1857 | ||
@@ -1931,7 +1932,8 @@ static int selinux_vm_enough_memory(struct mm_struct *mm, long pages) | |||
1931 | { | 1932 | { |
1932 | int rc, cap_sys_admin = 0; | 1933 | int rc, cap_sys_admin = 0; |
1933 | 1934 | ||
1934 | rc = selinux_capable(current, current_cred(), CAP_SYS_ADMIN, | 1935 | rc = selinux_capable(current, current_cred(), |
1936 | &init_user_ns, CAP_SYS_ADMIN, | ||
1935 | SECURITY_CAP_NOAUDIT); | 1937 | SECURITY_CAP_NOAUDIT); |
1936 | if (rc == 0) | 1938 | if (rc == 0) |
1937 | cap_sys_admin = 1; | 1939 | cap_sys_admin = 1; |
@@ -2834,7 +2836,8 @@ static int selinux_inode_getsecurity(const struct inode *inode, const char *name | |||
2834 | * and lack of permission just means that we fall back to the | 2836 | * and lack of permission just means that we fall back to the |
2835 | * in-core context value, not a denial. | 2837 | * in-core context value, not a denial. |
2836 | */ | 2838 | */ |
2837 | error = selinux_capable(current, current_cred(), CAP_MAC_ADMIN, | 2839 | error = selinux_capable(current, current_cred(), |
2840 | &init_user_ns, CAP_MAC_ADMIN, | ||
2838 | SECURITY_CAP_NOAUDIT); | 2841 | SECURITY_CAP_NOAUDIT); |
2839 | if (!error) | 2842 | if (!error) |
2840 | error = security_sid_to_context_force(isec->sid, &context, | 2843 | error = security_sid_to_context_force(isec->sid, &context, |
@@ -2968,7 +2971,7 @@ static int selinux_file_ioctl(struct file *file, unsigned int cmd, | |||
2968 | case KDSKBENT: | 2971 | case KDSKBENT: |
2969 | case KDSKBSENT: | 2972 | case KDSKBSENT: |
2970 | error = task_has_capability(current, cred, CAP_SYS_TTY_CONFIG, | 2973 | error = task_has_capability(current, cred, CAP_SYS_TTY_CONFIG, |
2971 | SECURITY_CAP_AUDIT); | 2974 | SECURITY_CAP_AUDIT); |
2972 | break; | 2975 | break; |
2973 | 2976 | ||
2974 | /* default case assumes that the command will go | 2977 | /* default case assumes that the command will go |