linux - 我可以使用 Kprobe 阻止新进程执行吗?

标签 linux security callback linux-kernel kprobe

Kprobe 有一个预处理函数,模糊记录如下:

User's pre-handler (kp->pre_handler)::

    #include <linux/kprobes.h>
    #include <linux/ptrace.h>
    int pre_handler(struct kprobe *p, struct pt_regs *regs);

Called with p pointing to the kprobe associated with the breakpoint,
and regs pointing to the struct containing the registers saved when
the breakpoint was hit.  Return 0 here unless you're a Kprobes geek.

我想知道是否可以使用此函数(或任何其他 Kprobe 功能)来防止进程被执行\ fork 。

最佳答案

如内核文档中所述,您可以通过更改适当的寄存器(例如 x86 中的 IP 寄存器)来更改执行路径:

Changing Execution Path
-----------------------

Since kprobes can probe into a running kernel code, it can change the
register set, including instruction pointer. This operation requires
maximum care, such as keeping the stack frame, recovering the execution
path etc. Since it operates on a running kernel and needs deep knowledge
of computer architecture and concurrent computing, you can easily shoot
your foot.

If you change the instruction pointer (and set up other related
registers) in pre_handler, you must return !0 so that kprobes stops
single stepping and just returns to the given address.
This also means post_handler should not be called anymore.

Note that this operation may be harder on some architectures which use
TOC (Table of Contents) for function call, since you have to setup a new
TOC for your function in your module, and recover the old one after
returning from it.

因此,您也许可以通过跳过某些代码来阻止进程的执行。我不会推荐它;您更有可能导致内核崩溃,而不是成功停止新进程的执行。

seccomp-bpf 可能更适合您的用例。 This StackOverflow answer为您提供利用 seccomp-bpf 所需的所有信息。

关于linux - 我可以使用 Kprobe 阻止新进程执行吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53457705/

相关文章:

python - 我下载了漏洞利用脚本,当尝试运行它时,它给了我一个错误

linux - eval/bash -c 与仅评估变量相比有什么意义?

linux - 基本: Where does %{REQUEST_URI} come from,是什么意思?

security - 从命令行确定 TLS/SSL 证书是否为 'trusted'?

Javascript Vue 或 React 存储敏感信息客户端安全

html - HTML 页面中的什么是唯一的?

linux - 下一个函数调用中的错误参数计数

javascript - 如何使用 webdriverio 验证它是否是登录页面

PHP - 将一个额外的参数(变量)传递给 set_exception_handler

flutter - 将ListView元素的CheckBox的位置传递给Flutter中的onChanged回调