GDB 下的 ptrace 权限被拒绝

Ida*_*rye 5 arch-linux permissions gdb

我已经设置了一个超级简单的 C 程序并用 GCC(带有-g标志)编译它。我试过用 运行它gdb a.out,设置断点main并运行它,但 GDB 忽略了我的断点,只是不停地运行整个程序。

在 SO 中的我的问题中,他们告诉我运行它stracegrep失败调用 ptrace。我这样做并得到:

5765 ptrace(PTRACE_TRACEME, 0, 0, 0) = -1 EPERM (Operation not permitted)
Run Code Online (Sandbox Code Playgroud)

当我尝试gdb使用sudo它运行时工作正常,所以这绝对是一个权限问题。我也试过重新安装 GDB,希望它能重新设置权限,但它没有帮助。以下是 GDB 和我正在尝试调试的可执行文件的组和权限:

-rwxr-xr-x 1 idanarye users 7797 Dec 28 04:52 ./a.out
-rwxr-xr-x 1 root root 5206304 Aug 31 07:10 /usr/bin/gdb
Run Code Online (Sandbox Code Playgroud)

我尝试使用谷歌搜索这个问题,但我能找到的只是另一个问题,即 GDB 无法附加到正在运行的进程,这是由于新的安全规则阻止了跟踪另一个进程,除非它是子进程。这不是这里的问题,因为我让 GDB 启动我想要调试的进程。/proc/sys/kernel/yama/ptrace_scope无论如何,我已经尝试了建议的解决方案(更改),但没有奏效。

我在这里缺少什么?我需要授予什么权限?

我正在运行 64 位 ArchLinux。

更新

不知道如何或为什么,但它现在有效。可能是系统更新修复了它...

slm*_*slm 2

我不认为权限被拒绝一定是在谈论传统的权限位(rwx..),而是我会对 SELinux 或 AppArmor 之类的东西表示怀疑,它们可能会拒绝您的进程访问。

我无法访问 ArchLinux 系统,但 Fedora 下有类似的东西,在此 Fedora Wiki 主题中进行了讨论:Features/SELinuxDenyPtrace

在这里,他们阻止通过 SELinux 访问 ptrace,因此您可能需要尝试禁用 SELinux 或 AppArmor(ArchLinux 恰好正在使用其中之一)。

你的尝试对我有用

我尝试在我的 Fedora 19 系统上编写代码,除了需要安装一些额外的 debuginfo RPM 之外,它按照您的预期工作。

例子

编译了你的代码。

$ gcc -g test.c 
Run Code Online (Sandbox Code Playgroud)

在 中运行生成的二进制文件gdb

$ gdb a.out 
GNU gdb (GDB) Fedora 7.6.1-46.fc19
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-redhat-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /home/saml/tst/106912/a.out...done.
(gdb) break main
Breakpoint 1 at 0x40053f: file test.c, line 4.
(gdb) run
Starting program: /home/saml/tst/106912/a.out 

Breakpoint 1, main (argc=1, argv=0x7fffffffd698) at test.c:4
4       printf("1\n");
Missing separate debuginfos, use: debuginfo-install glibc-2.17-20.fc19.x86_64
(gdb) quit
A debugging session is active.

    Inferior 1 [process 13341] will be killed.

Quit anyway? (y or n) y
Run Code Online (Sandbox Code Playgroud)

调试器抱怨我缺少 glibc 的 debuginfo,所以我安装了它们。

$ sudo debuginfo-install glibc-2.17-20.fc19.x86_64
Run Code Online (Sandbox Code Playgroud)

现在当我重新运行gdb.

$ gdb a.out 
GNU gdb (GDB) Fedora 7.6.1-46.fc19
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-redhat-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /home/saml/tst/106912/a.out...done.
(gdb) break main
Breakpoint 1 at 0x40053f: file test.c, line 4.
(gdb) run
Starting program: /home/saml/tst/106912/a.out 

Breakpoint 1, main (argc=1, argv=0x7fffffffd698) at test.c:4
4       printf("1\n");
(gdb) 
Run Code Online (Sandbox Code Playgroud)