更改内核中的文件权限
我正在编写内核模块(Linux 中的 C),我想更改其中其他文件的权限。 有什么解决办法吗? 因为我在内核中,所以无法使用 chmod 系统调用并且... 感谢您的帮助
这是我的 Makefile:
> obj-m += ca.o
>
> all:
> make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
>
> clean:
> make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
这是我的代码:
> #include <linux/string.h>
> #include <linux/mm.h>
> /* Snip, tons of includes (all of them :))*/
> #include <linux/delay.h> .... int procfile_write(struct file *file,
> const char *buffer, unsigned long
> count,
> void *data) { ... sys_chmod(path, per); ... } ...
制作时给出警告:
警告:“sys_chmod”[文件]未定义
并且当使用“sudo insmod”加载模块时,会出现以下错误:
模块中的未知符号
看来这个错误尤其发生在内核模块中。有什么想法吗?再次感谢!
I am writing kernel module(C in Linux) and I want to change the permission of the other files in it.
any solution?
since I am in kernel I can't use chmod syscall and ...
thanks for your help
This is my Makefile:
> obj-m += ca.o
>
> all:
> make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
>
> clean:
> make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
And this is my Code:
> #include <linux/string.h>
> #include <linux/mm.h>
> /* Snip, tons of includes (all of them :))*/
> #include <linux/delay.h> .... int procfile_write(struct file *file,
> const char *buffer, unsigned long
> count,
> void *data) { ... sys_chmod(path, per); ... } ...
When Making it gives a warning:
WARNING: "sys_chmod" [file] undefiened
and when loading the module with "sudo insmod" it gives this error:
Unknown sybol in module
it seems that this error happens especialy in kernel modules. any idea? again thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
欢迎来到 stackoverflow!您想要的 IIRC
sys_chmod()
人们开始担心,因为这不是你可以在内核中做的事情(除非你知道你在做什么)。如果您只想更改某个事件的权限,请使用 inotify 或类似命令从用户空间进行操作。
免责声明:
这是我在另一个内核模块中找到的一些代码,它使用 sys_* 调用:
还发现:
在
include/linux/syscalls.h
中请注意,自从我这样做以来已经有一段时间了任何内核的东西。例如,检查这是否是 chmod 内容的适当接口,并且您没有快捷方式执行任何其他可能实现安全挂钩的调用。
另外,此链接包含有关系统调用的信息和他们的符号。另外此处 是用户空间 API 系统调用及其在内核中实现位置的快速参考。
Welcome to stackoverflow! IIRC you want
sys_chmod()
People are starting to worry, as this isn't the kind of thing you might do in the kernel (unless you are use you know what you are doing). If you just want to change permissions on a certain event, do it from userspace with inotify or similar.
Disclaimer aside:
Here is some code I found in another kernel module, which uses the sys_* calls:
Also found:
in
include/linux/syscalls.h
Mind you, it has been a while since I did any kernel stuff. Check that this is the appropriate interface for chmod stuff and that you arn't shortcutting any other call that might implement security hooks, for example.
Also, This link contains information on syscalls and their symbols. Also Here is a quick-reference of user-space API system calls and where they are implemented in the kernel.
系统调用不是导出的符号。如果你想要的话,你需要做一些黑客工作。
您想了解
sys_call_table
。它包含一个指向每个系统调用的指针。查看旧内核上的
arch/x86/kernel/syscall_table_32.S
或arch/i386/kernel/entry.S
。您可以通过 grep sys_call_table /usr/src/linux/System.map(如果符号已导出,则使用
/proc/kallsyms
)来查找该表的基地址。您可以将此地址作为模块的参数(需要将十六进制字符串转换为指针)。
您将能够使用
arch/x86/include/asm/unistd_32.h
(或include/asm-i386/unistd.h
)中定义的偏移量调用正确的系统调用> 在较旧的内核上)。您会得到类似以下内容:
#define __NR_chmod 15
宏很有帮助:
另外,如果您传递应该是用户缓冲区的内核缓冲区(例如文件名),请不要忘记更改数据部分:
The syscalls are not exported symbols. You need to do a little bit of hacking if you want them.
you want to get your fingers on
sys_call_table
. It contains a pointer to every syscall.Look at
arch/x86/kernel/syscall_table_32.S
orarch/i386/kernel/entry.S
on older kernels.You can
grep sys_call_table /usr/src/linux/System.map
(or/proc/kallsyms
if the symbols are exported) to find the base address of this table.You can have this address as a parameter for your module (converting an hex string to a pointer will be needed).
You'll be able to call the right syscall with the offset defined in
arch/x86/include/asm/unistd_32.h
(orinclude/asm-i386/unistd.h
on older kernels).You get something like:
#define __NR_chmod 15
Macros are helpful:
Also, if you are passing kernel buffer (for filename for examples) that are supposed to be user buffers, don't forget to change the data segment: