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

╄→尐↘猪︶ㄣ 提交于 2019-12-04 09:15:42

.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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!