From nobody Sun Mar 31 18:15:52 2024 X-Original-To: dev-commits-src-main@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 4V72Q05WKyz5G6Tf; Sun, 31 Mar 2024 18:15:52 +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 4V72Q04yyfz43Xf; Sun, 31 Mar 2024 18:15:52 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1711908952; 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=1N6RR2+stJUVmnhDxvsIm3VAYWpAXGxjcmFRfcxy3Go=; b=yXgruZrRSxP/0xf0Vtb43bAFHNzsQgXn+FxGvyp8wMbFtPNMOTi6gr+tIXKosROBDBdREK HPx8W76AQMZnda08a+/0cm5JRJD9PwppVptrKRY9x4Jt0U4ctLRNlgoUVruEbYaktynPmm e+nMQT+N9pP+mmJzHZsGDIj3E07/8mS9ewOkoCLzcrYmH0r1ahB6QyH73rnr8KCjL9nyqL WX1C/YYT+F7F/bNUocQc0obSbmozmo0q2gR3tZ/Xnt91ElFQftfAHPOu/pyxqP5HrC1ZYP gptpIvLbJq4lxok1XkiSQ61q9f+70tfetZec0TPdsQGS9V16npJcOSQETYzD7Q== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1711908952; a=rsa-sha256; cv=none; b=RLZT+ieOwIWmQwZruCJmtiQ4z9OovCZNp6Es//3DQdO3a0EsIhwcToDSRhK8i0xrJmRWiH ydH43XzuAxWGLkofOrniMC7CfAQwoOoGzXWEhq8okS9NFJWDZTJFTqfvzS6A/ktwwr+R49 ay05hZYyP/UfGMzROJGl4azPR1TlhHFiEeXl0XzwxYpOcfUD2txwaAQvCK5BDJVq8q6Ins T+U3TnkxIwy0FmkVUv70pY+Sb93yWlvr+Ai96Q+JUhPsE5bPPpmb7Ui10rhi1t+cprWUdk RcBk3cCY+GpyyfcBvWNoL6UIWkT6oEtGUMGkmbOgEolwHjw9CvgzTNi3QmlOQA== 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=1711908952; 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=1N6RR2+stJUVmnhDxvsIm3VAYWpAXGxjcmFRfcxy3Go=; b=Klx1cvDo01Lf1j5ValjPuU9fpfDBb20WOkSidLavIlGaVSHSk564aarCBIMN/OOi4FyMig ljLOf356hZIaKMD7ZWOFSFd4FDAsL8UGwFkeOROrloZMTnk0S2RHFR+lNGPkEIt8HxUy+2 25CcN/QIBsTZsAftKvltJdjwOdwZDJSCknOggiQCONksZRzfna9LzMaumATIPkq+mT/B7a saACRcV6s3lPhJCGFHw8eFTM4k+FNtWyizPFEsq+5pNT7Nz++/tixblaGQSN1YV19gLcEv /y2c3xUh4GhIWv7QF+AA79GreLC4zxEFmZ9Pww1qYylacvpScL5lris4UuDGbA== 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 4V72Q04Z6dzpCZ; Sun, 31 Mar 2024 18:15:52 +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 42VIFqbB075174; Sun, 31 Mar 2024 18:15:52 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 42VIFqYb075171; Sun, 31 Mar 2024 18:15:52 GMT (envelope-from git) Date: Sun, 31 Mar 2024 18:15:52 GMT Message-Id: <202403311815.42VIFqYb075171@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mark Johnston Subject: git: 43b4da44118e - main - ptrace tests: Add a test using PROC_REAP_KILL to kill a traced debuggee List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@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/main X-Git-Reftype: branch X-Git-Commit: 43b4da44118e4fe29e9d7456db4390c9cbb53636 Auto-Submitted: auto-generated The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=43b4da44118e4fe29e9d7456db4390c9cbb53636 commit 43b4da44118e4fe29e9d7456db4390c9cbb53636 Author: Mark Johnston AuthorDate: 2024-03-31 18:11:47 +0000 Commit: Mark Johnston CommitDate: 2024-03-31 18:11:47 +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 --- 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 bd176e2963f0..b65c84144ad0 100644 --- a/tests/sys/kern/ptrace_test.c +++ b/tests/sys/kern/ptrace_test.c @@ -4368,6 +4368,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); @@ -4434,6 +4480,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()); }