1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0-or-later */
2*4882a593Smuzhiyun /* Credentials management - see Documentation/security/credentials.rst
3*4882a593Smuzhiyun *
4*4882a593Smuzhiyun * Copyright (C) 2008 Red Hat, Inc. All Rights Reserved.
5*4882a593Smuzhiyun * Written by David Howells (dhowells@redhat.com)
6*4882a593Smuzhiyun */
7*4882a593Smuzhiyun
8*4882a593Smuzhiyun #ifndef _LINUX_CRED_H
9*4882a593Smuzhiyun #define _LINUX_CRED_H
10*4882a593Smuzhiyun
11*4882a593Smuzhiyun #include <linux/capability.h>
12*4882a593Smuzhiyun #include <linux/init.h>
13*4882a593Smuzhiyun #include <linux/key.h>
14*4882a593Smuzhiyun #include <linux/atomic.h>
15*4882a593Smuzhiyun #include <linux/uidgid.h>
16*4882a593Smuzhiyun #include <linux/sched.h>
17*4882a593Smuzhiyun #include <linux/sched/user.h>
18*4882a593Smuzhiyun
19*4882a593Smuzhiyun struct cred;
20*4882a593Smuzhiyun struct inode;
21*4882a593Smuzhiyun
22*4882a593Smuzhiyun /*
23*4882a593Smuzhiyun * COW Supplementary groups list
24*4882a593Smuzhiyun */
25*4882a593Smuzhiyun struct group_info {
26*4882a593Smuzhiyun atomic_t usage;
27*4882a593Smuzhiyun int ngroups;
28*4882a593Smuzhiyun kgid_t gid[0];
29*4882a593Smuzhiyun } __randomize_layout;
30*4882a593Smuzhiyun
31*4882a593Smuzhiyun /**
32*4882a593Smuzhiyun * get_group_info - Get a reference to a group info structure
33*4882a593Smuzhiyun * @group_info: The group info to reference
34*4882a593Smuzhiyun *
35*4882a593Smuzhiyun * This gets a reference to a set of supplementary groups.
36*4882a593Smuzhiyun *
37*4882a593Smuzhiyun * If the caller is accessing a task's credentials, they must hold the RCU read
38*4882a593Smuzhiyun * lock when reading.
39*4882a593Smuzhiyun */
get_group_info(struct group_info * gi)40*4882a593Smuzhiyun static inline struct group_info *get_group_info(struct group_info *gi)
41*4882a593Smuzhiyun {
42*4882a593Smuzhiyun atomic_inc(&gi->usage);
43*4882a593Smuzhiyun return gi;
44*4882a593Smuzhiyun }
45*4882a593Smuzhiyun
46*4882a593Smuzhiyun /**
47*4882a593Smuzhiyun * put_group_info - Release a reference to a group info structure
48*4882a593Smuzhiyun * @group_info: The group info to release
49*4882a593Smuzhiyun */
50*4882a593Smuzhiyun #define put_group_info(group_info) \
51*4882a593Smuzhiyun do { \
52*4882a593Smuzhiyun if (atomic_dec_and_test(&(group_info)->usage)) \
53*4882a593Smuzhiyun groups_free(group_info); \
54*4882a593Smuzhiyun } while (0)
55*4882a593Smuzhiyun
56*4882a593Smuzhiyun extern struct group_info init_groups;
57*4882a593Smuzhiyun #ifdef CONFIG_MULTIUSER
58*4882a593Smuzhiyun extern struct group_info *groups_alloc(int);
59*4882a593Smuzhiyun extern void groups_free(struct group_info *);
60*4882a593Smuzhiyun
61*4882a593Smuzhiyun extern int in_group_p(kgid_t);
62*4882a593Smuzhiyun extern int in_egroup_p(kgid_t);
63*4882a593Smuzhiyun extern int groups_search(const struct group_info *, kgid_t);
64*4882a593Smuzhiyun
65*4882a593Smuzhiyun extern int set_current_groups(struct group_info *);
66*4882a593Smuzhiyun extern void set_groups(struct cred *, struct group_info *);
67*4882a593Smuzhiyun extern bool may_setgroups(void);
68*4882a593Smuzhiyun extern void groups_sort(struct group_info *);
69*4882a593Smuzhiyun #else
groups_free(struct group_info * group_info)70*4882a593Smuzhiyun static inline void groups_free(struct group_info *group_info)
71*4882a593Smuzhiyun {
72*4882a593Smuzhiyun }
73*4882a593Smuzhiyun
in_group_p(kgid_t grp)74*4882a593Smuzhiyun static inline int in_group_p(kgid_t grp)
75*4882a593Smuzhiyun {
76*4882a593Smuzhiyun return 1;
77*4882a593Smuzhiyun }
in_egroup_p(kgid_t grp)78*4882a593Smuzhiyun static inline int in_egroup_p(kgid_t grp)
79*4882a593Smuzhiyun {
80*4882a593Smuzhiyun return 1;
81*4882a593Smuzhiyun }
groups_search(const struct group_info * group_info,kgid_t grp)82*4882a593Smuzhiyun static inline int groups_search(const struct group_info *group_info, kgid_t grp)
83*4882a593Smuzhiyun {
84*4882a593Smuzhiyun return 1;
85*4882a593Smuzhiyun }
86*4882a593Smuzhiyun #endif
87*4882a593Smuzhiyun
88*4882a593Smuzhiyun /*
89*4882a593Smuzhiyun * The security context of a task
90*4882a593Smuzhiyun *
91*4882a593Smuzhiyun * The parts of the context break down into two categories:
92*4882a593Smuzhiyun *
93*4882a593Smuzhiyun * (1) The objective context of a task. These parts are used when some other
94*4882a593Smuzhiyun * task is attempting to affect this one.
95*4882a593Smuzhiyun *
96*4882a593Smuzhiyun * (2) The subjective context. These details are used when the task is acting
97*4882a593Smuzhiyun * upon another object, be that a file, a task, a key or whatever.
98*4882a593Smuzhiyun *
99*4882a593Smuzhiyun * Note that some members of this structure belong to both categories - the
100*4882a593Smuzhiyun * LSM security pointer for instance.
101*4882a593Smuzhiyun *
102*4882a593Smuzhiyun * A task has two security pointers. task->real_cred points to the objective
103*4882a593Smuzhiyun * context that defines that task's actual details. The objective part of this
104*4882a593Smuzhiyun * context is used whenever that task is acted upon.
105*4882a593Smuzhiyun *
106*4882a593Smuzhiyun * task->cred points to the subjective context that defines the details of how
107*4882a593Smuzhiyun * that task is going to act upon another object. This may be overridden
108*4882a593Smuzhiyun * temporarily to point to another security context, but normally points to the
109*4882a593Smuzhiyun * same context as task->real_cred.
110*4882a593Smuzhiyun */
111*4882a593Smuzhiyun struct cred {
112*4882a593Smuzhiyun atomic_t usage;
113*4882a593Smuzhiyun #ifdef CONFIG_DEBUG_CREDENTIALS
114*4882a593Smuzhiyun atomic_t subscribers; /* number of processes subscribed */
115*4882a593Smuzhiyun void *put_addr;
116*4882a593Smuzhiyun unsigned magic;
117*4882a593Smuzhiyun #define CRED_MAGIC 0x43736564
118*4882a593Smuzhiyun #define CRED_MAGIC_DEAD 0x44656144
119*4882a593Smuzhiyun #endif
120*4882a593Smuzhiyun kuid_t uid; /* real UID of the task */
121*4882a593Smuzhiyun kgid_t gid; /* real GID of the task */
122*4882a593Smuzhiyun kuid_t suid; /* saved UID of the task */
123*4882a593Smuzhiyun kgid_t sgid; /* saved GID of the task */
124*4882a593Smuzhiyun kuid_t euid; /* effective UID of the task */
125*4882a593Smuzhiyun kgid_t egid; /* effective GID of the task */
126*4882a593Smuzhiyun kuid_t fsuid; /* UID for VFS ops */
127*4882a593Smuzhiyun kgid_t fsgid; /* GID for VFS ops */
128*4882a593Smuzhiyun unsigned securebits; /* SUID-less security management */
129*4882a593Smuzhiyun kernel_cap_t cap_inheritable; /* caps our children can inherit */
130*4882a593Smuzhiyun kernel_cap_t cap_permitted; /* caps we're permitted */
131*4882a593Smuzhiyun kernel_cap_t cap_effective; /* caps we can actually use */
132*4882a593Smuzhiyun kernel_cap_t cap_bset; /* capability bounding set */
133*4882a593Smuzhiyun kernel_cap_t cap_ambient; /* Ambient capability set */
134*4882a593Smuzhiyun #ifdef CONFIG_KEYS
135*4882a593Smuzhiyun unsigned char jit_keyring; /* default keyring to attach requested
136*4882a593Smuzhiyun * keys to */
137*4882a593Smuzhiyun struct key *session_keyring; /* keyring inherited over fork */
138*4882a593Smuzhiyun struct key *process_keyring; /* keyring private to this process */
139*4882a593Smuzhiyun struct key *thread_keyring; /* keyring private to this thread */
140*4882a593Smuzhiyun struct key *request_key_auth; /* assumed request_key authority */
141*4882a593Smuzhiyun #endif
142*4882a593Smuzhiyun #ifdef CONFIG_SECURITY
143*4882a593Smuzhiyun void *security; /* subjective LSM security */
144*4882a593Smuzhiyun #endif
145*4882a593Smuzhiyun struct user_struct *user; /* real user ID subscription */
146*4882a593Smuzhiyun struct user_namespace *user_ns; /* user_ns the caps and keyrings are relative to. */
147*4882a593Smuzhiyun struct group_info *group_info; /* supplementary groups for euid/fsgid */
148*4882a593Smuzhiyun /* RCU deletion */
149*4882a593Smuzhiyun union {
150*4882a593Smuzhiyun int non_rcu; /* Can we skip RCU deletion? */
151*4882a593Smuzhiyun struct rcu_head rcu; /* RCU deletion hook */
152*4882a593Smuzhiyun };
153*4882a593Smuzhiyun } __randomize_layout;
154*4882a593Smuzhiyun
155*4882a593Smuzhiyun extern void __put_cred(struct cred *);
156*4882a593Smuzhiyun extern void exit_creds(struct task_struct *);
157*4882a593Smuzhiyun extern int copy_creds(struct task_struct *, unsigned long);
158*4882a593Smuzhiyun extern const struct cred *get_task_cred(struct task_struct *);
159*4882a593Smuzhiyun extern struct cred *cred_alloc_blank(void);
160*4882a593Smuzhiyun extern struct cred *prepare_creds(void);
161*4882a593Smuzhiyun extern struct cred *prepare_exec_creds(void);
162*4882a593Smuzhiyun extern int commit_creds(struct cred *);
163*4882a593Smuzhiyun extern void abort_creds(struct cred *);
164*4882a593Smuzhiyun extern const struct cred *override_creds(const struct cred *);
165*4882a593Smuzhiyun extern void revert_creds(const struct cred *);
166*4882a593Smuzhiyun extern struct cred *prepare_kernel_cred(struct task_struct *);
167*4882a593Smuzhiyun extern int change_create_files_as(struct cred *, struct inode *);
168*4882a593Smuzhiyun extern int set_security_override(struct cred *, u32);
169*4882a593Smuzhiyun extern int set_security_override_from_ctx(struct cred *, const char *);
170*4882a593Smuzhiyun extern int set_create_files_as(struct cred *, struct inode *);
171*4882a593Smuzhiyun extern int cred_fscmp(const struct cred *, const struct cred *);
172*4882a593Smuzhiyun extern void __init cred_init(void);
173*4882a593Smuzhiyun
174*4882a593Smuzhiyun /*
175*4882a593Smuzhiyun * check for validity of credentials
176*4882a593Smuzhiyun */
177*4882a593Smuzhiyun #ifdef CONFIG_DEBUG_CREDENTIALS
178*4882a593Smuzhiyun extern void __invalid_creds(const struct cred *, const char *, unsigned);
179*4882a593Smuzhiyun extern void __validate_process_creds(struct task_struct *,
180*4882a593Smuzhiyun const char *, unsigned);
181*4882a593Smuzhiyun
182*4882a593Smuzhiyun extern bool creds_are_invalid(const struct cred *cred);
183*4882a593Smuzhiyun
__validate_creds(const struct cred * cred,const char * file,unsigned line)184*4882a593Smuzhiyun static inline void __validate_creds(const struct cred *cred,
185*4882a593Smuzhiyun const char *file, unsigned line)
186*4882a593Smuzhiyun {
187*4882a593Smuzhiyun if (unlikely(creds_are_invalid(cred)))
188*4882a593Smuzhiyun __invalid_creds(cred, file, line);
189*4882a593Smuzhiyun }
190*4882a593Smuzhiyun
191*4882a593Smuzhiyun #define validate_creds(cred) \
192*4882a593Smuzhiyun do { \
193*4882a593Smuzhiyun __validate_creds((cred), __FILE__, __LINE__); \
194*4882a593Smuzhiyun } while(0)
195*4882a593Smuzhiyun
196*4882a593Smuzhiyun #define validate_process_creds() \
197*4882a593Smuzhiyun do { \
198*4882a593Smuzhiyun __validate_process_creds(current, __FILE__, __LINE__); \
199*4882a593Smuzhiyun } while(0)
200*4882a593Smuzhiyun
201*4882a593Smuzhiyun extern void validate_creds_for_do_exit(struct task_struct *);
202*4882a593Smuzhiyun #else
validate_creds(const struct cred * cred)203*4882a593Smuzhiyun static inline void validate_creds(const struct cred *cred)
204*4882a593Smuzhiyun {
205*4882a593Smuzhiyun }
validate_creds_for_do_exit(struct task_struct * tsk)206*4882a593Smuzhiyun static inline void validate_creds_for_do_exit(struct task_struct *tsk)
207*4882a593Smuzhiyun {
208*4882a593Smuzhiyun }
validate_process_creds(void)209*4882a593Smuzhiyun static inline void validate_process_creds(void)
210*4882a593Smuzhiyun {
211*4882a593Smuzhiyun }
212*4882a593Smuzhiyun #endif
213*4882a593Smuzhiyun
cap_ambient_invariant_ok(const struct cred * cred)214*4882a593Smuzhiyun static inline bool cap_ambient_invariant_ok(const struct cred *cred)
215*4882a593Smuzhiyun {
216*4882a593Smuzhiyun return cap_issubset(cred->cap_ambient,
217*4882a593Smuzhiyun cap_intersect(cred->cap_permitted,
218*4882a593Smuzhiyun cred->cap_inheritable));
219*4882a593Smuzhiyun }
220*4882a593Smuzhiyun
221*4882a593Smuzhiyun /**
222*4882a593Smuzhiyun * get_new_cred - Get a reference on a new set of credentials
223*4882a593Smuzhiyun * @cred: The new credentials to reference
224*4882a593Smuzhiyun *
225*4882a593Smuzhiyun * Get a reference on the specified set of new credentials. The caller must
226*4882a593Smuzhiyun * release the reference.
227*4882a593Smuzhiyun */
get_new_cred(struct cred * cred)228*4882a593Smuzhiyun static inline struct cred *get_new_cred(struct cred *cred)
229*4882a593Smuzhiyun {
230*4882a593Smuzhiyun atomic_inc(&cred->usage);
231*4882a593Smuzhiyun return cred;
232*4882a593Smuzhiyun }
233*4882a593Smuzhiyun
234*4882a593Smuzhiyun /**
235*4882a593Smuzhiyun * get_cred - Get a reference on a set of credentials
236*4882a593Smuzhiyun * @cred: The credentials to reference
237*4882a593Smuzhiyun *
238*4882a593Smuzhiyun * Get a reference on the specified set of credentials. The caller must
239*4882a593Smuzhiyun * release the reference. If %NULL is passed, it is returned with no action.
240*4882a593Smuzhiyun *
241*4882a593Smuzhiyun * This is used to deal with a committed set of credentials. Although the
242*4882a593Smuzhiyun * pointer is const, this will temporarily discard the const and increment the
243*4882a593Smuzhiyun * usage count. The purpose of this is to attempt to catch at compile time the
244*4882a593Smuzhiyun * accidental alteration of a set of credentials that should be considered
245*4882a593Smuzhiyun * immutable.
246*4882a593Smuzhiyun */
get_cred(const struct cred * cred)247*4882a593Smuzhiyun static inline const struct cred *get_cred(const struct cred *cred)
248*4882a593Smuzhiyun {
249*4882a593Smuzhiyun struct cred *nonconst_cred = (struct cred *) cred;
250*4882a593Smuzhiyun if (!cred)
251*4882a593Smuzhiyun return cred;
252*4882a593Smuzhiyun validate_creds(cred);
253*4882a593Smuzhiyun nonconst_cred->non_rcu = 0;
254*4882a593Smuzhiyun return get_new_cred(nonconst_cred);
255*4882a593Smuzhiyun }
256*4882a593Smuzhiyun
get_cred_rcu(const struct cred * cred)257*4882a593Smuzhiyun static inline const struct cred *get_cred_rcu(const struct cred *cred)
258*4882a593Smuzhiyun {
259*4882a593Smuzhiyun struct cred *nonconst_cred = (struct cred *) cred;
260*4882a593Smuzhiyun if (!cred)
261*4882a593Smuzhiyun return NULL;
262*4882a593Smuzhiyun if (!atomic_inc_not_zero(&nonconst_cred->usage))
263*4882a593Smuzhiyun return NULL;
264*4882a593Smuzhiyun validate_creds(cred);
265*4882a593Smuzhiyun nonconst_cred->non_rcu = 0;
266*4882a593Smuzhiyun return cred;
267*4882a593Smuzhiyun }
268*4882a593Smuzhiyun
269*4882a593Smuzhiyun /**
270*4882a593Smuzhiyun * put_cred - Release a reference to a set of credentials
271*4882a593Smuzhiyun * @cred: The credentials to release
272*4882a593Smuzhiyun *
273*4882a593Smuzhiyun * Release a reference to a set of credentials, deleting them when the last ref
274*4882a593Smuzhiyun * is released. If %NULL is passed, nothing is done.
275*4882a593Smuzhiyun *
276*4882a593Smuzhiyun * This takes a const pointer to a set of credentials because the credentials
277*4882a593Smuzhiyun * on task_struct are attached by const pointers to prevent accidental
278*4882a593Smuzhiyun * alteration of otherwise immutable credential sets.
279*4882a593Smuzhiyun */
put_cred(const struct cred * _cred)280*4882a593Smuzhiyun static inline void put_cred(const struct cred *_cred)
281*4882a593Smuzhiyun {
282*4882a593Smuzhiyun struct cred *cred = (struct cred *) _cred;
283*4882a593Smuzhiyun
284*4882a593Smuzhiyun if (cred) {
285*4882a593Smuzhiyun validate_creds(cred);
286*4882a593Smuzhiyun if (atomic_dec_and_test(&(cred)->usage))
287*4882a593Smuzhiyun __put_cred(cred);
288*4882a593Smuzhiyun }
289*4882a593Smuzhiyun }
290*4882a593Smuzhiyun
291*4882a593Smuzhiyun /**
292*4882a593Smuzhiyun * current_cred - Access the current task's subjective credentials
293*4882a593Smuzhiyun *
294*4882a593Smuzhiyun * Access the subjective credentials of the current task. RCU-safe,
295*4882a593Smuzhiyun * since nobody else can modify it.
296*4882a593Smuzhiyun */
297*4882a593Smuzhiyun #define current_cred() \
298*4882a593Smuzhiyun rcu_dereference_protected(current->cred, 1)
299*4882a593Smuzhiyun
300*4882a593Smuzhiyun /**
301*4882a593Smuzhiyun * current_real_cred - Access the current task's objective credentials
302*4882a593Smuzhiyun *
303*4882a593Smuzhiyun * Access the objective credentials of the current task. RCU-safe,
304*4882a593Smuzhiyun * since nobody else can modify it.
305*4882a593Smuzhiyun */
306*4882a593Smuzhiyun #define current_real_cred() \
307*4882a593Smuzhiyun rcu_dereference_protected(current->real_cred, 1)
308*4882a593Smuzhiyun
309*4882a593Smuzhiyun /**
310*4882a593Smuzhiyun * __task_cred - Access a task's objective credentials
311*4882a593Smuzhiyun * @task: The task to query
312*4882a593Smuzhiyun *
313*4882a593Smuzhiyun * Access the objective credentials of a task. The caller must hold the RCU
314*4882a593Smuzhiyun * readlock.
315*4882a593Smuzhiyun *
316*4882a593Smuzhiyun * The result of this function should not be passed directly to get_cred();
317*4882a593Smuzhiyun * rather get_task_cred() should be used instead.
318*4882a593Smuzhiyun */
319*4882a593Smuzhiyun #define __task_cred(task) \
320*4882a593Smuzhiyun rcu_dereference((task)->real_cred)
321*4882a593Smuzhiyun
322*4882a593Smuzhiyun /**
323*4882a593Smuzhiyun * get_current_cred - Get the current task's subjective credentials
324*4882a593Smuzhiyun *
325*4882a593Smuzhiyun * Get the subjective credentials of the current task, pinning them so that
326*4882a593Smuzhiyun * they can't go away. Accessing the current task's credentials directly is
327*4882a593Smuzhiyun * not permitted.
328*4882a593Smuzhiyun */
329*4882a593Smuzhiyun #define get_current_cred() \
330*4882a593Smuzhiyun (get_cred(current_cred()))
331*4882a593Smuzhiyun
332*4882a593Smuzhiyun /**
333*4882a593Smuzhiyun * get_current_user - Get the current task's user_struct
334*4882a593Smuzhiyun *
335*4882a593Smuzhiyun * Get the user record of the current task, pinning it so that it can't go
336*4882a593Smuzhiyun * away.
337*4882a593Smuzhiyun */
338*4882a593Smuzhiyun #define get_current_user() \
339*4882a593Smuzhiyun ({ \
340*4882a593Smuzhiyun struct user_struct *__u; \
341*4882a593Smuzhiyun const struct cred *__cred; \
342*4882a593Smuzhiyun __cred = current_cred(); \
343*4882a593Smuzhiyun __u = get_uid(__cred->user); \
344*4882a593Smuzhiyun __u; \
345*4882a593Smuzhiyun })
346*4882a593Smuzhiyun
347*4882a593Smuzhiyun /**
348*4882a593Smuzhiyun * get_current_groups - Get the current task's supplementary group list
349*4882a593Smuzhiyun *
350*4882a593Smuzhiyun * Get the supplementary group list of the current task, pinning it so that it
351*4882a593Smuzhiyun * can't go away.
352*4882a593Smuzhiyun */
353*4882a593Smuzhiyun #define get_current_groups() \
354*4882a593Smuzhiyun ({ \
355*4882a593Smuzhiyun struct group_info *__groups; \
356*4882a593Smuzhiyun const struct cred *__cred; \
357*4882a593Smuzhiyun __cred = current_cred(); \
358*4882a593Smuzhiyun __groups = get_group_info(__cred->group_info); \
359*4882a593Smuzhiyun __groups; \
360*4882a593Smuzhiyun })
361*4882a593Smuzhiyun
362*4882a593Smuzhiyun #define task_cred_xxx(task, xxx) \
363*4882a593Smuzhiyun ({ \
364*4882a593Smuzhiyun __typeof__(((struct cred *)NULL)->xxx) ___val; \
365*4882a593Smuzhiyun rcu_read_lock(); \
366*4882a593Smuzhiyun ___val = __task_cred((task))->xxx; \
367*4882a593Smuzhiyun rcu_read_unlock(); \
368*4882a593Smuzhiyun ___val; \
369*4882a593Smuzhiyun })
370*4882a593Smuzhiyun
371*4882a593Smuzhiyun #define task_uid(task) (task_cred_xxx((task), uid))
372*4882a593Smuzhiyun #define task_euid(task) (task_cred_xxx((task), euid))
373*4882a593Smuzhiyun
374*4882a593Smuzhiyun #define current_cred_xxx(xxx) \
375*4882a593Smuzhiyun ({ \
376*4882a593Smuzhiyun current_cred()->xxx; \
377*4882a593Smuzhiyun })
378*4882a593Smuzhiyun
379*4882a593Smuzhiyun #define current_uid() (current_cred_xxx(uid))
380*4882a593Smuzhiyun #define current_gid() (current_cred_xxx(gid))
381*4882a593Smuzhiyun #define current_euid() (current_cred_xxx(euid))
382*4882a593Smuzhiyun #define current_egid() (current_cred_xxx(egid))
383*4882a593Smuzhiyun #define current_suid() (current_cred_xxx(suid))
384*4882a593Smuzhiyun #define current_sgid() (current_cred_xxx(sgid))
385*4882a593Smuzhiyun #define current_fsuid() (current_cred_xxx(fsuid))
386*4882a593Smuzhiyun #define current_fsgid() (current_cred_xxx(fsgid))
387*4882a593Smuzhiyun #define current_cap() (current_cred_xxx(cap_effective))
388*4882a593Smuzhiyun #define current_user() (current_cred_xxx(user))
389*4882a593Smuzhiyun
390*4882a593Smuzhiyun extern struct user_namespace init_user_ns;
391*4882a593Smuzhiyun #ifdef CONFIG_USER_NS
392*4882a593Smuzhiyun #define current_user_ns() (current_cred_xxx(user_ns))
393*4882a593Smuzhiyun #else
current_user_ns(void)394*4882a593Smuzhiyun static inline struct user_namespace *current_user_ns(void)
395*4882a593Smuzhiyun {
396*4882a593Smuzhiyun return &init_user_ns;
397*4882a593Smuzhiyun }
398*4882a593Smuzhiyun #endif
399*4882a593Smuzhiyun
400*4882a593Smuzhiyun
401*4882a593Smuzhiyun #define current_uid_gid(_uid, _gid) \
402*4882a593Smuzhiyun do { \
403*4882a593Smuzhiyun const struct cred *__cred; \
404*4882a593Smuzhiyun __cred = current_cred(); \
405*4882a593Smuzhiyun *(_uid) = __cred->uid; \
406*4882a593Smuzhiyun *(_gid) = __cred->gid; \
407*4882a593Smuzhiyun } while(0)
408*4882a593Smuzhiyun
409*4882a593Smuzhiyun #define current_euid_egid(_euid, _egid) \
410*4882a593Smuzhiyun do { \
411*4882a593Smuzhiyun const struct cred *__cred; \
412*4882a593Smuzhiyun __cred = current_cred(); \
413*4882a593Smuzhiyun *(_euid) = __cred->euid; \
414*4882a593Smuzhiyun *(_egid) = __cred->egid; \
415*4882a593Smuzhiyun } while(0)
416*4882a593Smuzhiyun
417*4882a593Smuzhiyun #define current_fsuid_fsgid(_fsuid, _fsgid) \
418*4882a593Smuzhiyun do { \
419*4882a593Smuzhiyun const struct cred *__cred; \
420*4882a593Smuzhiyun __cred = current_cred(); \
421*4882a593Smuzhiyun *(_fsuid) = __cred->fsuid; \
422*4882a593Smuzhiyun *(_fsgid) = __cred->fsgid; \
423*4882a593Smuzhiyun } while(0)
424*4882a593Smuzhiyun
425*4882a593Smuzhiyun #endif /* _LINUX_CRED_H */
426