父进程的跟踪
子进程可以使用 ptrace 系统调用来跟踪其父进程吗?
操作系统是linux 2.6
谢谢。
更新1: 我想从“自身”追踪process1。这是不可能的,所以我 fork 并尝试从子进程执行 ptrace(process1_pid, PTRACE_ATTACH) 。但我不能,有一个奇怪的错误,比如内核禁止子进程跟踪其父进程
UPD2:安全策略可以禁止这种跟踪。哪些警察这样做?内核中的检查代码在哪里?
UPD3:在我的嵌入式 Linux 上,PEEKDATA 没有错误,但 GETREGS 没有错误:
child: getregs parent: -1
errno is 1, strerror is Operation not permitted
errno = EPERM
Can child process use the ptrace
system call to trace its parent?
Os is linux 2.6
Thanks.
upd1:
I want to trace process1 from "itself". It is impossible, so I do fork and try to do ptrace(process1_pid, PTRACE_ATTACH)
from child process. But I can't, there is a strange error, like kernel prohibits child from tracing their parent processes
UPD2: such tracing can be prohibited by security policies. Which polices do this? Where is the checking code in the kernel?
UPD3: on my embedded linux I have no errors with PEEKDATA, but not with GETREGS:
child: getregs parent: -1
errno is 1, strerror is Operation not permitted
errno = EPERM
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这个问题让我很感兴趣。所以我写了一些代码来尝试一下。
首先请记住,在跟踪进程时,除了名称(即
getppid()
)之外,跟踪进程在大多数情况下都会成为父进程。首先,手册的PTRACE_ATTACH
部分的片段很有帮助:现在这是我编写的代码,用于测试和验证您实际上可以
ptrace()
您的父级 (您可以通过将其转储到名为blah.c
的文件中并运行make blah
来构建它:请注意,我正在利用父级虚拟地址空间的复制来了解位置另请注意,当子进程终止时,我怀疑存在隐式分离,必须允许父进程继续,我没有进一步调查。
This question really interested me. So I wrote some code to try it out.
Firstly keep in mind, that when tracing a process, the tracing process becomes a parent for most purposes, except in name (i.e.
getppid()
). Firstly, a snippet of thePTRACE_ATTACH
section of the manual is helpful:Now here is the code I wrote to test and verify that you can in fact
ptrace()
your parent (you can build this by dumping it in a file namedblah.c
and runningmake blah
:Note that I'm exploiting the replication of the parent's virtual address space to know where to look. Also note that when the child then terminates, I suspect there's an implicit detach which must allow the parent to continue, I didn't investigate further.
是的,有可能...
甚至 GETREGS 也能工作。
在 x86 上检查
(基于 Matt Joiner 代码,谢谢他)
结果:
Yes it is possible...
Even GETREGS works.
Checked on x86
(based on Matt Joiner code, thanks him)
result: