Thursday, 15 September 2011

gdb - Linux effect of ptrace TRACEME call -



gdb - Linux effect of ptrace TRACEME call -

i have next code. calls ptrace(ptrace_traceme) goes infinite loop. have 2 questions.

1. after executing binary, can't attach gdb if root. 2. ptrace(ptrace_traceme), can't terminate process ctrl-c (sigint). stops.

can explain me reason?? give thanks in advance. ps. know debuggers forks kid , calls ptrace(ptrace_traceme) 'before' execve(). no need remind me this.

#include <sys/ptrace.h> #include <sys/reg.h> #include <sys/wait.h> #include <sys/types.h> #include <unistd.h> #include <stdlib.h> #include <stdio.h> #include <errno.h> #include <string.h> int main(int argc, char **argv) { printf("my pid : %d\n", getpid()); ptrace(ptrace_traceme); while(1){ printf("euid : %d\n", geteuid()); sleep(2); } homecoming 0; }

after executing binary, can't attach gdb if root.

from man ptrace:

errors

eperm specified process cannot traced. because parent has insufficient privileges (the required capability cap_sys_ptrace); non-root processes cannot trace processes cannot send signals or running set-user-id/set- group-id programs, obvious reasons. alternatively, process may beingness traced, or init(8) (pid 1).

with ptrace(ptrace_traceme), can't terminate process ctrl-c (sigint). stops.

from man ptrace:

description

while beingness traced, kid stop each time signal is delivered, if signal beingness ignored. (the exception sigkill, has usual effect.) parent notified @ next wait(2) , may inspect , modify kid process while stopped. parent causes kid continue, optionally ignoring delivered signal (or delivering different signal instead).

linux gdb ptrace

No comments:

Post a Comment