get_current()在这个内核模块中返回什么?

kar*_*421 3 c linux linux-kernel

我编写了一个读取和写入/proc文件的内核模块,它工作正常.现在我想使用它的权限,但是当我为下面显示的权限编写函数时,它给了我一个错误.目标是让每个人都能够读取文件,但只有root才能写入文件.

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,
};
Run Code Online (Sandbox Code Playgroud)

我得到的错误是:

/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'
Run Code Online (Sandbox Code Playgroud)

我知道current#defined是get_current().为什么会这样?是否有从中返回的结构的成员列表get_current()

nos*_*nos 6

struct task_struct定义中include/linux/sched.h的内核源代码树,你可以在那里查看成员.当前凭据将在get_current()->cred,有效用户ID为get_current()->cred->euid

直接访问这些成员是不安全的,你必须current_euid()从中调用include/linux/cred.h

您也可能对http://www.kernel.org/doc/Documentation/security/credentials.txt感兴趣