Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does get_current() return in this kernel module?

I have written a kernel module which reads and writes /proc files, and it is working fine. Now I want to use permissions with it, but when I write the function for permissions shown below it gives me an error. The goal is for everyone to be able to read the file but only root can write to it.

int my_permission(struct inode *inode, int op)
{
    if(op == 4||(op == 2 && current->euid = 0)) //euid is not a member of     task_struct
        return 0;
    return -EACCES;
}

const struct inode_operations my_iops = {
    .permission = my_permission,
};

The error I'm getting is:

/home/karan/practice/procf/testproc1.c: In function ‘my_permission’:
/home/karan/practice/procf/testproc1.c:50:32: error: ‘struct task_struct’ has no member named ‘euid'

I know that current is #defined to get_current(). Why is this happening? Is there a list of members of the struct returned from get_current()?

like image 870
karan421 Avatar asked Mar 16 '26 00:03

karan421


1 Answers

The struct task_struct is defined in include/linux/sched.h in the kernel source tree, you can view the members there. The current credentials would be in get_current()->cred , and the effective user id is get_current()->cred->euid

It's not safe to access those members directly, you must rather call current_euid() from include/linux/cred.h

http://www.kernel.org/doc/Documentation/security/credentials.txt might be of interest to you as well

like image 200
nos Avatar answered Mar 17 '26 15:03

nos