本文介绍了如何在Linux Kernel 4.2中获取当前进程的UID和EUID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如LDD3第6页p175所示,我们可以通过current->uidcurrent->euid获得当前进程的UID和EUID.但是Linux Kernel 4.2的struct task_struct定义不再包含uideuid命名的字段.因此,我想知道是否还有其他获取UID和EUID的方法?谢谢!

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!

推荐答案

.uid.euid字段已移至struct cred,现在在struct task_struct中显示为.cred字段.它是在以下提交中完成的: CRED :将任务安全性上下文与task_struct 分开.如果查看include/linux/sched.h文件的差异,您会注意到这一变化:

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

所以现在代替:

current->uid;
current->euid;

您应该使用:

const struct cred *cred = current_cred();

cred->uid;
cred->euid;

请注意,应该使用current_cred()函数来访问.cred字段,因为它是 RCU 指针.

Notice that current_cred() function should be used to access .cred field, as it's RCU pointer.

还要 check_same_owner()实现例子.

这篇关于如何在Linux Kernel 4.2中获取当前进程的UID和EUID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-16 05:39