How to solve “ptrace operation not permitted” when trying to attach GDB to a process?

前端 未结 13 2224
予麋鹿
予麋鹿 2020-11-30 18:28

I\'m trying to attach a program with gdb but it returns:

Attaching to process 29139
Could not attach to process. If your uid matches the ui

13条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-30 19:02

    Jesup's answer is correct; it is due to Linux kernel hardening. In my case, I am using Docker Community for Mac, and in order to do change the flag I must enter the LinuxKit shell using justin cormack's nsenter (ref: https://www.bretfisher.com/docker-for-mac-commands-for-getting-into-local-docker-vm/ ).

    docker run -it --rm --privileged --pid=host justincormack/nsenter1

    / # cat /etc/issue

    Welcome to LinuxKit

                        ##         .
                  ## ## ##        ==
               ## ## ## ## ##    ===
           /"""""""""""""""""\___/ ===
          {                       /  ===-
           \______ O           __/
             \    \         __/
              \____\_______/
    

    / # cat /proc/sys/kernel/yama/ptrace_scope

    1

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

    / # exit

提交回复
热议问题