processlinux-kerneluseridprocess-group

Getting a user ID and a process group ID from a task_struct and a pid_namespace


I'm trying to modify Linux kernel and I need to get the user ID and the process group ID from a task_struct and a pid_namespace. Although I searched their definitions in the source code, I couldn't find any global variables or functions (maybe I am missing because of the lack of the comments in codes) to access them.

Is there a method to get those inside the kernel space since I can not use user-space functions like getuid(), etc.?


Solution

  • You should be able to use task_struct->cred->uid or task_struct->real_cred->uid. That being said, I have not tested this and this is just from a cursory reading of LXR (include/linux/sched.h line 1508 and include/linux/cred.h line 127).

    If you want the PGID, try pid_vnr(task_pgrp(task_struct)). This code is from kernel/sys.c line 990.