How to get the current process UID and EUID in Linux Kernel 4.2?

As shown in chapter 6 p175 in LDD3, we can get the current process UID and EUID with current->uidand current->euid. But the struct task_structLinux Kernel 4.2 definition no longer contains fields named uidor euid. So, I wonder if there are other methods to get the UID and EUID? Thank!

+4
source share
1 answer
Fields

.uidand .euidwere moved to struct cred, which is now displayed as .credin a field struct task_struct. This was done in this commit: CRED: a separate task security context from task_struct . If you look at the diff for the file include/linux/sched.h, you may 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;

Please note that the function current_cred()must be used to access the field .cred, as it is an RCU pointer .

Check also check_same_owner () .

+7
source

Source: https://habr.com/ru/post/1653010/


All Articles