Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Data Structures | Macros | Functions | Variables
cred.h File Reference
#include <linux/capability.h>
#include <linux/init.h>
#include <linux/key.h>
#include <linux/selinux.h>
#include <linux/atomic.h>
#include <linux/uidgid.h>

Go to the source code of this file.

Data Structures

struct  group_info
 
struct  cred
 

Macros

#define NGROUPS_SMALL   32
 
#define NGROUPS_PER_BLOCK   ((unsigned int)(PAGE_SIZE / sizeof(kgid_t)))
 
#define put_group_info(group_info)
 
#define GROUP_AT(gi, i)   ((gi)->blocks[(i) / NGROUPS_PER_BLOCK][(i) % NGROUPS_PER_BLOCK])
 
#define current_cred()   rcu_dereference_protected(current->cred, 1)
 
#define __task_cred(task)   rcu_dereference((task)->real_cred)
 
#define get_current_cred()   (get_cred(current_cred()))
 
#define get_current_user()
 
#define get_current_groups()
 
#define task_cred_xxx(task, xxx)
 
#define task_uid(task)   (task_cred_xxx((task), uid))
 
#define task_euid(task)   (task_cred_xxx((task), euid))
 
#define current_cred_xxx(xxx)
 
#define current_uid()   (current_cred_xxx(uid))
 
#define current_gid()   (current_cred_xxx(gid))
 
#define current_euid()   (current_cred_xxx(euid))
 
#define current_egid()   (current_cred_xxx(egid))
 
#define current_suid()   (current_cred_xxx(suid))
 
#define current_sgid()   (current_cred_xxx(sgid))
 
#define current_fsuid()   (current_cred_xxx(fsuid))
 
#define current_fsgid()   (current_cred_xxx(fsgid))
 
#define current_cap()   (current_cred_xxx(cap_effective))
 
#define current_user()   (current_cred_xxx(user))
 
#define current_security()   (current_cred_xxx(security))
 
#define current_user_ns()   (&init_user_ns)
 
#define task_user_ns(task)   (&init_user_ns)
 
#define current_uid_gid(_uid, _gid)
 
#define current_euid_egid(_euid, _egid)
 
#define current_fsuid_fsgid(_fsuid, _fsgid)
 

Functions

struct group_infogroups_alloc (int)
 
void groups_free (struct group_info *)
 
int set_current_groups (struct group_info *)
 
int set_groups (struct cred *, struct group_info *)
 
int groups_search (const struct group_info *, kgid_t)
 
int in_group_p (kgid_t)
 
int in_egroup_p (kgid_t)
 
void __put_cred (struct cred *)
 
void exit_creds (struct task_struct *)
 
int copy_creds (struct task_struct *, unsigned long)
 
struct credget_task_cred (struct task_struct *)
 
struct credcred_alloc_blank (void)
 
struct credprepare_creds (void)
 
struct credprepare_exec_creds (void)
 
int commit_creds (struct cred *)
 
void abort_creds (struct cred *)
 
struct credoverride_creds (const struct cred *)
 
void revert_creds (const struct cred *)
 
struct credprepare_kernel_cred (struct task_struct *)
 
int change_create_files_as (struct cred *, struct inode *)
 
int set_security_override (struct cred *, u32)
 
int set_security_override_from_ctx (struct cred *, const char *)
 
int set_create_files_as (struct cred *, struct inode *)
 
void __init cred_init (void)
 

Variables

struct group_info init_groups
 
struct user_namespace init_user_ns
 

Macro Definition Documentation

#define __task_cred (   task)    rcu_dereference((task)->real_cred)

__task_cred - Access a task's objective credentials : The task to query

Access the objective credentials of a task. The caller must hold the RCU readlock.

The result of this function should not be passed directly to get_cred(); rather get_task_cred() should be used instead.

Definition at line 285 of file cred.h.

#define current_cap ( )    (current_cred_xxx(cap_effective))

Definition at line 353 of file cred.h.

#define current_cred ( )    rcu_dereference_protected(current->cred, 1)

current_cred - Access the current task's subjective credentials

Access the subjective credentials of the current task. RCU-safe, since nobody else can modify it.

Definition at line 272 of file cred.h.

#define current_cred_xxx (   xxx)
Value:
({ \
current_cred()->xxx; \
})

Definition at line 340 of file cred.h.

#define current_egid ( )    (current_cred_xxx(egid))

Definition at line 348 of file cred.h.

#define current_euid ( )    (current_cred_xxx(euid))

Definition at line 347 of file cred.h.

#define current_euid_egid (   _euid,
  _egid 
)
Value:
do { \
const struct cred *__cred; \
__cred = current_cred(); \
*(_euid) = __cred->euid; \
*(_egid) = __cred->egid; \
} while(0)

Definition at line 375 of file cred.h.

#define current_fsgid ( )    (current_cred_xxx(fsgid))

Definition at line 352 of file cred.h.

#define current_fsuid ( )    (current_cred_xxx(fsuid))

Definition at line 351 of file cred.h.

#define current_fsuid_fsgid (   _fsuid,
  _fsgid 
)
Value:
do { \
const struct cred *__cred; \
__cred = current_cred(); \
*(_fsuid) = __cred->fsuid; \
*(_fsgid) = __cred->fsgid; \
} while(0)

Definition at line 383 of file cred.h.

#define current_gid ( )    (current_cred_xxx(gid))

Definition at line 346 of file cred.h.

#define current_security ( )    (current_cred_xxx(security))

Definition at line 355 of file cred.h.

#define current_sgid ( )    (current_cred_xxx(sgid))

Definition at line 350 of file cred.h.

#define current_suid ( )    (current_cred_xxx(suid))

Definition at line 349 of file cred.h.

#define current_uid ( )    (current_cred_xxx(uid))

Definition at line 345 of file cred.h.

#define current_uid_gid (   _uid,
  _gid 
)
Value:
do { \
const struct cred *__cred; \
__cred = current_cred(); \
*(_uid) = __cred->uid; \
*(_gid) = __cred->gid; \
} while(0)

Definition at line 367 of file cred.h.

#define current_user ( )    (current_cred_xxx(user))

Definition at line 354 of file cred.h.

#define current_user_ns (   void)    (&init_user_ns)

Definition at line 362 of file cred.h.

#define get_current_cred ( )    (get_cred(current_cred()))

get_current_cred - Get the current task's subjective credentials

Get the subjective credentials of the current task, pinning them so that they can't go away. Accessing the current task's credentials directly is not permitted.

Definition at line 295 of file cred.h.

#define get_current_groups ( )
Value:
({ \
struct group_info *__groups; \
const struct cred *__cred; \
__cred = current_cred(); \
__groups = get_group_info(__cred->group_info); \
__groups; \
})

get_current_groups - Get the current task's supplementary group list

Get the supplementary group list of the current task, pinning it so that it can't go away.

Definition at line 319 of file cred.h.

#define get_current_user ( )
Value:
({ \
const struct cred *__cred; \
__cred = current_cred(); \
__u = get_uid(__cred->user); \
__u; \
})

get_current_user - Get the current task's user_struct

Get the user record of the current task, pinning it so that it can't go away.

Definition at line 304 of file cred.h.

#define GROUP_AT (   gi,
  i 
)    ((gi)->blocks[(i) / NGROUPS_PER_BLOCK][(i) % NGROUPS_PER_BLOCK])

Definition at line 73 of file cred.h.

#define NGROUPS_PER_BLOCK   ((unsigned int)(PAGE_SIZE / sizeof(kgid_t)))

Definition at line 30 of file cred.h.

#define NGROUPS_SMALL   32

Definition at line 29 of file cred.h.

#define put_group_info (   group_info)
Value:
do { \
groups_free(group_info); \
} while (0)

put_group_info - Release a reference to a group info structure : The group info to release

Definition at line 59 of file cred.h.

#define task_cred_xxx (   task,
  xxx 
)
Value:
({ \
__typeof__(((struct cred *)NULL)->xxx) ___val; \
rcu_read_lock(); \
___val = __task_cred((task))->xxx; \
rcu_read_unlock(); \
___val; \
})

Definition at line 328 of file cred.h.

#define task_euid (   task)    (task_cred_xxx((task), euid))

Definition at line 338 of file cred.h.

#define task_uid (   task)    (task_cred_xxx((task), uid))

Definition at line 337 of file cred.h.

#define task_user_ns (   task)    (&init_user_ns)

Definition at line 363 of file cred.h.

Function Documentation

void __put_cred ( struct cred cred)

__put_cred - Destroy a set of credentials : The record to release

Destroy a set of credentials on which no references remain.

Definition at line 169 of file cred.c.

void abort_creds ( struct cred new)

abort_creds - Discard a set of credentials and unlock the current task : The credentials that were going to be applied

Discard a set of credentials that were under construction and unlock the current task.

Definition at line 549 of file cred.c.

int change_create_files_as ( struct cred ,
struct inode  
)
int commit_creds ( struct cred new)

commit_creds - Install new credentials upon the current task : The credentials to be assigned

Install a new set of credentials to the current task, using RCU to replace the old set. Both the objective and the subjective credentials pointers are updated. This function may not be called if the subjective credentials are in an overridden state.

This function eats the caller's reference to the new credentials.

Always returns 0 thus allowing this function to be tail-called at the end of, say, sys_setgid().

Definition at line 472 of file cred.c.

int copy_creds ( struct task_struct ,
unsigned  long 
)

Definition at line 384 of file cred.c.

struct cred* cred_alloc_blank ( void  )
read

Definition at line 241 of file cred.c.

void __init cred_init ( void  )

Definition at line 619 of file cred.c.

void exit_creds ( struct task_struct )

Definition at line 191 of file cred.c.

struct cred* get_task_cred ( struct task_struct task)
read

get_task_cred - Get another task's objective credentials : The task to query

Get the objective credentials of a task, pinning them so that they can't go away. Accessing a task's credentials directly is not permitted.

The caller must also make sure task doesn't get deleted, either by holding a ref on task or by holding tasklist_lock to prevent it from being unlinked.

Definition at line 222 of file cred.c.

struct group_info* groups_alloc ( int  )
read

Definition at line 14 of file groups.c.

void groups_free ( struct group_info )

Definition at line 53 of file groups.c.

int groups_search ( const struct group_info ,
kgid_t   
)

Definition at line 135 of file groups.c.

int in_egroup_p ( kgid_t  )

Definition at line 271 of file groups.c.

int in_group_p ( kgid_t  )

Definition at line 259 of file groups.c.

struct cred* override_creds ( const struct cred new)
read

override_creds - Override the current process's subjective credentials : The credentials to be assigned

Install a set of temporary override subjective credentials on the current process, returning the old set for later reversion.

Definition at line 570 of file cred.c.

struct cred* prepare_creds ( void  )
read

prepare_creds - Prepare a new set of credentials for modification

Prepare a new set of task credentials for modification. A task's creds shouldn't generally be modified directly, therefore this function is used to prepare a new copy, which the caller then modifies and then commits by calling commit_creds().

Preparation involves making a copy of the objective creds for modification.

Returns a pointer to the new creds-to-be if successful, NULL otherwise.

Call commit_creds() or abort_creds() to clean up.

Definition at line 287 of file cred.c.

struct cred* prepare_exec_creds ( void  )
read

Definition at line 335 of file cred.c.

struct cred* prepare_kernel_cred ( struct task_struct daemon)
read

prepare_kernel_cred - Prepare a set of credentials for a kernel service : A userspace daemon to be used as a reference

Prepare a set of credentials for a kernel service. This can then be used to override a task's own credentials so that work can be done on behalf of that task that requires a different subjective context.

is used to provide a base for the security record, but can be NULL. If is supplied, then the security data will be derived from that; otherwise they'll be set to 0 and no groups, full capabilities and no keys.

The caller may change these controls afterwards if desired.

Returns the new credentials or NULL if out of memory.

Does not take, and does not return holding current->cred_replace_mutex.

Definition at line 644 of file cred.c.

void revert_creds ( const struct cred old)

revert_creds - Revert a temporary subjective credentials override : The credentials to be restored

Revert a temporary set of override subjective credentials to an old set, discarding the override set.

Definition at line 599 of file cred.c.

int set_create_files_as ( struct cred new,
struct inode inode 
)

set_create_files_as - Set the LSM file create context in a set of credentials : The credentials to alter : The inode to take the context from

Change the LSM file creation context in a set of credentials to be the same as the object context of the specified inode, so that the new inodes have the same MAC context as that inode.

Definition at line 754 of file cred.c.

int set_current_groups ( struct group_info group_info)

set_current_groups - Change current's group subscription : The group list to impose

Validate a group subscription and, if valid, impose it upon current's task security record.

Definition at line 182 of file groups.c.

int set_groups ( struct cred new,
struct group_info group_info 
)

set_groups - Change a group subscription in a set of credentials : The newly prepared set of credentials to alter : The group list to install

Validate a group subscription and, if valid, insert it into a set of credentials.

Definition at line 164 of file groups.c.

int set_security_override ( struct cred new,
u32  secid 
)

set_security_override - Set the security ID in a set of credentials : The credentials to alter : The LSM security ID to set

Set the LSM security ID in a set of credentials so that the subjective security is overridden when an alternative set of credentials is used.

Definition at line 716 of file cred.c.

int set_security_override_from_ctx ( struct cred new,
const char secctx 
)

set_security_override_from_ctx - Set the security ID in a set of credentials : The credentials to alter : The LSM security context to generate the security ID from.

Set the LSM security ID in a set of credentials so that the subjective security is overridden when an alternative set of credentials is used. The security ID is specified in string form as a security context to be interpreted by the LSM.

Definition at line 732 of file cred.c.

Variable Documentation

struct group_info init_groups

Definition at line 12 of file groups.c.

struct user_namespace init_user_ns

Definition at line 24 of file user.c.