Home > Linux, Nerd > gdb attach fails with ptrace: Operation not permitted

gdb attach fails with ptrace: Operation not permitted

Today I ran into a weird problem. I could not attach to my own process with gdb. The process ran under my UID, but gdb refused to attach. This is a problem of wrong permissions, although /proc/[pid]/status looked ok:

...
Uid:    1000    1000    1000    1000
Gid:    1000    1000    1000    1000
...

I am the owner but cannot attach? Well, I launched gdb as root and could attach. Strange. Without digging deeper into this, my dirty workaround was this:

sudo chmod +s /usr/bin/gdb

Update: Thanks to Mario, who pointed out, that the reason is the Kernel hardening stuff build into the Ubuntu kernel. See his comment how to fix the problem permanently.

  1. Mario
    21. Oktober 2010, 14:35 | #1

    I like your style :-) . Nice hack!

  2. Mario
    21. Oktober 2010, 17:48 | #2

    I found the issue:

    https://wiki.ubuntu.com/SecurityTeam/Roadmap/KernelHardening#ptrace%20Protection

    And the solution is just either do this (as root):

    $ echo 0 > /proc/sys/kernel/yama/ptrace_scope

    …or make it permanent by setting ptrace_scope to 0 in /etc/sysctl.d/10-ptrace.conf

    Hope you find it useful!

  3. Jens Rantil
    14. Juli 2011, 09:14 | #3

    The solution above only works for Ubuntu. I am experiencing the same issue but in Debian. Holler if you have a solution!

  4. AlexanderCosmonaut
    3. Februar 2012, 18:04 | #4

    Thanks!!!

  1. 21. März 2012, 21:50 | #1