From nobody Mon Apr 15 14:05:33 2024 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4VJ88F6DVyz5Gflf; Mon, 15 Apr 2024 14:05:33 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4VJ88F4PFPz4WGl; Mon, 15 Apr 2024 14:05:33 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1713189933; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=FyoANJ/YO59USUCZGA/9ojt1L/neg6OX5ymrHmxW288=; b=ZSe3lkNV5m04unYY+uQZpdhWmzcG1fY82pLcEGeLb06kfH1qK6oxtNA41jhJkpDHsg47bn Xbd4miPmk2lpQmiNYLsVXo9EKUlxNihCfeRQeEbt3lP66roWsrvFHZcRBca6ISBBNVLjJr 8nMR6RAwfLXjA1QUz02YjOdYRn2sd+fVL+AmKingDFvJsKw4827lwIuWK6Ln5cDpf4iRta aNdT0JKP9+yWOWh/ljmUYFErvysReSJ+j9Brs/TV3OffjiE+D1XWxjqsHiVstytKgo4I6m KEOGa1uaImBoU+XvPdEzn9r/mMV9674Y1ifOsnyKgbPuIqPQwPhc8AI/5aI9Ew== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1713189933; a=rsa-sha256; cv=none; b=i3Jn7Z6JCjFb+Q2sRff6vhqAlorNvwCupuFVlLHPMgd90kN+nIORctre9EXNz9RdadF6bZ f+n7k+FR7SL9x1h+AOPd0E96XiH11Hf+hu9UO7U4drsYCofrMaz2LnVTp5sw7Qqd0PFpwk OBP42WzQqCDlgO0t/mlV2+PdvJC9lMtT9d46avANc73cXHcf20i2kU3cV+3BrQP+WXz8pY IAhhdaVtT585/PJT8HsnCeUoyJ1kZL4i5iBB9ba/fSiWGgCbCKLfqIrF9m52GWEjTGvNPl 95OxDHUkzrQv+ghloPI4577dnTagi4mrwCDeooPjwppC/KOtUBOwx+qGLLhxEQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1713189933; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=FyoANJ/YO59USUCZGA/9ojt1L/neg6OX5ymrHmxW288=; b=L6tFw6z5j3parl7Jm3h86Es8AuIq7Euwit0KKprbhacUNZ28sJ6XtqbEoXX16kdE/1ESmM OLDjMVg5+ZKiwKl9pF+7GZeqove+t13ZAxteuS3kss0uFuMDm3mRNynstbnn70BwhKrpwp Ft+roXR3zdWn9hXEf8SrRThlH84eOxammvl4EPEMIe3SkUN8atQWypB1ynn1E5gDadr4mP xnmLy1Nhsfr3kMZzM+QYNY3G14+miy9ZUOmNIWruSFt9QuMOusD2gFThg3QjU6n0dpdojo WXi+I7Ux/2qUPI/HPcmd7eh9VUBWNqrFWrKwn4jUj8eHx3+TZzjsR2tkkYGX7Q== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4VJ88F3jvgz136Y; Mon, 15 Apr 2024 14:05:33 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 43FE5X7N070109; Mon, 15 Apr 2024 14:05:33 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 43FE5Xm1070106; Mon, 15 Apr 2024 14:05:33 GMT (envelope-from git) Date: Mon, 15 Apr 2024 14:05:33 GMT Message-Id: <202404151405.43FE5Xm1070106@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mark Johnston Subject: git: 16f6ce3f826b - stable/14 - ptrace tests: Add a test using PROC_REAP_KILL to kill a traced debuggee List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: 16f6ce3f826b402390459ece55df719737695abb Auto-Submitted: auto-generated The branch stable/14 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=16f6ce3f826b402390459ece55df719737695abb commit 16f6ce3f826b402390459ece55df719737695abb Author: Mark Johnston AuthorDate: 2024-03-31 18:11:47 +0000 Commit: Mark Johnston CommitDate: 2024-04-15 14:05:13 +0000 ptrace tests: Add a test using PROC_REAP_KILL to kill a traced debuggee This exercises the bug fix in commit 9241ebc796c1 ("thread_single(9): decline external requests for traced or debugger-stopped procs"). Reviewed by: kib MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D44564 (cherry picked from commit 43b4da44118e4fe29e9d7456db4390c9cbb53636) --- tests/sys/kern/ptrace_test.c | 47 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/tests/sys/kern/ptrace_test.c b/tests/sys/kern/ptrace_test.c index 5666215f9377..5152affa0e8b 100644 --- a/tests/sys/kern/ptrace_test.c +++ b/tests/sys/kern/ptrace_test.c @@ -4369,6 +4369,52 @@ ATF_TC_BODY(ptrace__PT_SC_REMOTE_getpid, tc) ATF_REQUIRE(ptrace(PT_DETACH, fpid, (caddr_t)1, 0) != -1); } +/* + * Ensure that procctl(PROC_REAP_KILL) won't block forever waiting for a target + * process that stopped to report its status to a debugger. + */ +ATF_TC_WITHOUT_HEAD(ptrace__reap_kill_stopped); +ATF_TC_BODY(ptrace__reap_kill_stopped, tc) +{ + struct procctl_reaper_kill prk; + pid_t debuggee, wpid; + int error, status; + + REQUIRE_EQ(procctl(P_PID, getpid(), PROC_REAP_ACQUIRE, NULL), 0); + + debuggee = fork(); + ATF_REQUIRE(debuggee >= 0); + if (debuggee == 0) { + trace_me(); + for (;;) + sleep(10); + _exit(0); + } + wpid = waitpid(debuggee, &status, 0); + REQUIRE_EQ(wpid, debuggee); + ATF_REQUIRE(WIFSTOPPED(status)); + REQUIRE_EQ(WSTOPSIG(status), SIGSTOP); + + /* Resume the child and ask it to stop during syscall exits. */ + ATF_REQUIRE(ptrace(PT_TO_SCX, debuggee, (caddr_t)1, 0) != -1); + + /* Give the debuggee some time to go to sleep. */ + usleep(100000); + + /* + * Kill the child process. procctl() may attempt to stop the target + * process to prevent it from adding new children to the reaper subtree, + * and this should not conflict with the child stopping itself for the + * debugger. + */ + memset(&prk, 0, sizeof(prk)); + prk.rk_sig = SIGTERM; + error = procctl(P_PID, getpid(), PROC_REAP_KILL, &prk); + REQUIRE_EQ(error, 0); + REQUIRE_EQ(1, prk.rk_killed); + REQUIRE_EQ(-1, prk.rk_fpid); +} + ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, ptrace__parent_wait_after_trace_me); @@ -4435,6 +4481,7 @@ ATF_TP_ADD_TCS(tp) ATF_TP_ADD_TC(tp, ptrace__procdesc_wait_child); ATF_TP_ADD_TC(tp, ptrace__procdesc_reparent_wait_child); ATF_TP_ADD_TC(tp, ptrace__PT_SC_REMOTE_getpid); + ATF_TP_ADD_TC(tp, ptrace__reap_kill_stopped); return (atf_no_error()); }