如何编写Linux内核模块时,你得到的用户ID [英] How to get userID when writing Linux kernel module
问题描述
下面是我在我的内核模块的功能,我插入使用 insmod的
命令后,制作
在稍后阶段。我工作的金鱼(2.6.29)
Here is my function in my kernel module which I insert using insmod
command after make
at later stages. I am working on goldfish (2.6.29)
asmlinkage long our_sys_read(unsigned int fd, char *buf, size_t count)
{
printk("------->> our_sys_read getuid() ---------- %d\n", getuid());
return original_call_read(fd,buf,count);
}
我想捕获系统呼叫,并找出哪些用户所做的这些系统调用。但是当我运行'化妆',它引发了我下面的错误。
I want to trap system calls and find out which user made these system calls. But when I run 'make', it throws me following error.
/home/mohsin/LKM/trapcall.c:245: error: implicit declaration of function 'getuid'
任何建议将AP preciated。
Any suggestion would be appreciated.
推荐答案
在花费两年天后,我终于想通了如何让谁做了一个系统调用的进程的UID。我会给所有我在不同的链接中找到的建议,这样,如果我的解决方案不起作用,别人的一个可能的工作。
After spending two days, I finally figured out how to get uid of the process who made a system call. I will give all the suggestions I found on different links so that if my solution does not work, one of the others may work.
1)截至告诉我垫,
#include <include/linux/cred.h>
static int getuid()
{
return current_uid();
}
您调用这个函数来获得UID,但它给了我负数像 -943124788
等。
You call this function to get uid but it gave me negative numbers like -943124788
etc.
2)
uid_t credd_uid ;
const struct cred *cred = current_cred();
credd_uid = current->cred->uid;
相同输出一样大的负数。
Same output like large negative numbers.
3)
uid_t struct_uid;
struct user_struct *u = current_user();
struct_uid = get_uid(u);
4)曾为解决方案
这给这里实际上的。
我)声明顶部函数原型像
i) Declare function prototype on the top like
asmlinkage int (*getuid_call)();
二)增加以下线的init_module()函数
ii) Add following line to init_module() function
/ *获取系统调用的getuid * /
/* Get the system call for getuid */
getuid_call = sys_call_table[__NR_getuid];
三)调用函数在被困的系统调用函数来得到类似的uid
iii) Call the function in your trapped system call functions to get uid like
uid_t uid = getuid_call();
这篇关于如何编写Linux内核模块时,你得到的用户ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!