15 #include <linux/capability.h>
29 #define NGROUPS_SMALL 32
30 #define NGROUPS_PER_BLOCK ((unsigned int)(PAGE_SIZE / sizeof(kgid_t)))
59 #define put_group_info(group_info) \
61 if (atomic_dec_and_test(&(group_info)->usage)) \
62 groups_free(group_info); \
73 #define GROUP_AT(gi, i) \
74 ((gi)->blocks[(i) / NGROUPS_PER_BLOCK][(i) % NGROUPS_PER_BLOCK])
84 struct thread_group_cred {
89 struct key *process_keyring;
119 #ifdef CONFIG_DEBUG_CREDENTIALS
123 #define CRED_MAGIC 0x43736564
124 #define CRED_MAGIC_DEAD 0x44656144
140 unsigned char jit_keyring;
142 struct key *thread_keyring;
144 struct thread_group_cred *tgcred;
146 #ifdef CONFIG_SECURITY
176 #ifdef CONFIG_DEBUG_CREDENTIALS
177 extern void __invalid_creds(
const struct cred *,
const char *,
unsigned);
178 extern void __validate_process_creds(
struct task_struct *,
179 const char *,
unsigned);
181 extern bool creds_are_invalid(
const struct cred *
cred);
183 static inline void __validate_creds(
const struct cred *
cred,
186 if (
unlikely(creds_are_invalid(cred)))
187 __invalid_creds(cred, file, line);
190 #define validate_creds(cred) \
192 __validate_creds((cred), __FILE__, __LINE__); \
195 #define validate_process_creds() \
197 __validate_process_creds(current, __FILE__, __LINE__); \
200 extern void validate_creds_for_do_exit(
struct task_struct *);
202 static inline void validate_creds(
const struct cred *cred)
205 static inline void validate_creds_for_do_exit(
struct task_struct *tsk)
208 static inline void validate_process_creds(
void)
220 static inline struct cred *get_new_cred(
struct cred *cred)
239 static inline const struct cred *get_cred(
const struct cred *cred)
241 struct cred *nonconst_cred = (
struct cred *) cred;
242 validate_creds(cred);
243 return get_new_cred(nonconst_cred);
257 static inline void put_cred(
const struct cred *_cred)
259 struct cred *cred = (
struct cred *) _cred;
261 validate_creds(cred);
272 #define current_cred() \
273 rcu_dereference_protected(current->cred, 1)
285 #define __task_cred(task) \
286 rcu_dereference((task)->real_cred)
295 #define get_current_cred() \
296 (get_cred(current_cred()))
304 #define get_current_user() \
306 struct user_struct *__u; \
307 const struct cred *__cred; \
308 __cred = current_cred(); \
309 __u = get_uid(__cred->user); \
319 #define get_current_groups() \
321 struct group_info *__groups; \
322 const struct cred *__cred; \
323 __cred = current_cred(); \
324 __groups = get_group_info(__cred->group_info); \
328 #define task_cred_xxx(task, xxx) \
330 __typeof__(((struct cred *)NULL)->xxx) ___val; \
332 ___val = __task_cred((task))->xxx; \
337 #define task_uid(task) (task_cred_xxx((task), uid))
338 #define task_euid(task) (task_cred_xxx((task), euid))
340 #define current_cred_xxx(xxx) \
342 current_cred()->xxx; \
345 #define current_uid() (current_cred_xxx(uid))
346 #define current_gid() (current_cred_xxx(gid))
347 #define current_euid() (current_cred_xxx(euid))
348 #define current_egid() (current_cred_xxx(egid))
349 #define current_suid() (current_cred_xxx(suid))
350 #define current_sgid() (current_cred_xxx(sgid))
351 #define current_fsuid() (current_cred_xxx(fsuid))
352 #define current_fsgid() (current_cred_xxx(fsgid))
353 #define current_cap() (current_cred_xxx(cap_effective))
354 #define current_user() (current_cred_xxx(user))
355 #define current_security() (current_cred_xxx(security))
358 #ifdef CONFIG_USER_NS
359 #define current_user_ns() (current_cred_xxx(user_ns))
360 #define task_user_ns(task) (task_cred_xxx((task), user_ns))
362 #define current_user_ns() (&init_user_ns)
363 #define task_user_ns(task) (&init_user_ns)
367 #define current_uid_gid(_uid, _gid) \
369 const struct cred *__cred; \
370 __cred = current_cred(); \
371 *(_uid) = __cred->uid; \
372 *(_gid) = __cred->gid; \
375 #define current_euid_egid(_euid, _egid) \
377 const struct cred *__cred; \
378 __cred = current_cred(); \
379 *(_euid) = __cred->euid; \
380 *(_egid) = __cred->egid; \
383 #define current_fsuid_fsgid(_fsuid, _fsgid) \
385 const struct cred *__cred; \
386 __cred = current_cred(); \
387 *(_fsuid) = __cred->fsuid; \
388 *(_fsgid) = __cred->fsgid; \