prctl.2: PR_SET_DUMPABLE makes process non-ptrace-attachable

We've recently discovered that GDB will fail to attach to any
process that sets itself non-dumpable. Tested on kernel 2.6.32,
with:

int main(int argc, char *argv[])
{
    if (prctl(PR_SET_DUMPABLE, 0, 0, 0) != 0) {
        perror("prctl");
    }
    printf("Run gdb %s %d\n", argv[0], getpid());
    sleep(20);
    abort();
}

./a.out
Run gdb ./a.out 30476

gdb -q  ./a.out 30476
Reading symbols from /tmp/a.out...done.
Attaching to program: /tmp/a.out, process 30476
ptrace: Operation not permitted.
/tmp/30476: No such file or directory.

Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
This commit is contained in:
Paul Pluzhnikov 2011-09-17 06:10:54 +02:00 committed by Michael Kerrisk
parent 2e781e2082
commit cadcf1b16b
1 changed files with 4 additions and 1 deletions

View File

@ -43,7 +43,7 @@
.\" FIXME: Document PR_TASK_PERF_EVENTS_DISABLE and
.\" PR_TASK_PERF_EVENTS_ENABLE (new in 2.6.32)
.\"
.TH PRCTL 2 2010-05-13 "Linux" "Linux Programmer's Manual"
.TH PRCTL 2 2011-09-17 "Linux" "Linux Programmer's Manual"
.SH NAME
prctl \- operations on a process
.SH SYNOPSIS
@ -120,6 +120,9 @@ for security reasons, this feature has been removed.
.I /proc/sys/fs/suid_dumpable
in
.BR proc (5).)
Processes that are not dumpable can not be attached via
.BR ptrace(2)
.BR PTRACE_ATTACH .
.TP
.BR PR_GET_DUMPABLE " (since Linux 2.3.20)"
Return (as the function result) the current state of the calling