Skip to content

Commit

Permalink
userns: make has_capability* into real functions
Browse files Browse the repository at this point in the history
So we can let type safety keep things sane, and as a bonus we can remove
the declaration of init_user_ns in capability.h.

Signed-off-by: Serge E. Hallyn <[email protected]>
Cc: "Eric W. Biederman" <[email protected]>
Cc: Daniel Lezcano <[email protected]>
Cc: David Howells <[email protected]>
Cc: James Morris <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
hallyn authored and torvalds committed Mar 24, 2011
1 parent 8409cca commit 3263245
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 30 deletions.
34 changes: 4 additions & 30 deletions include/linux/capability.h
Original file line number Diff line number Diff line change
Expand Up @@ -371,8 +371,6 @@ struct cpu_vfs_cap_data {
struct dentry;
struct user_namespace;

extern struct user_namespace init_user_ns;

struct user_namespace *current_user_ns(void);

extern const kernel_cap_t __cap_empty_set;
Expand Down Expand Up @@ -541,34 +539,10 @@ static inline kernel_cap_t cap_raise_nfsd_set(const kernel_cap_t a,
cap_intersect(permitted, __cap_nfsd_set));
}

/**
* has_capability - Determine if a task has a superior capability available
* @t: The task in question
* @cap: The capability to be tested for
*
* Return true if the specified task has the given superior capability
* currently in effect, false if not.
*
* Note that this does not set PF_SUPERPRIV on the task.
*/
#define has_capability(t, cap) (security_real_capable((t), &init_user_ns, (cap)) == 0)

#define has_ns_capability(t, ns, cap) (security_real_capable((t), (ns), (cap)) == 0)

/**
* has_capability_noaudit - Determine if a task has a superior capability available (unaudited)
* @t: The task in question
* @cap: The capability to be tested for
*
* Return true if the specified task has the given superior capability
* currently in effect, false if not, but don't write an audit message for the
* check.
*
* Note that this does not set PF_SUPERPRIV on the task.
*/
#define has_capability_noaudit(t, cap) \
(security_real_capable_noaudit((t), &init_user_ns, (cap)) == 0)

extern bool has_capability(struct task_struct *t, int cap);
extern bool has_ns_capability(struct task_struct *t,
struct user_namespace *ns, int cap);
extern bool has_capability_noaudit(struct task_struct *t, int cap);
extern bool capable(int cap);
extern bool ns_capable(struct user_namespace *ns, int cap);
extern bool task_ns_capable(struct task_struct *t, int cap);
Expand Down
54 changes: 54 additions & 0 deletions kernel/capability.c
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,60 @@ SYSCALL_DEFINE2(capset, cap_user_header_t, header, const cap_user_data_t, data)
return ret;
}

/**
* has_capability - Does a task have a capability in init_user_ns
* @t: The task in question
* @cap: The capability to be tested for
*
* Return true if the specified task has the given superior capability
* currently in effect to the initial user namespace, false if not.
*
* Note that this does not set PF_SUPERPRIV on the task.
*/
bool has_capability(struct task_struct *t, int cap)
{
int ret = security_real_capable(t, &init_user_ns, cap);

return (ret == 0);
}

/**
* has_capability - Does a task have a capability in a specific user ns
* @t: The task in question
* @ns: target user namespace
* @cap: The capability to be tested for
*
* Return true if the specified task has the given superior capability
* currently in effect to the specified user namespace, false if not.
*
* Note that this does not set PF_SUPERPRIV on the task.
*/
bool has_ns_capability(struct task_struct *t,
struct user_namespace *ns, int cap)
{
int ret = security_real_capable(t, ns, cap);

return (ret == 0);
}

/**
* has_capability_noaudit - Does a task have a capability (unaudited)
* @t: The task in question
* @cap: The capability to be tested for
*
* Return true if the specified task has the given superior capability
* currently in effect to init_user_ns, false if not. Don't write an
* audit message for the check.
*
* Note that this does not set PF_SUPERPRIV on the task.
*/
bool has_capability_noaudit(struct task_struct *t, int cap)
{
int ret = security_real_capable_noaudit(t, &init_user_ns, cap);

return (ret == 0);
}

/**
* capable - Determine if the current task has a superior capability in effect
* @cap: The capability to be tested for
Expand Down

0 comments on commit 3263245

Please sign in to comment.