- 论坛徽章:
- 1
|
现在想不然任何用户重起机器,做在内核层,开始以为挂住reboot系统调用就可轻松实现,但一试却不行:
- asmlinkage int my_reboot(int magic1, int magic2, unsigned int cmd, void * arg){
- struct log reboot_log;
- if(policy == GLOBAL_DISABLE)
- return o_reboot(magic1,magic2,cmd,arg);
- return -EACCES;
- }
复制代码
这里实现一个策略,如果GLOBAL_DISABLE策略起作用那么就调用原来的reboot,其他情况就返回权限不允许。
所以我分别strace了/sbin/reboot,/sbin/shutdown,/sbin/init
几个和重起有关的命令,竟然无法跟踪到reboot调用,奇怪的很!这里我把strace的报告贴出来,大家帮我分析讨论一下,如何准确挂住reboot?
/sbin/reboot:
- execve("/sbin/reboot", ["reboot"], [/* 21 vars */]) = 0
- uname({sys="Linux", node="redhat73", ...}) = 0
- brk(0) = 0x804adc0
- ...
- open("/halt", O_RDWR|O_CREAT, 0644) = 4
- close(4) = 0
- execve("/sbin/shutdown", ["shutdown", "-r", "now"], [/* 21 vars */]) = 0
- uname({sys="Linux", node="redhat73", ...}) = 0
- brk(0) = 0x804c8a4
- ...
- --- SIGCHLD (Child exited) ---
- execve("/sbin/init", ["/sbin/init", "6"], [/* 21 vars */]) = 0
- uname({sys="Linux", node="redhat73", ...}) = 0
- brk(0) = 0x804e6b4
- ...
复制代码
/sbin/shutdown
- execve("/sbin/shutdown", ["shutdown", "-r", "now"], [/* 20 vars */]) = 0
- uname({sys="Linux", node="redhat73", ...}) = 0
- brk(0) = 0x804c8a4
- ...
- --- SIGCHLD (Child exited) ---
- unlink("/etc/nologin") = -1 ENOENT (No such file or directory)
- sync() = 0
- execve("/sbin/init", ["/sbin/init", "6"], [/* 20 vars */]) = 0
- uname({sys="Linux", node="redhat73", ...}) = 0
- brk(0) = 0x804e6b4
- ...
复制代码
/sbin/init:
- execve("/sbin/init", ["/sbin/init", "6"], [/* 20 vars */]) = 0
- uname({sys="Linux", node="redhat73", ...}) = 0
- brk(0) = 0x804e6b4
- ...
复制代码
这里我省略了很多不必要的信息,大致可以看出最终都是调用/sbin/init,但还是看不出到底调用了哪个系统调用,我如何挂住reboot?? |
|