Skip to content

Commit 7699820

Browse files
committed
exec_ptrace_seize: no need to PTRACE_CONT child after messaging it.
Now that we don't use a signal to wake up the tracee, there is no need to use PTRACE_CONT to continue it since it will not be in stop-wait.
1 parent 2f24226 commit 7699820

1 file changed

Lines changed: 3 additions & 27 deletions

File tree

src/exec_ptrace.c

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1235,8 +1235,7 @@ exec_ptrace_seize(pid_t child, int intercept_fd)
12351235
PTRACE_O_TRACEFORK|PTRACE_O_TRACEVFORK|
12361236
PTRACE_O_TRACEEXEC;
12371237
struct command_status cstat;
1238-
int ret = -1;
1239-
int status;
1238+
int ret = true;
12401239
debug_decl(exec_ptrace_seize, SUDO_DEBUG_EXEC);
12411240

12421241
#ifdef HAVE_PROCESS_VM_READV
@@ -1258,6 +1257,7 @@ exec_ptrace_seize(pid_t child, int intercept_fd)
12581257
if (errno != EPERM) {
12591258
sudo_warn("%s: ptrace(PTRACE_SEIZE, %d, NULL, 0x%lx)",
12601259
__func__, (int)child, ptrace_opts);
1260+
ret = -1;
12611261
goto done;
12621262
}
12631263
sudo_debug_printf(SUDO_DEBUG_WARN,
@@ -1271,34 +1271,10 @@ exec_ptrace_seize(pid_t child, int intercept_fd)
12711271
cstat.val = 0;
12721272
if (send(intercept_fd, &cstat, sizeof(cstat), 0) == -1) {
12731273
sudo_warn("%s", U_("unable to wake up child"));
1274+
ret = -1;
12741275
goto done;
12751276
}
12761277

1277-
/* If PTRACE_SEIZE failed, we are done. */
1278-
if (!ret)
1279-
goto done;
1280-
1281-
/* Wait for the child to enter trace stop and continue it. */
1282-
for (;;) {
1283-
if (waitpid(child, &status, __WALL) != -1)
1284-
break;
1285-
if (errno == EINTR)
1286-
continue;
1287-
sudo_warn(U_("%s: %s"), __func__, "waitpid");
1288-
goto done;
1289-
}
1290-
if (!WIFSTOPPED(status)) {
1291-
sudo_warnx(U_("process %d exited unexpectedly"), (int)child);
1292-
goto done;
1293-
}
1294-
if (ptrace(PTRACE_CONT, child, NULL, (void *)SIGUSR1) == -1) {
1295-
sudo_warn("%s: ptrace(PTRACE_CONT, %d, NULL, SIGUSR1)",
1296-
__func__, (int)child);
1297-
goto done;
1298-
}
1299-
1300-
ret = true;
1301-
13021278
done:
13031279
debug_return_int(ret);
13041280
}

0 commit comments

Comments
 (0)