Retrieving session Id in linux kernel (Kernel Space)

前提是你 提交于 2019-12-24 16:22:25

问题


I want to retrieve the sessionid of the current process in linux kernel (Kernel Space). I saw task_struct has a field sessionid but it is defined only when the macro CONFIG_AUDITSYSCALL is ON. So i tried to build the kernel with this macro ON but still i was not getting the result. Also I tried getting its value from function with CONFIG_AUDITSYSCALL on audit_get_sessionid(current) but was getting either -1 or junk value ( different from getsid(0) method in user space).

I am struck at this point. Any suggestion would be of great help.


回答1:


You can take a look at the getsid syscall at here: http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=blob;f=kernel/sys.c#l1106

SYSCALL_DEFINE1(getsid, pid_t, pid)
{
     struct task_struct *p;
     struct pid *sid;
     int retval;

     rcu_read_lock();
     if (!pid)
             sid = task_session(current);
     else {
     ...

Which suggest you can use the kernel function task_session() to get the session id.




回答2:


pid_vnr(task_session(current)); would do what u want!!



来源:https://stackoverflow.com/questions/10422806/retrieving-session-id-in-linux-kernel-kernel-space

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