1b4d0d230SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-or-later */ 2af777cd1SKees Cook /* Credentials management - see Documentation/security/credentials.rst 39e2b2dc4SDavid Howells * 49e2b2dc4SDavid Howells * Copyright (C) 2008 Red Hat, Inc. All Rights Reserved. 59e2b2dc4SDavid Howells * Written by David Howells ([email protected]) 69e2b2dc4SDavid Howells */ 79e2b2dc4SDavid Howells 89e2b2dc4SDavid Howells #ifndef _LINUX_CRED_H 99e2b2dc4SDavid Howells #define _LINUX_CRED_H 109e2b2dc4SDavid Howells 11b6dff3ecSDavid Howells #include <linux/capability.h> 12b2e1feafSAlexey Dobriyan #include <linux/init.h> 13b6dff3ecSDavid Howells #include <linux/key.h> 1460063497SArun Sharma #include <linux/atomic.h> 15d7700842SElena Reshetova #include <linux/refcount.h> 16ae2975bcSEric W. Biederman #include <linux/uidgid.h> 175b825c3aSIngo Molnar #include <linux/sched.h> 188703e8a4SIngo Molnar #include <linux/sched/user.h> 199e2b2dc4SDavid Howells 20b6dff3ecSDavid Howells struct cred; 213a3b7ce9SDavid Howells struct inode; 229e2b2dc4SDavid Howells 23b6dff3ecSDavid Howells /* 24b6dff3ecSDavid Howells * COW Supplementary groups list 25b6dff3ecSDavid Howells */ 26b6dff3ecSDavid Howells struct group_info { 27d7700842SElena Reshetova refcount_t usage; 28b6dff3ecSDavid Howells int ngroups; 29c1f26493SHubert Jasudowicz kgid_t gid[]; 303859a271SKees Cook } __randomize_layout; 31b6dff3ecSDavid Howells 32b6dff3ecSDavid Howells /** 33b6dff3ecSDavid Howells * get_group_info - Get a reference to a group info structure 34b6dff3ecSDavid Howells * @group_info: The group info to reference 35b6dff3ecSDavid Howells * 3686a264abSDavid Howells * This gets a reference to a set of supplementary groups. 3786a264abSDavid Howells * 3886a264abSDavid Howells * If the caller is accessing a task's credentials, they must hold the RCU read 3986a264abSDavid Howells * lock when reading. 40b6dff3ecSDavid Howells */ 4186a264abSDavid Howells static inline struct group_info *get_group_info(struct group_info *gi) 4286a264abSDavid Howells { 43d7700842SElena Reshetova refcount_inc(&gi->usage); 4486a264abSDavid Howells return gi; 4586a264abSDavid Howells } 46b6dff3ecSDavid Howells 47b6dff3ecSDavid Howells /** 48b6dff3ecSDavid Howells * put_group_info - Release a reference to a group info structure 49b6dff3ecSDavid Howells * @group_info: The group info to release 50b6dff3ecSDavid Howells */ 51b6dff3ecSDavid Howells #define put_group_info(group_info) \ 52b6dff3ecSDavid Howells do { \ 53d7700842SElena Reshetova if (refcount_dec_and_test(&(group_info)->usage)) \ 54b6dff3ecSDavid Howells groups_free(group_info); \ 55b6dff3ecSDavid Howells } while (0) 56b6dff3ecSDavid Howells 572813893fSIulia Manda #ifdef CONFIG_MULTIUSER 582813893fSIulia Manda extern struct group_info *groups_alloc(int); 59b6dff3ecSDavid Howells extern void groups_free(struct group_info *); 602813893fSIulia Manda 612813893fSIulia Manda extern int in_group_p(kgid_t); 622813893fSIulia Manda extern int in_egroup_p(kgid_t); 634b09791bSOndrej Mosnáček extern int groups_search(const struct group_info *, kgid_t); 644b09791bSOndrej Mosnáček 654b09791bSOndrej Mosnáček extern int set_current_groups(struct group_info *); 664b09791bSOndrej Mosnáček extern void set_groups(struct cred *, struct group_info *); 674b09791bSOndrej Mosnáček extern bool may_setgroups(void); 684b09791bSOndrej Mosnáček extern void groups_sort(struct group_info *); 692813893fSIulia Manda #else 702813893fSIulia Manda static inline void groups_free(struct group_info *group_info) 712813893fSIulia Manda { 722813893fSIulia Manda } 732813893fSIulia Manda 742813893fSIulia Manda static inline int in_group_p(kgid_t grp) 752813893fSIulia Manda { 762813893fSIulia Manda return 1; 772813893fSIulia Manda } 782813893fSIulia Manda static inline int in_egroup_p(kgid_t grp) 792813893fSIulia Manda { 802813893fSIulia Manda return 1; 812813893fSIulia Manda } 824b09791bSOndrej Mosnáček static inline int groups_search(const struct group_info *group_info, kgid_t grp) 834b09791bSOndrej Mosnáček { 844b09791bSOndrej Mosnáček return 1; 854b09791bSOndrej Mosnáček } 862813893fSIulia Manda #endif 87b6dff3ecSDavid Howells 88b6dff3ecSDavid Howells /* 89b6dff3ecSDavid Howells * The security context of a task 90b6dff3ecSDavid Howells * 91b6dff3ecSDavid Howells * The parts of the context break down into two categories: 92b6dff3ecSDavid Howells * 93b6dff3ecSDavid Howells * (1) The objective context of a task. These parts are used when some other 94b6dff3ecSDavid Howells * task is attempting to affect this one. 95b6dff3ecSDavid Howells * 96b6dff3ecSDavid Howells * (2) The subjective context. These details are used when the task is acting 97b6dff3ecSDavid Howells * upon another object, be that a file, a task, a key or whatever. 98b6dff3ecSDavid Howells * 99b6dff3ecSDavid Howells * Note that some members of this structure belong to both categories - the 100b6dff3ecSDavid Howells * LSM security pointer for instance. 101b6dff3ecSDavid Howells * 102b6dff3ecSDavid Howells * A task has two security pointers. task->real_cred points to the objective 103b6dff3ecSDavid Howells * context that defines that task's actual details. The objective part of this 104b6dff3ecSDavid Howells * context is used whenever that task is acted upon. 105b6dff3ecSDavid Howells * 106b6dff3ecSDavid Howells * task->cred points to the subjective context that defines the details of how 107b6dff3ecSDavid Howells * that task is going to act upon another object. This may be overridden 108b6dff3ecSDavid Howells * temporarily to point to another security context, but normally points to the 109b6dff3ecSDavid Howells * same context as task->real_cred. 110b6dff3ecSDavid Howells */ 111b6dff3ecSDavid Howells struct cred { 112f8fa5d76SJens Axboe atomic_long_t usage; 113078de5f7SEric W. Biederman kuid_t uid; /* real UID of the task */ 114078de5f7SEric W. Biederman kgid_t gid; /* real GID of the task */ 115078de5f7SEric W. Biederman kuid_t suid; /* saved UID of the task */ 116078de5f7SEric W. Biederman kgid_t sgid; /* saved GID of the task */ 117078de5f7SEric W. Biederman kuid_t euid; /* effective UID of the task */ 118078de5f7SEric W. Biederman kgid_t egid; /* effective GID of the task */ 119078de5f7SEric W. Biederman kuid_t fsuid; /* UID for VFS ops */ 120078de5f7SEric W. Biederman kgid_t fsgid; /* GID for VFS ops */ 121b6dff3ecSDavid Howells unsigned securebits; /* SUID-less security management */ 122b6dff3ecSDavid Howells kernel_cap_t cap_inheritable; /* caps our children can inherit */ 123b6dff3ecSDavid Howells kernel_cap_t cap_permitted; /* caps we're permitted */ 124b6dff3ecSDavid Howells kernel_cap_t cap_effective; /* caps we can actually use */ 125b6dff3ecSDavid Howells kernel_cap_t cap_bset; /* capability bounding set */ 12658319057SAndy Lutomirski kernel_cap_t cap_ambient; /* Ambient capability set */ 127b6dff3ecSDavid Howells #ifdef CONFIG_KEYS 128b6dff3ecSDavid Howells unsigned char jit_keyring; /* default keyring to attach requested 129b6dff3ecSDavid Howells * keys to */ 1305c7e372cSJann Horn struct key *session_keyring; /* keyring inherited over fork */ 1313a50597dSDavid Howells struct key *process_keyring; /* keyring private to this process */ 132b6dff3ecSDavid Howells struct key *thread_keyring; /* keyring private to this thread */ 133b6dff3ecSDavid Howells struct key *request_key_auth; /* assumed request_key authority */ 134b6dff3ecSDavid Howells #endif 135b6dff3ecSDavid Howells #ifdef CONFIG_SECURITY 1364ebd7651SPaul Moore void *security; /* LSM security */ 137b6dff3ecSDavid Howells #endif 138b6dff3ecSDavid Howells struct user_struct *user; /* real user ID subscription */ 1390093ccb6SEric W. Biederman struct user_namespace *user_ns; /* user_ns the caps and keyrings are relative to. */ 140905ae01cSAlexey Gladkov struct ucounts *ucounts; 141b6dff3ecSDavid Howells struct group_info *group_info; /* supplementary groups for euid/fsgid */ 142d7852fbdSLinus Torvalds /* RCU deletion */ 143d7852fbdSLinus Torvalds union { 144d7852fbdSLinus Torvalds int non_rcu; /* Can we skip RCU deletion? */ 145b6dff3ecSDavid Howells struct rcu_head rcu; /* RCU deletion hook */ 146d7852fbdSLinus Torvalds }; 1473859a271SKees Cook } __randomize_layout; 148b6dff3ecSDavid Howells 149f1752eecSDavid Howells extern void __put_cred(struct cred *); 150e0e81739SDavid Howells extern void exit_creds(struct task_struct *); 151f1752eecSDavid Howells extern int copy_creds(struct task_struct *, unsigned long); 152de09a977SDavid Howells extern const struct cred *get_task_cred(struct task_struct *); 153ee18d64cSDavid Howells extern struct cred *cred_alloc_blank(void); 154d84f4f99SDavid Howells extern struct cred *prepare_creds(void); 155a6f76f23SDavid Howells extern struct cred *prepare_exec_creds(void); 156d84f4f99SDavid Howells extern int commit_creds(struct cred *); 157d84f4f99SDavid Howells extern void abort_creds(struct cred *); 1583b11a1deSDavid Howells extern const struct cred *override_creds(const struct cred *); 1593b11a1deSDavid Howells extern void revert_creds(const struct cred *); 1603a3b7ce9SDavid Howells extern struct cred *prepare_kernel_cred(struct task_struct *); 1613a3b7ce9SDavid Howells extern int set_security_override(struct cred *, u32); 1623a3b7ce9SDavid Howells extern int set_security_override_from_ctx(struct cred *, const char *); 1633a3b7ce9SDavid Howells extern int set_create_files_as(struct cred *, struct inode *); 164d89b22d4SNeilBrown extern int cred_fscmp(const struct cred *, const struct cred *); 165d84f4f99SDavid Howells extern void __init cred_init(void); 166905ae01cSAlexey Gladkov extern int set_cred_ucounts(struct cred *); 167d84f4f99SDavid Howells 16858319057SAndy Lutomirski static inline bool cap_ambient_invariant_ok(const struct cred *cred) 16958319057SAndy Lutomirski { 17058319057SAndy Lutomirski return cap_issubset(cred->cap_ambient, 17158319057SAndy Lutomirski cap_intersect(cred->cap_permitted, 17258319057SAndy Lutomirski cred->cap_inheritable)); 17358319057SAndy Lutomirski } 17458319057SAndy Lutomirski 175*49dffdfdSVinicius Costa Gomes /* 176*49dffdfdSVinicius Costa Gomes * Override creds without bumping reference count. Caller must ensure 177*49dffdfdSVinicius Costa Gomes * reference remains valid or has taken reference. Almost always not the 178*49dffdfdSVinicius Costa Gomes * interface you want. Use override_creds()/revert_creds() instead. 179*49dffdfdSVinicius Costa Gomes */ 180*49dffdfdSVinicius Costa Gomes static inline const struct cred *override_creds_light(const struct cred *override_cred) 181*49dffdfdSVinicius Costa Gomes { 182*49dffdfdSVinicius Costa Gomes const struct cred *old = current->cred; 183*49dffdfdSVinicius Costa Gomes 184*49dffdfdSVinicius Costa Gomes rcu_assign_pointer(current->cred, override_cred); 185*49dffdfdSVinicius Costa Gomes return old; 186*49dffdfdSVinicius Costa Gomes } 187*49dffdfdSVinicius Costa Gomes 188*49dffdfdSVinicius Costa Gomes static inline void revert_creds_light(const struct cred *revert_cred) 189*49dffdfdSVinicius Costa Gomes { 190*49dffdfdSVinicius Costa Gomes rcu_assign_pointer(current->cred, revert_cred); 191*49dffdfdSVinicius Costa Gomes } 192*49dffdfdSVinicius Costa Gomes 193d84f4f99SDavid Howells /** 19441e84562SMateusz Guzik * get_new_cred_many - Get references on a new set of credentials 19541e84562SMateusz Guzik * @cred: The new credentials to reference 19641e84562SMateusz Guzik * @nr: Number of references to acquire 19741e84562SMateusz Guzik * 19841e84562SMateusz Guzik * Get references on the specified set of new credentials. The caller must 19941e84562SMateusz Guzik * release all acquired references. 20041e84562SMateusz Guzik */ 20141e84562SMateusz Guzik static inline struct cred *get_new_cred_many(struct cred *cred, int nr) 20241e84562SMateusz Guzik { 203f8fa5d76SJens Axboe atomic_long_add(nr, &cred->usage); 20441e84562SMateusz Guzik return cred; 20541e84562SMateusz Guzik } 20641e84562SMateusz Guzik 20741e84562SMateusz Guzik /** 208d84f4f99SDavid Howells * get_new_cred - Get a reference on a new set of credentials 209d84f4f99SDavid Howells * @cred: The new credentials to reference 210d84f4f99SDavid Howells * 211d84f4f99SDavid Howells * Get a reference on the specified set of new credentials. The caller must 212d84f4f99SDavid Howells * release the reference. 213d84f4f99SDavid Howells */ 214d84f4f99SDavid Howells static inline struct cred *get_new_cred(struct cred *cred) 215d84f4f99SDavid Howells { 21641e84562SMateusz Guzik return get_new_cred_many(cred, 1); 217d84f4f99SDavid Howells } 218f1752eecSDavid Howells 219f1752eecSDavid Howells /** 22041e84562SMateusz Guzik * get_cred_many - Get references on a set of credentials 221f1752eecSDavid Howells * @cred: The credentials to reference 22241e84562SMateusz Guzik * @nr: Number of references to acquire 223f1752eecSDavid Howells * 22441e84562SMateusz Guzik * Get references on the specified set of credentials. The caller must release 22541e84562SMateusz Guzik * all acquired reference. If %NULL is passed, it is returned with no action. 22698870ab0SDavid Howells * 22798870ab0SDavid Howells * This is used to deal with a committed set of credentials. Although the 22898870ab0SDavid Howells * pointer is const, this will temporarily discard the const and increment the 22998870ab0SDavid Howells * usage count. The purpose of this is to attempt to catch at compile time the 23098870ab0SDavid Howells * accidental alteration of a set of credentials that should be considered 23198870ab0SDavid Howells * immutable. 232f1752eecSDavid Howells */ 23341e84562SMateusz Guzik static inline const struct cred *get_cred_many(const struct cred *cred, int nr) 234f1752eecSDavid Howells { 2351c388ad0SPaul Menage struct cred *nonconst_cred = (struct cred *) cred; 236f06bc033SNeilBrown if (!cred) 237f06bc033SNeilBrown return cred; 238d7852fbdSLinus Torvalds nonconst_cred->non_rcu = 0; 23941e84562SMateusz Guzik return get_new_cred_many(nonconst_cred, nr); 24041e84562SMateusz Guzik } 24141e84562SMateusz Guzik 24241e84562SMateusz Guzik /* 24341e84562SMateusz Guzik * get_cred - Get a reference on a set of credentials 24441e84562SMateusz Guzik * @cred: The credentials to reference 24541e84562SMateusz Guzik * 24641e84562SMateusz Guzik * Get a reference on the specified set of credentials. The caller must 24741e84562SMateusz Guzik * release the reference. If %NULL is passed, it is returned with no action. 24841e84562SMateusz Guzik * 24941e84562SMateusz Guzik * This is used to deal with a committed set of credentials. 25041e84562SMateusz Guzik */ 25141e84562SMateusz Guzik static inline const struct cred *get_cred(const struct cred *cred) 25241e84562SMateusz Guzik { 25341e84562SMateusz Guzik return get_cred_many(cred, 1); 254f1752eecSDavid Howells } 255f1752eecSDavid Howells 25697d0fb23SNeilBrown static inline const struct cred *get_cred_rcu(const struct cred *cred) 25797d0fb23SNeilBrown { 25897d0fb23SNeilBrown struct cred *nonconst_cred = (struct cred *) cred; 25997d0fb23SNeilBrown if (!cred) 26097d0fb23SNeilBrown return NULL; 261f8fa5d76SJens Axboe if (!atomic_long_inc_not_zero(&nonconst_cred->usage)) 26297d0fb23SNeilBrown return NULL; 263d7852fbdSLinus Torvalds nonconst_cred->non_rcu = 0; 26497d0fb23SNeilBrown return cred; 26597d0fb23SNeilBrown } 26697d0fb23SNeilBrown 267f1752eecSDavid Howells /** 268f1752eecSDavid Howells * put_cred - Release a reference to a set of credentials 269f1752eecSDavid Howells * @cred: The credentials to release 27041e84562SMateusz Guzik * @nr: Number of references to release 271f1752eecSDavid Howells * 272f1752eecSDavid Howells * Release a reference to a set of credentials, deleting them when the last ref 273f06bc033SNeilBrown * is released. If %NULL is passed, nothing is done. 27498870ab0SDavid Howells * 27598870ab0SDavid Howells * This takes a const pointer to a set of credentials because the credentials 27698870ab0SDavid Howells * on task_struct are attached by const pointers to prevent accidental 27798870ab0SDavid Howells * alteration of otherwise immutable credential sets. 278f1752eecSDavid Howells */ 27941e84562SMateusz Guzik static inline void put_cred_many(const struct cred *_cred, int nr) 280f1752eecSDavid Howells { 281c69e8d9cSDavid Howells struct cred *cred = (struct cred *) _cred; 282d84f4f99SDavid Howells 283f06bc033SNeilBrown if (cred) { 284f8fa5d76SJens Axboe if (atomic_long_sub_and_test(nr, &cred->usage)) 285f1752eecSDavid Howells __put_cred(cred); 286f1752eecSDavid Howells } 287f06bc033SNeilBrown } 288f1752eecSDavid Howells 28941e84562SMateusz Guzik /* 29041e84562SMateusz Guzik * put_cred - Release a reference to a set of credentials 29141e84562SMateusz Guzik * @cred: The credentials to release 29241e84562SMateusz Guzik * 29341e84562SMateusz Guzik * Release a reference to a set of credentials, deleting them when the last ref 29441e84562SMateusz Guzik * is released. If %NULL is passed, nothing is done. 29541e84562SMateusz Guzik */ 29641e84562SMateusz Guzik static inline void put_cred(const struct cred *cred) 29741e84562SMateusz Guzik { 29841e84562SMateusz Guzik put_cred_many(cred, 1); 29941e84562SMateusz Guzik } 30041e84562SMateusz Guzik 30186a264abSDavid Howells /** 3023b11a1deSDavid Howells * current_cred - Access the current task's subjective credentials 30386a264abSDavid Howells * 30432955148SAl Viro * Access the subjective credentials of the current task. RCU-safe, 30532955148SAl Viro * since nobody else can modify it. 30686a264abSDavid Howells */ 30786a264abSDavid Howells #define current_cred() \ 30827e4e436SDavid Howells rcu_dereference_protected(current->cred, 1) 30986a264abSDavid Howells 31086a264abSDavid Howells /** 311ae4b884fSJeff Layton * current_real_cred - Access the current task's objective credentials 312ae4b884fSJeff Layton * 313ae4b884fSJeff Layton * Access the objective credentials of the current task. RCU-safe, 314ae4b884fSJeff Layton * since nobody else can modify it. 315ae4b884fSJeff Layton */ 316ae4b884fSJeff Layton #define current_real_cred() \ 317ae4b884fSJeff Layton rcu_dereference_protected(current->real_cred, 1) 318ae4b884fSJeff Layton 319ae4b884fSJeff Layton /** 3203b11a1deSDavid Howells * __task_cred - Access a task's objective credentials 32186a264abSDavid Howells * @task: The task to query 32286a264abSDavid Howells * 3233b11a1deSDavid Howells * Access the objective credentials of a task. The caller must hold the RCU 32443e13cc1SOleg Nesterov * readlock. 32586a264abSDavid Howells * 3268f92054eSDavid Howells * The result of this function should not be passed directly to get_cred(); 3278f92054eSDavid Howells * rather get_task_cred() should be used instead. 32886a264abSDavid Howells */ 32986a264abSDavid Howells #define __task_cred(task) \ 33043e13cc1SOleg Nesterov rcu_dereference((task)->real_cred) 33186a264abSDavid Howells 33286a264abSDavid Howells /** 3333b11a1deSDavid Howells * get_current_cred - Get the current task's subjective credentials 33486a264abSDavid Howells * 3353b11a1deSDavid Howells * Get the subjective credentials of the current task, pinning them so that 3363b11a1deSDavid Howells * they can't go away. Accessing the current task's credentials directly is 3373b11a1deSDavid Howells * not permitted. 33886a264abSDavid Howells */ 33986a264abSDavid Howells #define get_current_cred() \ 34086a264abSDavid Howells (get_cred(current_cred())) 34186a264abSDavid Howells 34286a264abSDavid Howells /** 34386a264abSDavid Howells * get_current_user - Get the current task's user_struct 34486a264abSDavid Howells * 34586a264abSDavid Howells * Get the user record of the current task, pinning it so that it can't go 34686a264abSDavid Howells * away. 34786a264abSDavid Howells */ 34886a264abSDavid Howells #define get_current_user() \ 34986a264abSDavid Howells ({ \ 35086a264abSDavid Howells struct user_struct *__u; \ 351638a8439SLinus Torvalds const struct cred *__cred; \ 35232955148SAl Viro __cred = current_cred(); \ 35386a264abSDavid Howells __u = get_uid(__cred->user); \ 35486a264abSDavid Howells __u; \ 35586a264abSDavid Howells }) 35686a264abSDavid Howells 35786a264abSDavid Howells /** 35886a264abSDavid Howells * get_current_groups - Get the current task's supplementary group list 35986a264abSDavid Howells * 36086a264abSDavid Howells * Get the supplementary group list of the current task, pinning it so that it 36186a264abSDavid Howells * can't go away. 36286a264abSDavid Howells */ 36386a264abSDavid Howells #define get_current_groups() \ 36486a264abSDavid Howells ({ \ 36586a264abSDavid Howells struct group_info *__groups; \ 366638a8439SLinus Torvalds const struct cred *__cred; \ 36732955148SAl Viro __cred = current_cred(); \ 36886a264abSDavid Howells __groups = get_group_info(__cred->group_info); \ 36986a264abSDavid Howells __groups; \ 37086a264abSDavid Howells }) 37186a264abSDavid Howells 37286a264abSDavid Howells #define task_cred_xxx(task, xxx) \ 37386a264abSDavid Howells ({ \ 374d84f4f99SDavid Howells __typeof__(((struct cred *)NULL)->xxx) ___val; \ 37586a264abSDavid Howells rcu_read_lock(); \ 37686a264abSDavid Howells ___val = __task_cred((task))->xxx; \ 37786a264abSDavid Howells rcu_read_unlock(); \ 37886a264abSDavid Howells ___val; \ 37986a264abSDavid Howells }) 38086a264abSDavid Howells 38186a264abSDavid Howells #define task_uid(task) (task_cred_xxx((task), uid)) 38286a264abSDavid Howells #define task_euid(task) (task_cred_xxx((task), euid)) 38321d1c5e3SAlexey Gladkov #define task_ucounts(task) (task_cred_xxx((task), ucounts)) 38486a264abSDavid Howells 38586a264abSDavid Howells #define current_cred_xxx(xxx) \ 38686a264abSDavid Howells ({ \ 38732955148SAl Viro current_cred()->xxx; \ 38886a264abSDavid Howells }) 38986a264abSDavid Howells 39086a264abSDavid Howells #define current_uid() (current_cred_xxx(uid)) 39186a264abSDavid Howells #define current_gid() (current_cred_xxx(gid)) 39286a264abSDavid Howells #define current_euid() (current_cred_xxx(euid)) 39386a264abSDavid Howells #define current_egid() (current_cred_xxx(egid)) 39486a264abSDavid Howells #define current_suid() (current_cred_xxx(suid)) 39586a264abSDavid Howells #define current_sgid() (current_cred_xxx(sgid)) 39686a264abSDavid Howells #define current_fsuid() (current_cred_xxx(fsuid)) 39786a264abSDavid Howells #define current_fsgid() (current_cred_xxx(fsgid)) 39886a264abSDavid Howells #define current_cap() (current_cred_xxx(cap_effective)) 39986a264abSDavid Howells #define current_user() (current_cred_xxx(user)) 40021d1c5e3SAlexey Gladkov #define current_ucounts() (current_cred_xxx(ucounts)) 40186a264abSDavid Howells 4027e6bd8faSEric W. Biederman extern struct user_namespace init_user_ns; 40347a150edSSerge E. Hallyn #ifdef CONFIG_USER_NS 40447a150edSSerge E. Hallyn #define current_user_ns() (current_cred_xxx(user_ns)) 40547a150edSSerge E. Hallyn #else 4060335695dSArnd Bergmann static inline struct user_namespace *current_user_ns(void) 4070335695dSArnd Bergmann { 4080335695dSArnd Bergmann return &init_user_ns; 4090335695dSArnd Bergmann } 41047a150edSSerge E. Hallyn #endif 41147a150edSSerge E. Hallyn 4123486740aSSerge E. Hallyn 41386a264abSDavid Howells #define current_uid_gid(_uid, _gid) \ 41486a264abSDavid Howells do { \ 41586a264abSDavid Howells const struct cred *__cred; \ 41686a264abSDavid Howells __cred = current_cred(); \ 41786a264abSDavid Howells *(_uid) = __cred->uid; \ 41886a264abSDavid Howells *(_gid) = __cred->gid; \ 41986a264abSDavid Howells } while(0) 42086a264abSDavid Howells 42186a264abSDavid Howells #define current_euid_egid(_euid, _egid) \ 42286a264abSDavid Howells do { \ 42386a264abSDavid Howells const struct cred *__cred; \ 42486a264abSDavid Howells __cred = current_cred(); \ 42586a264abSDavid Howells *(_euid) = __cred->euid; \ 42686a264abSDavid Howells *(_egid) = __cred->egid; \ 42786a264abSDavid Howells } while(0) 42886a264abSDavid Howells 42986a264abSDavid Howells #define current_fsuid_fsgid(_fsuid, _fsgid) \ 43086a264abSDavid Howells do { \ 43186a264abSDavid Howells const struct cred *__cred; \ 43286a264abSDavid Howells __cred = current_cred(); \ 43386a264abSDavid Howells *(_fsuid) = __cred->fsuid; \ 43486a264abSDavid Howells *(_fsgid) = __cred->fsgid; \ 43586a264abSDavid Howells } while(0) 43686a264abSDavid Howells 4379e2b2dc4SDavid Howells #endif /* _LINUX_CRED_H */ 438