aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/capability.h
diff options
context:
space:
mode:
authorSerge E. Hallyn <serge@hallyn.com>2011-03-23 19:43:17 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2011-03-23 22:47:02 -0400
commit3486740a4f32a6a466f5ac931654d154790ba648 (patch)
treeac5d968a66057fa84933b8f89fd3e916270dffed /include/linux/capability.h
parent59607db367c57f515183cb203642291bb14d9c40 (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/capability.h')
-rw-r--r--include/linux/capability.h36
1 files changed, 28 insertions, 8 deletions
diff --git a/include/linux/capability.h b/include/linux/capability.h
index fb16a3699b99..7c9c82903012 100644
--- a/include/linux/capability.h
+++ b/include/linux/capability.h
@@ -368,6 +368,17 @@ struct cpu_vfs_cap_data {
368 368
369#ifdef __KERNEL__ 369#ifdef __KERNEL__
370 370
371struct dentry;
372struct user_namespace;
373
374extern struct user_namespace init_user_ns;
375
376struct user_namespace *current_user_ns(void);
377
378extern const kernel_cap_t __cap_empty_set;
379extern const kernel_cap_t __cap_full_set;
380extern const kernel_cap_t __cap_init_eff_set;
381
371/* 382/*
372 * Internal kernel functions only 383 * Internal kernel functions only
373 */ 384 */
@@ -530,10 +541,6 @@ static inline kernel_cap_t cap_raise_nfsd_set(const kernel_cap_t a,
530 cap_intersect(permitted, __cap_nfsd_set)); 541 cap_intersect(permitted, __cap_nfsd_set));
531} 542}
532 543
533extern const kernel_cap_t __cap_empty_set;
534extern const kernel_cap_t __cap_full_set;
535extern const kernel_cap_t __cap_init_eff_set;
536
537/** 544/**
538 * has_capability - Determine if a task has a superior capability available 545 * has_capability - Determine if a task has a superior capability available
539 * @t: The task in question 546 * @t: The task in question
@@ -544,7 +551,7 @@ extern const kernel_cap_t __cap_init_eff_set;
544 * 551 *
545 * Note that this does not set PF_SUPERPRIV on the task. 552 * Note that this does not set PF_SUPERPRIV on the task.
546 */ 553 */
547#define has_capability(t, cap) (security_real_capable((t), (cap)) == 0) 554#define has_capability(t, cap) (security_real_capable((t), &init_user_ns, (cap)) == 0)
548 555
549/** 556/**
550 * has_capability_noaudit - Determine if a task has a superior capability available (unaudited) 557 * has_capability_noaudit - Determine if a task has a superior capability available (unaudited)
@@ -558,12 +565,25 @@ extern const kernel_cap_t __cap_init_eff_set;
558 * Note that this does not set PF_SUPERPRIV on the task. 565 * Note that this does not set PF_SUPERPRIV on the task.
559 */ 566 */
560#define has_capability_noaudit(t, cap) \ 567#define has_capability_noaudit(t, cap) \
561 (security_real_capable_noaudit((t), (cap)) == 0) 568 (security_real_capable_noaudit((t), &init_user_ns, (cap)) == 0)
562 569
563extern int capable(int cap); 570extern bool capable(int cap);
571extern bool ns_capable(struct user_namespace *ns, int cap);
572extern bool task_ns_capable(struct task_struct *t, int cap);
573
574/**
575 * nsown_capable - Check superior capability to one's own user_ns
576 * @cap: The capability in question
577 *
578 * Return true if the current task has the given superior capability
579 * targeted at its own user namespace.
580 */
581static inline bool nsown_capable(int cap)
582{
583 return ns_capable(current_user_ns(), cap);
584}
564 585
565/* audit system wants to get cap info from files as well */ 586/* audit system wants to get cap info from files as well */
566struct dentry;
567extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps); 587extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
568 588
569#endif /* __KERNEL__ */ 589#endif /* __KERNEL__ */