Commit f1c84dae0ecc51aa35c81f19a0ebcd6c0921ddcb

Authored by Eric Paris
1 parent d2a7009f0b

capabilities: remove task_ns_* functions

task_ in the front of a function, in the security subsystem anyway, means
to me at least, that we are operating with that task as the subject of the
security decision.  In this case what it means is that we are using current as
the subject but we use the task to get the right namespace.  Who in the world
would ever realize that's what task_ns_capability means just by the name?  This
patch eliminates the task_ns functions entirely and uses the has_ns_capability
function instead.  This means we explicitly open code the ns in question in
the caller.  I think it makes the caller a LOT more clear what is going on.

Signed-off-by: Eric Paris <eparis@redhat.com>
Acked-by: Serge E. Hallyn <serge.hallyn@canonical.com>

Showing 5 changed files with 7 additions and 20 deletions Side-by-side Diff

include/linux/capability.h
... ... @@ -547,7 +547,6 @@
547 547 struct user_namespace *ns, int cap);
548 548 extern bool capable(int cap);
549 549 extern bool ns_capable(struct user_namespace *ns, int cap);
550   -extern bool task_ns_capable(struct task_struct *t, int cap);
551 550 extern bool nsown_capable(int cap);
552 551  
553 552 /* audit system wants to get cap info from files as well */
include/linux/cred.h
... ... @@ -358,10 +358,12 @@
358 358 #define current_security() (current_cred_xxx(security))
359 359  
360 360 #ifdef CONFIG_USER_NS
361   -#define current_user_ns() (current_cred_xxx(user_ns))
  361 +#define current_user_ns() (current_cred_xxx(user_ns))
  362 +#define task_user_ns(task) (task_cred_xxx((task), user_ns))
362 363 #else
363 364 extern struct user_namespace init_user_ns;
364   -#define current_user_ns() (&init_user_ns)
  365 +#define current_user_ns() (&init_user_ns)
  366 +#define task_user_ns(task) (&init_user_ns)
365 367 #endif
366 368  
367 369  
... ... @@ -409,20 +409,6 @@
409 409 EXPORT_SYMBOL(capable);
410 410  
411 411 /**
412   - * task_ns_capable - Determine whether current task has a superior
413   - * capability targeted at a specific task's user namespace.
414   - * @t: The task whose user namespace is targeted.
415   - * @cap: The capability in question.
416   - *
417   - * Return true if it does, false otherwise.
418   - */
419   -bool task_ns_capable(struct task_struct *t, int cap)
420   -{
421   - return ns_capable(task_cred_xxx(t, user)->user_ns, cap);
422   -}
423   -EXPORT_SYMBOL(task_ns_capable);
424   -
425   -/**
426 412 * nsown_capable - Check superior capability to one's own user_ns
427 413 * @cap: The capability in question
428 414 *
... ... @@ -196,7 +196,7 @@
196 196 smp_rmb();
197 197 if (task->mm)
198 198 dumpable = get_dumpable(task->mm);
199   - if (!dumpable && !task_ns_capable(task, CAP_SYS_PTRACE))
  199 + if (!dumpable && !ns_capable(task_user_ns(task), CAP_SYS_PTRACE))
200 200 return -EPERM;
201 201  
202 202 return security_ptrace_access_check(task, mode);
... ... @@ -266,7 +266,7 @@
266 266 task->ptrace = PT_PTRACED;
267 267 if (seize)
268 268 task->ptrace |= PT_SEIZED;
269   - if (task_ns_capable(task, CAP_SYS_PTRACE))
  269 + if (ns_capable(task_user_ns(task), CAP_SYS_PTRACE))
270 270 task->ptrace |= PT_PTRACE_CAP;
271 271  
272 272 __ptrace_link(task, current);
... ... @@ -5409,7 +5409,7 @@
5409 5409 goto out_free_cpus_allowed;
5410 5410 }
5411 5411 retval = -EPERM;
5412   - if (!check_same_owner(p) && !task_ns_capable(p, CAP_SYS_NICE))
  5412 + if (!check_same_owner(p) && !ns_capable(task_user_ns(p), CAP_SYS_NICE))
5413 5413 goto out_unlock;
5414 5414  
5415 5415 retval = security_task_setscheduler(p);