正确的 kill syscall linux 使用模式

标签 c linux security system system-calls

<分区>

man对于 int kill(pid_t pid, int sig); 说:

If pid equals -1, then sig is sent to every process for which the calling process has permission to send signals, except for process 1 (init), but see below.

这是否意味着如果我的程序以 root 权限运行并且意外地(由于内存损坏或黑客攻击)提供 -1 作为 pid 参数 - 这将对整个系统造成完整的 DoS?

如果是这样,是否建议在调用这个潜在的灾难性调用之前始终对 pid 参数值执行双重检查? (只是说)

最佳答案

Does this mean that if my program is run with root permissions and it accidentally (due to memory corruption or a hack) provides -1 as pid argument - this will cause a complete DoS for the entire system?

是的,这种情况是可能的。但它发生的可能性非常小。因为没有以 root 权限运行的程序会做这样的事情。如果恶意用户/二进制文件以某种方式获得了 root 权限,那么发送信号只是问题之一。

If so, is it recommended to always perform a double check for the pid argument value before calling this potentially disastrous call?

那只是 super 偏执的想法。进行灾难性事件的方法有数千种。您不妨担心:

如果没有在系统启动时运行的恶意守护进程会怎样:

kill(-1, SIGKILL);

您如何知道您创建的库函数是否不会调用 reboot(2) 并重新启动您的系统?

等等

此外,PID 不仅仅是用户提供的需要清理的值。 PID 主要是使用系统调用或库调用在程序中获取的值。因此,“意外”使用 -1 的可能性为零。基本上,您某人/程序拥有 root 权限并决定搞砸您的系统,那么您无能为力。

关于正确的 kill syscall linux 使用模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34578490/

相关文章:

php - 如何防止 PHP 中的 SQL 注入(inject)?

php - 如何防止 PHP 中的 SQL 注入(inject)?

objective-c - 比较浮点值有多危险?

c++ - Cmake可以生成一个同时支持调试和发布的makefile吗

linux - 如何添加一个 cron 作业来运行 php 脚本

linux - 检查非默认加载器的共享库

c - 将特定的结构字段作为函数参数传递

c - C 中 PriorityQueue 的问题

linux - 正则表达式模式在 sublime text 中找到,但在 linux sed 命令 sed 中找不到

javascript - 有什么好的方法可以防止JavaScript多人游戏作弊?