aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/capability.c
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/capability.c')
-rw-r--r--kernel/capability.c42
1 files changed, 37 insertions, 5 deletions
diff --git a/kernel/capability.c b/kernel/capability.c
index 9e9385f132c..0a3d2c863a1 100644
--- a/kernel/capability.c
+++ b/kernel/capability.c
@@ -14,6 +14,7 @@
14#include <linux/security.h> 14#include <linux/security.h>
15#include <linux/syscalls.h> 15#include <linux/syscalls.h>
16#include <linux/pid_namespace.h> 16#include <linux/pid_namespace.h>
17#include <linux/user_namespace.h>
17#include <asm/uaccess.h> 18#include <asm/uaccess.h>
18 19
19/* 20/*
@@ -299,17 +300,48 @@ error:
299 * This sets PF_SUPERPRIV on the task if the capability is available on the 300 * This sets PF_SUPERPRIV on the task if the capability is available on the
300 * assumption that it's about to be used. 301 * assumption that it's about to be used.
301 */ 302 */
302int capable(int cap) 303bool capable(int cap)
304{
305 return ns_capable(&init_user_ns, cap);
306}
307EXPORT_SYMBOL(capable);
308
309/**
310 * ns_capable - Determine if the current task has a superior capability in effect
311 * @ns: The usernamespace we want the capability in
312 * @cap: The capability to be tested for
313 *
314 * Return true if the current task has the given superior capability currently
315 * available for use, false if not.
316 *
317 * This sets PF_SUPERPRIV on the task if the capability is available on the
318 * assumption that it's about to be used.
319 */
320bool ns_capable(struct user_namespace *ns, int cap)
303{ 321{
304 if (unlikely(!cap_valid(cap))) { 322 if (unlikely(!cap_valid(cap))) {
305 printk(KERN_CRIT "capable() called with invalid cap=%u\n", cap); 323 printk(KERN_CRIT "capable() called with invalid cap=%u\n", cap);
306 BUG(); 324 BUG();
307 } 325 }
308 326
309 if (security_capable(current_cred(), cap) == 0) { 327 if (security_capable(ns, current_cred(), cap) == 0) {
310 current->flags |= PF_SUPERPRIV; 328 current->flags |= PF_SUPERPRIV;
311 return 1; 329 return true;
312 } 330 }
313 return 0; 331 return false;
314} 332}
315EXPORT_SYMBOL(capable); 333EXPORT_SYMBOL(ns_capable);
334
335/**
336 * task_ns_capable - Determine whether current task has a superior
337 * capability targeted at a specific task's user namespace.
338 * @t: The task whose user namespace is targeted.
339 * @cap: The capability in question.
340 *
341 * Return true if it does, false otherwise.
342 */
343bool task_ns_capable(struct task_struct *t, int cap)
344{
345 return ns_capable(task_cred_xxx(t, user)->user_ns, cap);
346}
347EXPORT_SYMBOL(task_ns_capable);