After spending two days, I finally figured out how to get the uid of the process that made the system call. I will give all the suggestions that I found on different links, so that if my solution does not work, one of the others can work.
1) As Mats told me,
#include <include/linux/cred.h> static int getuid() { return current_uid(); }
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 result as large negative numbers.
3)
uid_t struct_uid; struct user_struct *u = current_user(); struct_uid = get_uid(u);
4) working solution
It is given here .
i) Declare a function prototype on top, for example
asmlinkage int (*getuid_call)();
ii) Add the following line to the init_module () function
/ * Get a system call for getuid * /
getuid_call = sys_call_table[__NR_getuid];
iii) Call the function in your system calls to get uid as
uid_t uid = getuid_call();
source share