I am trying to write my own system call under Arch linux system, the following is the format of the system call:
long getpeuid(pid_t pid, uid_t *uid)
Which is used to get the euid of calling process's parent process.
I know I have to verify three things first:
check if the pointer is pointing to the user space. That can be done by
access_ok()
.check if the pointer is pointing to the calling process's address space.
check if the calling process has the permission to write to the space the pointer is pointing to.
I found the syscall copy_to_user()
can copy the kernel space variable to user space, but I am not sure if the syscall checks the other prerequisites first.
Also, I am not sure how can I get the calling process's parent process euid. I know getppid()
could get the parent process ID, but I am not sure how to proceed with that. Can someone give me some hint on this?
Thanks in advance!
EDIT:
A follow up question, if I want to check if the effective uid of parent process is root, I could simply see if euid equals 0, is that right?
EDIT:
Another question, are we allowed to call getppid() and other syscalls inside a syscall? after some googling, it seems like everyone is trying to avoid doing this.