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 /include/linux/security.h | |
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 'include/linux/security.h')
-rw-r--r-- | include/linux/security.h | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/include/linux/security.h b/include/linux/security.h index 56cac520d014..ca02f1716736 100644 --- a/include/linux/security.h +++ b/include/linux/security.h | |||
@@ -47,13 +47,14 @@ | |||
47 | 47 | ||
48 | struct ctl_table; | 48 | struct ctl_table; |
49 | struct audit_krule; | 49 | struct audit_krule; |
50 | struct user_namespace; | ||
50 | 51 | ||
51 | /* | 52 | /* |
52 | * These functions are in security/capability.c and are used | 53 | * These functions are in security/capability.c and are used |
53 | * as the default capabilities functions | 54 | * as the default capabilities functions |
54 | */ | 55 | */ |
55 | extern int cap_capable(struct task_struct *tsk, const struct cred *cred, | 56 | extern int cap_capable(struct task_struct *tsk, const struct cred *cred, |
56 | int cap, int audit); | 57 | struct user_namespace *ns, int cap, int audit); |
57 | extern int cap_settime(const struct timespec *ts, const struct timezone *tz); | 58 | extern int cap_settime(const struct timespec *ts, const struct timezone *tz); |
58 | extern int cap_ptrace_access_check(struct task_struct *child, unsigned int mode); | 59 | extern int cap_ptrace_access_check(struct task_struct *child, unsigned int mode); |
59 | extern int cap_ptrace_traceme(struct task_struct *parent); | 60 | extern int cap_ptrace_traceme(struct task_struct *parent); |
@@ -1262,6 +1263,7 @@ static inline void security_free_mnt_opts(struct security_mnt_opts *opts) | |||
1262 | * credentials. | 1263 | * credentials. |
1263 | * @tsk contains the task_struct for the process. | 1264 | * @tsk contains the task_struct for the process. |
1264 | * @cred contains the credentials to use. | 1265 | * @cred contains the credentials to use. |
1266 | * @ns contains the user namespace we want the capability in | ||
1265 | * @cap contains the capability <include/linux/capability.h>. | 1267 | * @cap contains the capability <include/linux/capability.h>. |
1266 | * @audit: Whether to write an audit message or not | 1268 | * @audit: Whether to write an audit message or not |
1267 | * Return 0 if the capability is granted for @tsk. | 1269 | * Return 0 if the capability is granted for @tsk. |
@@ -1384,7 +1386,7 @@ struct security_operations { | |||
1384 | const kernel_cap_t *inheritable, | 1386 | const kernel_cap_t *inheritable, |
1385 | const kernel_cap_t *permitted); | 1387 | const kernel_cap_t *permitted); |
1386 | int (*capable) (struct task_struct *tsk, const struct cred *cred, | 1388 | int (*capable) (struct task_struct *tsk, const struct cred *cred, |
1387 | int cap, int audit); | 1389 | struct user_namespace *ns, int cap, int audit); |
1388 | int (*quotactl) (int cmds, int type, int id, struct super_block *sb); | 1390 | int (*quotactl) (int cmds, int type, int id, struct super_block *sb); |
1389 | int (*quota_on) (struct dentry *dentry); | 1391 | int (*quota_on) (struct dentry *dentry); |
1390 | int (*syslog) (int type); | 1392 | int (*syslog) (int type); |
@@ -1665,9 +1667,12 @@ int security_capset(struct cred *new, const struct cred *old, | |||
1665 | const kernel_cap_t *effective, | 1667 | const kernel_cap_t *effective, |
1666 | const kernel_cap_t *inheritable, | 1668 | const kernel_cap_t *inheritable, |
1667 | const kernel_cap_t *permitted); | 1669 | const kernel_cap_t *permitted); |
1668 | int security_capable(const struct cred *cred, int cap); | 1670 | int security_capable(struct user_namespace *ns, const struct cred *cred, |
1669 | int security_real_capable(struct task_struct *tsk, int cap); | 1671 | int cap); |
1670 | int security_real_capable_noaudit(struct task_struct *tsk, int cap); | 1672 | int security_real_capable(struct task_struct *tsk, struct user_namespace *ns, |
1673 | int cap); | ||
1674 | int security_real_capable_noaudit(struct task_struct *tsk, | ||
1675 | struct user_namespace *ns, int cap); | ||
1671 | int security_quotactl(int cmds, int type, int id, struct super_block *sb); | 1676 | int security_quotactl(int cmds, int type, int id, struct super_block *sb); |
1672 | int security_quota_on(struct dentry *dentry); | 1677 | int security_quota_on(struct dentry *dentry); |
1673 | int security_syslog(int type); | 1678 | int security_syslog(int type); |
@@ -1860,28 +1865,29 @@ static inline int security_capset(struct cred *new, | |||
1860 | return cap_capset(new, old, effective, inheritable, permitted); | 1865 | return cap_capset(new, old, effective, inheritable, permitted); |
1861 | } | 1866 | } |
1862 | 1867 | ||
1863 | static inline int security_capable(const struct cred *cred, int cap) | 1868 | static inline int security_capable(struct user_namespace *ns, |
1869 | const struct cred *cred, int cap) | ||
1864 | { | 1870 | { |
1865 | return cap_capable(current, cred, cap, SECURITY_CAP_AUDIT); | 1871 | return cap_capable(current, cred, ns, cap, SECURITY_CAP_AUDIT); |
1866 | } | 1872 | } |
1867 | 1873 | ||
1868 | static inline int security_real_capable(struct task_struct *tsk, int cap) | 1874 | static inline int security_real_capable(struct task_struct *tsk, struct user_namespace *ns, int cap) |
1869 | { | 1875 | { |
1870 | int ret; | 1876 | int ret; |
1871 | 1877 | ||
1872 | rcu_read_lock(); | 1878 | rcu_read_lock(); |
1873 | ret = cap_capable(tsk, __task_cred(tsk), cap, SECURITY_CAP_AUDIT); | 1879 | ret = cap_capable(tsk, __task_cred(tsk), ns, cap, SECURITY_CAP_AUDIT); |
1874 | rcu_read_unlock(); | 1880 | rcu_read_unlock(); |
1875 | return ret; | 1881 | return ret; |
1876 | } | 1882 | } |
1877 | 1883 | ||
1878 | static inline | 1884 | static inline |
1879 | int security_real_capable_noaudit(struct task_struct *tsk, int cap) | 1885 | int security_real_capable_noaudit(struct task_struct *tsk, struct user_namespace *ns, int cap) |
1880 | { | 1886 | { |
1881 | int ret; | 1887 | int ret; |
1882 | 1888 | ||
1883 | rcu_read_lock(); | 1889 | rcu_read_lock(); |
1884 | ret = cap_capable(tsk, __task_cred(tsk), cap, | 1890 | ret = cap_capable(tsk, __task_cred(tsk), ns, cap, |
1885 | SECURITY_CAP_NOAUDIT); | 1891 | SECURITY_CAP_NOAUDIT); |
1886 | rcu_read_unlock(); | 1892 | rcu_read_unlock(); |
1887 | return ret; | 1893 | return ret; |