1

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.

CraCod
  • 11
  • 3

2 Answers2

3

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.

kuba
  • 7,329
  • 1
  • 36
  • 41
  • Thanks a lot Kuba for the prompt reply. I tried using what you mentioned but i was getting different results for getsid(0) in user space and task_session(current) in kernel space. The values are :15422 (with getsid(0) ) :3473445976 ( with task_session(current)) – CraCod May 02 '12 at 23:14
  • 2
    I just figured it out : pid_vnr(task_session(current)); would return us the current session's id. Thanks to Kuba... – CraCod May 03 '12 at 01:37
  • @sebe It scares me that you're writing kernel code, and didn't notice that `sid` in the example code was a *pointer*. – Jonathon Reinhart Jul 23 '15 at 12:29
0

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

helpme
  • 570
  • 1
  • 7
  • 26