Skip to content

Commit 7b61d64

Browse files
committed
capabilites: introduce new has_ns_capabilities_noaudit
For consistency in interfaces, introduce a new interface called has_ns_capabilities_noaudit. It checks if the given task has the given capability in the given namespace. Use this new function by has_capabilities_noaudit. Signed-off-by: Eric Paris <eparis@redhat.com> Acked-by: Serge E. Hallyn <serge.hallyn@canonical.com>
1 parent 25e7570 commit 7b61d64

2 files changed

Lines changed: 27 additions & 5 deletions

File tree

‎include/linux/capability.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,8 @@ extern bool has_capability(struct task_struct *t, int cap);
543543
extern bool has_ns_capability(struct task_struct *t,
544544
struct user_namespace *ns, int cap);
545545
extern bool has_capability_noaudit(struct task_struct *t, int cap);
546+
extern bool has_ns_capability_noaudit(struct task_struct *t,
547+
struct user_namespace *ns, int cap);
546548
extern bool capable(int cap);
547549
extern bool ns_capable(struct user_namespace *ns, int cap);
548550
extern bool task_ns_capable(struct task_struct *t, int cap);

‎kernel/capability.c‎

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -325,27 +325,47 @@ bool has_capability(struct task_struct *t, int cap)
325325
}
326326

327327
/**
328-
* has_capability_noaudit - Does a task have a capability (unaudited)
328+
* has_ns_capability_noaudit - Does a task have a capability (unaudited)
329+
* in a specific user ns.
329330
* @t: The task in question
331+
* @ns: target user namespace
330332
* @cap: The capability to be tested for
331333
*
332334
* Return true if the specified task has the given superior capability
333-
* currently in effect to init_user_ns, false if not. Don't write an
334-
* audit message for the check.
335+
* currently in effect to the specified user namespace, false if not.
336+
* Do not write an audit message for the check.
335337
*
336338
* Note that this does not set PF_SUPERPRIV on the task.
337339
*/
338-
bool has_capability_noaudit(struct task_struct *t, int cap)
340+
bool has_ns_capability_noaudit(struct task_struct *t,
341+
struct user_namespace *ns, int cap)
339342
{
340343
int ret;
341344

342345
rcu_read_lock();
343-
ret = security_capable_noaudit(__task_cred(t), &init_user_ns, cap);
346+
ret = security_capable_noaudit(__task_cred(t), ns, cap);
344347
rcu_read_unlock();
345348

346349
return (ret == 0);
347350
}
348351

352+
/**
353+
* has_capability_noaudit - Does a task have a capability (unaudited) in the
354+
* initial user ns
355+
* @t: The task in question
356+
* @cap: The capability to be tested for
357+
*
358+
* Return true if the specified task has the given superior capability
359+
* currently in effect to init_user_ns, false if not. Don't write an
360+
* audit message for the check.
361+
*
362+
* Note that this does not set PF_SUPERPRIV on the task.
363+
*/
364+
bool has_capability_noaudit(struct task_struct *t, int cap)
365+
{
366+
return has_ns_capability_noaudit(t, &init_user_ns, cap);
367+
}
368+
349369
/**
350370
* capable - Determine if the current task has a superior capability in effect
351371
* @cap: The capability to be tested for

0 commit comments

Comments
 (0)