Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to find out what user owns a process from the process's task_struct?

I have a task_struct * that I got by calling find_task_by_vpid(get_pid()). I'd like to figure out what user owns that process so that I can do some permission checking in the system call I'm writing, but looking through the task_struct source code hasn't helped much. The only thing that looked helpful is the loginuid, but for some reason the kernel won't compile if I try to access it like this: my_task_struct->loginuid. Is there another way to get the user who called the process from the task_struct?

like image 689
Mason Avatar asked Oct 27 '12 22:10

Mason


1 Answers

Unfortunately, the user/group ids are no longer stored in the task struct, but instead in a separate privilege structure that's dynamically allocated and shared between all tasks that have the same ids. This in turn creates a situation where setuid can fail due to resource exhaustion, and failure of setuid to prop privileges is an infamous source of vulnerabilities...

Anyway, it's in these members of the task_struct:

    const struct cred __rcu *real_cred; /* objective and real subjective task
                                     * credentials (COW) */
    const struct cred __rcu *cred;  /* effective (overridable) subjective task
                                     * credentials (COW) */
like image 102
R.. GitHub STOP HELPING ICE Avatar answered Sep 28 '22 09:09

R.. GitHub STOP HELPING ICE