Linux内核-通过模块动态添加系统调用
有什么方法可以动态添加系统调用,例如通过模块?我找到了可以使用模块覆盖现有系统调用的地方,只需更改 sys_call_table[] 数组即可在安装模块时获取覆盖的函数而不是本机函数,但是您可以这样做吗使用新的系统调用和模块?
Is there any way to add a system call dynamic, such as through a module? I have found places where I can override an existing system call with a module by just changing the sys_call_table[]
array to get my overridden function instead of the native when my module is installed, but can you do this with a new system call and a module?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不,
sys_call_table
的大小是固定的:正如您可能已经发现的那样,您能做的最好的事情就是 拦截现有系统调用。
No,
sys_call_table
is of fixed size:The best you can do, as you probably already discovered, is to intercept existing system calls.
在某些情况下,拦截现有的系统调用(在内核中完成某些操作)并不是正确的方法。例如,如果您的用户空间驱动程序需要在内核中执行某些操作、向那里发送某些内容或从内核读取某些内容?
通常对于驱动程序来说,正确的方法是使用 ioctl() 调用,这只是一种系统调用,但它可以通过 ioctl() 传递不同的参数来调用不同的内核函数或驱动程序模块。
以上是用户控制的内核代码执行。
对于数据传递,您可以使用 procfs 或 sysfs 驱动程序与内核通信。
PS:当你拦截系统调用时,这通常会影响整个操作系统,你必须担心如何安全地解决问题:如果其他人正在调用系统调用,然后你修改/拦截代码怎么办?
Intercepting existing system call (to have something done in the kernel) is not the right way in some cases. For eg, if your userspace drivers need to execute something in kernel, send something there, or read something from kernel?
Usually for drivers, the right way is to use ioctl() call, which is just one system call, but it can call different kernel functions or driver modules - by passing different parameters through ioctl().
The above is for user-controlled kernel code execution.
For data passing, you can use procfs, or sysfs drivers to talk to the kernel.
PS: when you intercept system call, which generally affect the entire OS, you have to worry about how to solve the problem of doing it safely: what if someone else is halfway calling the system call, and then you modify/intercept the codes?