gdb attach fails with ptrace: Operation not permitted

[COPY FROM http://blog.mellenthin.de/archives/2010/10/18/gdb-attach-fails-with-ptrace-operation-not-permitted/#comment-141535 ]

处理办法一:

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.

 

处理办法二:

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!

posted @ 2011-11-17 23:02  MagicLetters  阅读(640)  评论(0编辑  收藏  举报