~ubuntu-branches/ubuntu/saucy/strace/saucy-proposed

« back to all changes in this revision

Viewing changes to strace.c

  • Committer: Bazaar Package Importer
  • Author(s): Kees Cook
  • Date: 2010-06-09 15:28:14 UTC
  • Revision ID: james.westby@ubuntu.com-20100609152814-wedkfnt2js6di6ic
Tags: 4.5.20-2ubuntu1
Add debian/patches/ptrace-error-verbosity.patch: try to make PTRACE
scope sysctl more discoverable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
431
431
                                unsigned int ntid = 0, nerr = 0;
432
432
                                struct dirent *de;
433
433
                                int tid;
 
434
                                int eperm = 0;
434
435
                                while ((de = readdir(dir)) != NULL) {
435
436
                                        if (de->d_fileno == 0)
436
437
                                                continue;
438
439
                                        if (tid <= 0)
439
440
                                                continue;
440
441
                                        ++ntid;
441
 
                                        if (ptrace(PTRACE_ATTACH, tid, (char *) 1, 0) < 0)
 
442
                                        if (ptrace(PTRACE_ATTACH, tid, (char *) 1, 0) < 0) {
 
443
                                                if (errno == EPERM)
 
444
                                                        eperm = 1;
442
445
                                                ++nerr;
 
446
                                        }
443
447
                                        else if (tid != tcbtab[tcbi]->pid) {
444
448
                                                tcp = alloctcb(tid);
445
449
                                                tcp->flags |= TCB_ATTACHED|TCB_CLONE_THREAD|TCB_CLONE_DETACHED|TCB_FOLLOWFORK;
459
463
                                ntid -= nerr;
460
464
                                if (ntid == 0) {
461
465
                                        perror("attach: ptrace(PTRACE_ATTACH, ...)");
 
466
                                        if (eperm)
 
467
                                                fprintf(stderr,
 
468
"Could not attach to process.  If your uid matches the uid of the target\n"
 
469
"process, check the setting of /proc/sys/kernel/ptrace_scope, or try again\n"
 
470
"as the root user.  For more details, see /etc/sysctl.d/10-ptrace.conf\n");
462
471
                                        droptcb(tcp);
463
472
                                        continue;
464
473
                                }
474
483
# endif
475
484
                if (ptrace(PTRACE_ATTACH, tcp->pid, (char *) 1, 0) < 0) {
476
485
                        perror("attach: ptrace(PTRACE_ATTACH, ...)");
 
486
                        if (errno == EPERM)
 
487
                                fprintf(stderr,
 
488
"Could not attach to process.  If your uid matches the uid of the target\n"
 
489
"process, check the setting of /proc/sys/kernel/ptrace_scope, or try again\n"
 
490
"as the root user.  For more details, see /etc/sysctl.d/10-ptrace.conf\n");
477
491
                        droptcb(tcp);
478
492
                        continue;
479
493
                }