是否可以通过LKM添加系统调用?

时间:2022-06-28 18:04:36

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.

我想通过LKM添加一个新的系统调用,但我不知道该怎么做。也就是说,我知道如果我想添加一个全新的系统调用,我可以查看sys_call_table并找到一个sys_ni_syscall并只是替换它,但我很好奇是否可以实际添加到sys_call_table。我意识到它可能是不可能的,因为它是一个固定大小的数组,但我想知道是否有任何其他聪明的方法来添加系统调用而不覆盖未使用的系统调用号。

3 个解决方案

#1


3  

Here's an example
linux system calls

这是一个linux系统调用的例子

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.

编辑:上面的示例显示了如何实现系统调用,只要从可加载模块实现一个; AFAIK,这是不可能的,除非你在哪里覆盖现有的,因为数组的大小是#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.

请记住,还需要更改用户空间,至少如果您希望能够实际使用新的系统调用。

#2


1  

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.

查看Linux Documentation Project网站上的“Linux内核模块编程指南”(http://www.tldp.org/LDP/lkmpg/2.6/html/index.html)。具体来说,请查看系统调用:http://www.tldp.org/LDP/lkmpg/2.6/html/x978.html。这应该会给你一个开始,至少。

#3


1  

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.

这是一个老问题,但我想提出我的解决方案。实现“类似系统调用”环境的最简单方法是依赖虚假设备。特别是,您可以创建一个实际上没有驱动任何东西的新设备驱动程序。然而,在其上书写,可能导致已安装的模块执行所需的操作。此外,如果要提供多种服务,可以将它们映射到ioctl操作。

#1


3  

Here's an example
linux system calls

这是一个linux系统调用的例子

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.

编辑:上面的示例显示了如何实现系统调用,只要从可加载模块实现一个; AFAIK,这是不可能的,除非你在哪里覆盖现有的,因为数组的大小是#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.

请记住,还需要更改用户空间,至少如果您希望能够实际使用新的系统调用。

#2


1  

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.

查看Linux Documentation Project网站上的“Linux内核模块编程指南”(http://www.tldp.org/LDP/lkmpg/2.6/html/index.html)。具体来说,请查看系统调用:http://www.tldp.org/LDP/lkmpg/2.6/html/x978.html。这应该会给你一个开始,至少。

#3


1  

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.

这是一个老问题,但我想提出我的解决方案。实现“类似系统调用”环境的最简单方法是依赖虚假设备。特别是,您可以创建一个实际上没有驱动任何东西的新设备驱动程序。然而,在其上书写,可能导致已安装的模块执行所需的操作。此外,如果要提供多种服务,可以将它们映射到ioctl操作。