Skip to content

Commit

Permalink
Detach from process if used in -p pid mode
Browse files Browse the repository at this point in the history
  • Loading branch information
robertswiecki committed Sep 23, 2015
1 parent 17118ce commit 4f9d479
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
3 changes: 3 additions & 0 deletions linux/arch.c
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,9 @@ void arch_reapChild(honggfuzz_t * hfuzz, fuzzer_t * fuzzer)
}
arch_removeTimer(&timerid);
arch_perfAnalyze(hfuzz, fuzzer, &perfFds);
if (childPid != ptracePid) {
arch_ptraceDetach(ptracePid);
}
return;
}

Expand Down
18 changes: 17 additions & 1 deletion linux/ptrace_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -909,9 +909,9 @@ static bool arch_listThreads(int tasks[], size_t thrSz, int pid)
return true;
}

#define MAX_THREAD_IN_TASK 4096
bool arch_ptraceAttach(pid_t pid)
{
#define MAX_THREAD_IN_TASK 4096
int tasks[MAX_THREAD_IN_TASK + 1] = { 0 };
if (!arch_listThreads(tasks, MAX_THREAD_IN_TASK, pid)) {
LOGMSG(l_ERROR, "Couldn't read thread list for pid '%d'", pid);
Expand All @@ -933,3 +933,19 @@ bool arch_ptraceAttach(pid_t pid)
}
return true;
}

void arch_ptraceDetach(pid_t pid)
{
int tasks[MAX_THREAD_IN_TASK + 1] = { 0 };
if (!arch_listThreads(tasks, MAX_THREAD_IN_TASK, pid)) {
LOGMSG(l_ERROR, "Couldn't read thread list for pid '%d'", pid);
return;
}

for (int i = 0; i < MAX_THREAD_IN_TASK && tasks[i]; i++) {
ptrace(PTRACE_INTERRUPT, tasks[i], NULL, NULL);
int status;
while (wait4(tasks[i], &status, __WALL, NULL) != pid) ;
ptrace(PTRACE_DETACH, tasks[i], NULL, NULL);
}
}
1 change: 1 addition & 0 deletions linux/ptrace_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
extern bool arch_ptraceEnable(honggfuzz_t * fuzz);
extern void arch_ptraceAnalyze(honggfuzz_t * fuzz, int status, pid_t pid, fuzzer_t * fuzzer);
extern bool arch_ptraceAttach(pid_t pid);
extern void arch_ptraceDetach(pid_t pid);
extern void arch_ptraceGetCustomPerf(honggfuzz_t * fuzz, pid_t pid, uint64_t * cnt);

#endif

0 comments on commit 4f9d479

Please sign in to comment.