Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to add a system call via a LKM?

I'd like to add a new system call via an LKM, but I'm not sure how to do this. That is, I know that if I want to add a completely new system call, I can look through the sys_call_table and find a sys_ni_syscall and just replace it, but I was curious if it was possible to actually add to the sys_call_table. I realize it's probably not possible, given that it's a fixed size array, but I was wondering if there were any other clever ways to add system calls without overriding an unused system call number.

like image 234
FreeMemory Avatar asked Jan 20 '09 22:01

FreeMemory


People also ask

Can a system call call another system call?

System calls can't call other system calls because it wouldn't make sense to go through all the effort of doing a system call when you're already in the kernel.

How the user can communicate via system calls?

System call provides the services of the operating system to the user programs via Application Program Interface(API). It provides an interface between a process and operating system to allow user-level processes to request services of the operating system. System calls are the only entry points into the kernel system.

What is API system call?

API is the acronym for Application Programming Interface, which is a software intermediary that allows two applications to talk to each other.


3 Answers

Here's an example
linux system calls

edit:
The example above shows howto implement a system call, as far as implementing one from a loadable module; AFAIK, that's not possible, unless you where to overwrite an existing one because the size of the array is a #define.

Keep in mind there are user space changes required as well, at least if you want to be able to actually use the new system call.

like image 126
Steve Lazaridis Avatar answered Oct 10 '22 21:10

Steve Lazaridis


Check The Linux Documentation Project website for "The Linux Kernel Module Programming Guide" (http://www.tldp.org/LDP/lkmpg/2.6/html/index.html). Specifically, look here for System Calls: http://www.tldp.org/LDP/lkmpg/2.6/html/x978.html. That should give you a start, at least.

like image 37
Shannon Nelson Avatar answered Oct 10 '22 19:10

Shannon Nelson


This is an old question, but nevertheless I want to propose my solution. The easiest way to implement a "system-call-like" environment is to rely on a fake device. In particular, you could create a new device driver which is not actually driving anything. Yet, writing on it, can cause the installed module to perform the required actions. Additionally, if you want to offer several services, you might map them to ioctl operations.

like image 20
ilpelle Avatar answered Oct 10 '22 19:10

ilpelle