Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do certain Linux x86_64 system calls require a stub?

If one tries to hook certain syscalls via sys_call_table-hooking, e.g. sys_execve this will fail, because they are indirectly called by a stub. For sys_execve this is stub_execve (compare assembly code on LXR).

But what are these stubs good for? Why do only certain system calls like execve(2) and fork(2) require a stub and how is this connected to x86_64? Is there a workaround to hook stubbed syscalls (in a Loadable Kernel Module)?

like image 994
Propantriol Avatar asked May 19 '14 09:05

Propantriol


People also ask

What is a system call stub?

The system call stub functions provide a high-level language interface to a function whose main job is to generate the software interrupt (trap) needed to get the kernel's attention. These functions are often called wrappers. The stub functions on most operating systems do the same basic steps.

How do system calls work in Linux?

A system call is a function that allows a process to communicate with the Linux kernel. It's just a programmatic way for a computer program to order a facility from the operating system's kernel. System calls expose the operating system's resources to user programs through an API (Application Programming Interface).

What is the system call number for the exit system call on Kali 64 bit Linux?

The exit syscall is number 60 .

How many Linux Syscalls are there?

There can be a maximum of 6 system call parameters. Both the system call number and the parameters are stored in certain registers. For example, on 32bit x86 architecture, the system call identifier is stored in the EAX register, while parameters in registers EBX, ECX, EDX, ESI, EDI, EBP.


1 Answers

From here, it says:

"Certain special system calls that need to save a complete full stack frame."

And I think execve is just one of these special system calls.

From the code of stub_execve, If you want to hook it, at least you can try:

  1. Get to understand the meaning of those assembly code and do it by yourself, then you can call your own function in your own assembly code.
  2. From the middle of the assembly code, it has a call sys_execve, you can replace the address of sys_execve to your own hook function.
like image 104
zym Avatar answered Oct 18 '22 05:10

zym