nelhage / reptyr

Reparent a running program to a new terminal
MIT License
5.82k stars 215 forks source link

Unable to attach to pid #32

Open wilzbach opened 10 years ago

wilzbach commented 10 years ago

Commands I tried to far: a) echo "hi" ; sleep 200; echo "hi" b) ping "foo.com" c) irssi

Version: 0.5 on x64. Tested on zsh + bash.

Steps to reproduce

$ ctrl+z                     # Suspend the current process
(I also tried to use bg here)
(optional: $ jobs -l      # get the PID )
$ disown "%1"           # Detach irssi from the shell

start a new terminal:

$ reptyr  <PID>  # Get back the process

Unfortunately I get the following error:

[+] Checking for problematic process group members...
[+] Allocated scratch page: 7f011f20d000
[+] Looking up fds for tty in child.
[+] Resolved child tty: 880a
[+] Found an alias for the tty: 0
[+] Found an alias for the tty: 1
[+] Found an alias for the tty: 2
[-] Unable to open the tty in the child.
Unable to attach to pid 15021: Permission denied
Thanatermesis commented 10 years ago

Same problem here, using Debian Wheezy with a debian kernel (upgraded) 3.10

Thanatermesis commented 10 years ago

Tried also with the default kernel, I got this:

~ ❯❯❯ reptyr 8453 1 [+] Allocated scratch page: b7723000 [+] Looking up fds for tty in child. [+] Resolved child tty: 880c [+] Found an alias for the tty: 0 [+] Found an alias for the tty: 1 [+] Found an alias for the tty: 2 [+] Opened the new tty in the child: 3 [+] Target is not a session leader, attempting to setsid. [+] Forked a child: 8592 [+] Change pgid for pid 8453 [+] Change pgid for pid 8579 [-] failed: Permission denied [-] Failed to setsid: Operation not permitted [+] Change pgid for pid 8453 [+] Change pgid for pid 8592 Unable to attach to pid 8453: Operation not permitted

rossjones commented 10 years ago

Did you do this as mentioned in the documentation/readme?

echo 0 > /proc/sys/kernel/yama/ptrace_scope
Thanatermesis commented 10 years ago

yes, also tried as root

jensenak commented 10 years ago

I had this problem with a pg_basebackup that I wanted to move to a screen session. I followed similar steps to those previously mentioned (suspend, background, disown, reptyr) and got "permission denied" exactly as mentioned by Thanatermesis.

Oddly, as root I was unable to assume control of the process, but as postgres, it worked. I hope that helps someone.

Earnestly commented 9 years ago

Note for others, even with ptrace_scope set to 0, the UIDs of both parent and child needs to be the same, thus if you try to reptyr as root (or as a different UID) a program running as your user, it will not let you.

eromoe commented 7 years ago

echo 0 > /proc/sys/kernel/yama/ptrace_scope donot work in a docker container And Seems ptrace and strace not work due to security features https://github.com/moby/moby/issues/20064 https://github.com/moby/moby/issues/21051

Running docker with

--security-opt="apparmor=unconfined" --cap-add=SYS_PTRACE