As LDD3 chapter 6 p175 show, we can get current process UID and EUID by current->uid
and current->euid
.
But the definition of struct task_struct
of Linux Kernel 4.2 don't contain fields named by uid
or euid
any more.
So, I wonder if there are any other methods to get UID and EUID ?
Thanks!
Asked
Active
Viewed 9,966 times
5

Yang. fr
- 305
- 3
- 8
1 Answers
10
.uid
and .euid
fields were moved to struct cred
, which is now exposed as .cred
field in struct task_struct
. It was done in this commit: CRED: Separate task security context from task_struct. If you look at diff for include/linux/sched.h
file, you can notice this change:
- uid_t uid,euid,suid,fsuid;
- gid_t gid,egid,sgid,fsgid;
+ struct cred *cred; /* actual/objective task credentials */
So now instead of:
current->uid;
current->euid;
you should use:
const struct cred *cred = current_cred();
cred->uid;
cred->euid;
Notice that current_cred()
function should be used to access .cred
field, as it's RCU pointer.
Check out also check_same_owner() implementation for example.

Sam Protsenko
- 14,045
- 4
- 59
- 75
-
3Thanks! Following your advice, I also have found some useful MACRO in
., e.g. `current_uid()`, `current_euid()` etc, to get these current process ownership information. – Yang. fr Aug 31 '16 at 04:42